linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/6] [media] iguanair: Fix return value on transmit
@ 2012-08-10 19:28 Sean Young
  2012-08-10 19:28 ` [PATCH 2/6] [media] rc: transmit on device which does not support it should fail Sean Young
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Sean Young @ 2012-08-10 19:28 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Jarod Wilson, Greg Kroah-Hartman,
	Stefan Macher, linux-media

Transmit returned 0 after sending and failed to send anything if the amount
exceeded its buffer size. Also fix some minor errors.

Signed-off-by: Sean Young <sean@mess.org>
---
 drivers/media/rc/iguanair.c | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/drivers/media/rc/iguanair.c b/drivers/media/rc/iguanair.c
index aa7f34f..437aa42 100644
--- a/drivers/media/rc/iguanair.c
+++ b/drivers/media/rc/iguanair.c
@@ -75,7 +75,7 @@ struct iguanair {
 
 #define MAX_PACKET_SIZE		8u
 #define TIMEOUT			1000
-#define RX_RESOLUTION		21330
+#define RX_RESOLUTION		21333
 
 struct packet {
 	uint16_t start;
@@ -349,7 +349,7 @@ static int iguanair_tx(struct rc_dev *dev, unsigned *txbuf, unsigned count)
 {
 	struct iguanair *ir = dev->priv;
 	uint8_t space, *payload;
-	unsigned i, size, rc;
+	unsigned i, size, rc, bytes;
 	struct send_packet *packet;
 
 	mutex_lock(&ir->lock);
@@ -357,17 +357,22 @@ static int iguanair_tx(struct rc_dev *dev, unsigned *txbuf, unsigned count)
 	/* convert from us to carrier periods */
 	for (i = size = 0; i < count; i++) {
 		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 (!packet) {
-		rc = -ENOMEM;
+	if (count == 0) {
+		rc = -EINVAL;
 		goto out;
 	}
 
-	if (size > ir->bufsize) {
-		rc = -E2BIG;
+	packet = kmalloc(sizeof(*packet) + size, GFP_KERNEL);
+	if (!packet) {
+		rc = -ENOMEM;
 		goto out;
 	}
 
@@ -398,7 +403,7 @@ static int iguanair_tx(struct rc_dev *dev, unsigned *txbuf, unsigned count)
 		rc = iguanair_receiver(ir, false);
 		if (rc) {
 			dev_warn(ir->dev, "disable receiver before transmit failed\n");
-			goto out;
+			goto out_kfree;
 		}
 	}
 
@@ -414,11 +419,12 @@ static int iguanair_tx(struct rc_dev *dev, unsigned *txbuf, unsigned count)
 			dev_warn(ir->dev, "re-enable receiver after transmit failed\n");
 	}
 
+out_kfree:
+	kfree(packet);
 out:
 	mutex_unlock(&ir->lock);
-	kfree(packet);
 
-	return rc;
+	return rc ? rc : count;
 }
 
 static int iguanair_open(struct rc_dev *rdev)
@@ -466,16 +472,16 @@ static int __devinit iguanair_probe(struct usb_interface *intf,
 	ir = kzalloc(sizeof(*ir), GFP_KERNEL);
 	rc = rc_allocate_device();
 	if (!ir || !rc) {
-		ret = ENOMEM;
+		ret = -ENOMEM;
 		goto out;
 	}
 
-	ir->buf_in = usb_alloc_coherent(udev, MAX_PACKET_SIZE, GFP_ATOMIC,
+	ir->buf_in = usb_alloc_coherent(udev, MAX_PACKET_SIZE, GFP_KERNEL,
 								&ir->dma_in);
 	ir->urb_in = usb_alloc_urb(0, GFP_KERNEL);
 
 	if (!ir->buf_in || !ir->urb_in) {
-		ret = ENOMEM;
+		ret = -ENOMEM;
 		goto out;
 	}
 
-- 
1.7.11.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-08-12 16:48 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-10 19:28 [PATCH 1/6] [media] iguanair: Fix return value on transmit Sean Young
2012-08-10 19:28 ` [PATCH 2/6] [media] rc: transmit on device which does not support it should fail Sean Young
2012-08-10 19:28 ` [PATCH 3/6] [media] rc: Add support for the TechnoTrend USB IR Receiver Sean Young
2012-08-10 19:28 ` [PATCH 4/6] [media] rc: do not wake up rc thread unless there is something to do Sean Young
2012-08-10 19:28 ` [PATCH 5/6] [staging] lirc: remove lirc_ttusbir driver Sean Young
2012-08-10 19:28 ` [PATCH 6/6] [staging] lirc: lirc_ene0100.h is not referenced anywhere Sean Young
2012-08-11 20:52 ` [PATCH 1/6] [media] iguanair: Fix return value on transmit Sean Young
2012-08-12 16:48   ` Mauro Carvalho Chehab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).