All of lore.kernel.org
 help / color / mirror / Atom feed
* staging: iio: iio_ring_rip_outer return immediately if rip_lots returns <= 0
@ 2010-10-07 10:41 michael.hennerich
  2010-10-07 10:41 ` [PATCH] " michael.hennerich
  0 siblings, 1 reply; 4+ messages in thread
From: michael.hennerich @ 2010-10-07 10:41 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, drivers


The last two days I was casing a bug related sw ringbuffer usage.
Reading from an empty buffer caused my system to crash anytime later in
all kinds of fashions. The crash happened at a time where no iio related
function calls where going on.

It appears that on my nommu development system freeing memory twice can
lead to such bugs. And the fact that it does error right away made debugging
this issue a pain.

iio_ring_rip_outer() calls rb->access.rip_lots() which defaults in the
sw ring buffer case to iio_rip_sw_rb().

iio_rip_sw_rb() returns 0 and frees the local buffer:

	if (initial_write_p == initial_read_p) /* No new data available.*/
or
	if (unlikely(initial_read_p == NULL)) /* No data here as yet */

However iio_ring_rip_outer() only checks for  copied/retured  < 0.
It then carries on copies 0 bytes to user and frees the buffer again.

^ permalink raw reply	[flat|nested] 4+ messages in thread
* [PATCH] staging: iio: iio_ring_rip_outer return immediately if rip_lots returns <= 0
@ 2010-10-07 11:27 michael.hennerich
  0 siblings, 0 replies; 4+ messages in thread
From: michael.hennerich @ 2010-10-07 11:27 UTC (permalink / raw)
  To: greg; +Cc: linux-iio, drivers, jic23, Michael Hennerich

From: Michael Hennerich <michael.hennerich@analog.com>

Acked-by: Jonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
---
 drivers/staging/iio/industrialio-ring.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/staging/iio/industrialio-ring.c b/drivers/staging/iio/industrialio-ring.c
index edcf6be..d393ace 100644
--- a/drivers/staging/iio/industrialio-ring.c
+++ b/drivers/staging/iio/industrialio-ring.c
@@ -105,7 +105,7 @@ static ssize_t iio_ring_rip_outer(struct file *filp, char __user *buf,
 		return -EINVAL;
 	copied = rb->access.rip_lots(rb, count, &data, &dead_offset);
 
-	if (copied < 0) {
+	if (copied <= 0) {
 		ret = copied;
 		goto error_ret;
 	}
-- 
1.6.0.2

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

end of thread, other threads:[~2010-10-07 11:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-07 10:41 staging: iio: iio_ring_rip_outer return immediately if rip_lots returns <= 0 michael.hennerich
2010-10-07 10:41 ` [PATCH] " michael.hennerich
2010-10-07 11:28   ` Jonathan Cameron
  -- strict thread matches above, loose matches on Subject: below --
2010-10-07 11:27 michael.hennerich

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.