public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [staging] iio, adc: Do not leak memory in ad7280_event_handler()
@ 2011-11-06 21:49 Jesper Juhl
  2011-11-06 21:49 ` Jonathan Cameron
  2011-11-27  0:43 ` Greg KH
  0 siblings, 2 replies; 5+ messages in thread
From: Jesper Juhl @ 2011-11-06 21:49 UTC (permalink / raw)
  To: linux-iio, devel, linux-kernel
  Cc: Paul Gortmaker, Michael Hennerich, Greg Kroah-Hartman,
	Jonathan Cameron

If ad7280_read_all_channels() returns <0 then we'll leak the memory
allocated to 'channels' when we return and that variable goes out of
scope.
This patch fixes the leak.

Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
 drivers/staging/iio/adc/ad7280a.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

 note: I don't have the hardware, so patch is compile tested only.

diff --git a/drivers/staging/iio/adc/ad7280a.c b/drivers/staging/iio/adc/ad7280a.c
index 372d059..dddc03c 100644
--- a/drivers/staging/iio/adc/ad7280a.c
+++ b/drivers/staging/iio/adc/ad7280a.c
@@ -687,8 +687,10 @@ static irqreturn_t ad7280_event_handler(int irq, void *private)
 		return IRQ_HANDLED;
 
 	ret = ad7280_read_all_channels(st, st->scan_cnt, channels);
-	if (ret < 0)
+	if (ret < 0) {
+		kfree(channels);
 		return IRQ_HANDLED;
+	}
 
 	for (i = 0; i < st->scan_cnt; i++) {
 		if (((channels[i] >> 23) & 0xF) <= AD7280A_CELL_VOLTAGE_6) {
-- 
1.7.7.2


-- 
Jesper Juhl <jj@chaosbits.net>       http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.


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

end of thread, other threads:[~2011-12-05 22:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-06 21:49 [PATCH] [staging] iio, adc: Do not leak memory in ad7280_event_handler() Jesper Juhl
2011-11-06 21:49 ` Jonathan Cameron
2011-11-07  7:37   ` Lars-Peter Clausen
2011-11-27  0:43 ` Greg KH
2011-12-05 22:48   ` Jesper Juhl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox