Commit 884bfd08 authored by Sean Young's avatar Sean Young Committed by Mauro Carvalho Chehab

[media] iguanair: fix return value for transmit

Also fix error codes returned from open.
Signed-off-by: default avatarSean Young <sean@mess.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 7c0bd96b
...@@ -327,7 +327,7 @@ static int iguanair_tx(struct rc_dev *dev, unsigned *txbuf, unsigned count) ...@@ -327,7 +327,7 @@ static int iguanair_tx(struct rc_dev *dev, unsigned *txbuf, unsigned count)
{ {
struct iguanair *ir = dev->priv; struct iguanair *ir = dev->priv;
uint8_t space, *payload; uint8_t space, *payload;
unsigned i, size, rc; unsigned i, size, rc, bytes;
struct send_packet *packet; struct send_packet *packet;
mutex_lock(&ir->lock); mutex_lock(&ir->lock);
...@@ -335,17 +335,22 @@ static int iguanair_tx(struct rc_dev *dev, unsigned *txbuf, unsigned count) ...@@ -335,17 +335,22 @@ static int iguanair_tx(struct rc_dev *dev, unsigned *txbuf, unsigned count)
/* convert from us to carrier periods */ /* convert from us to carrier periods */
for (i = size = 0; i < count; i++) { for (i = size = 0; i < count; i++) {
txbuf[i] = DIV_ROUND_CLOSEST(txbuf[i] * ir->carrier, 1000000); txbuf[i] = DIV_ROUND_CLOSEST(txbuf[i] * ir->carrier, 1000000);
size += (txbuf[i] + 126) / 127; bytes = (txbuf[i] + 126) / 127;
if (size + bytes > ir->bufsize) {
count = i;
break;
}
size += bytes;
} }
packet = kmalloc(sizeof(*packet) + size, GFP_KERNEL); if (count == 0) {
if (!packet) { rc = -EINVAL;
rc = -ENOMEM;
goto out; goto out;
} }
if (size > ir->bufsize) { packet = kmalloc(sizeof(*packet) + size, GFP_KERNEL);
rc = -E2BIG; if (!packet) {
rc = -ENOMEM;
goto out; goto out;
} }
...@@ -376,7 +381,7 @@ static int iguanair_tx(struct rc_dev *dev, unsigned *txbuf, unsigned count) ...@@ -376,7 +381,7 @@ static int iguanair_tx(struct rc_dev *dev, unsigned *txbuf, unsigned count)
rc = iguanair_receiver(ir, false); rc = iguanair_receiver(ir, false);
if (rc) { if (rc) {
dev_warn(ir->dev, "disable receiver before transmit failed\n"); dev_warn(ir->dev, "disable receiver before transmit failed\n");
goto out; goto out_kfree;
} }
} }
...@@ -392,11 +397,12 @@ static int iguanair_tx(struct rc_dev *dev, unsigned *txbuf, unsigned count) ...@@ -392,11 +397,12 @@ static int iguanair_tx(struct rc_dev *dev, unsigned *txbuf, unsigned count)
dev_warn(ir->dev, "re-enable receiver after transmit failed\n"); dev_warn(ir->dev, "re-enable receiver after transmit failed\n");
} }
out_kfree:
kfree(packet);
out: out:
mutex_unlock(&ir->lock); mutex_unlock(&ir->lock);
kfree(packet);
return rc; return rc ? rc : count;
} }
static int iguanair_open(struct rc_dev *rdev) static int iguanair_open(struct rc_dev *rdev)
...@@ -444,7 +450,7 @@ static int __devinit iguanair_probe(struct usb_interface *intf, ...@@ -444,7 +450,7 @@ static int __devinit iguanair_probe(struct usb_interface *intf,
ir = kzalloc(sizeof(*ir), GFP_KERNEL); ir = kzalloc(sizeof(*ir), GFP_KERNEL);
rc = rc_allocate_device(); rc = rc_allocate_device();
if (!ir || !rc) { if (!ir || !rc) {
ret = ENOMEM; ret = -ENOMEM;
goto out; goto out;
} }
...@@ -453,7 +459,7 @@ static int __devinit iguanair_probe(struct usb_interface *intf, ...@@ -453,7 +459,7 @@ static int __devinit iguanair_probe(struct usb_interface *intf,
ir->urb_in = usb_alloc_urb(0, GFP_KERNEL); ir->urb_in = usb_alloc_urb(0, GFP_KERNEL);
if (!ir->buf_in || !ir->urb_in) { if (!ir->buf_in || !ir->urb_in) {
ret = ENOMEM; ret = -ENOMEM;
goto out; goto out;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment