* [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
* Re: [PATCH] [staging] iio, adc: Do not leak memory in ad7280_event_handler()
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
1 sibling, 1 reply; 5+ messages in thread
From: Jonathan Cameron @ 2011-11-06 21:49 UTC (permalink / raw)
To: Jesper Juhl
Cc: linux-iio, devel, linux-kernel, Paul Gortmaker, Michael Hennerich,
Greg Kroah-Hartman, Jonathan Cameron
On 11/06/2011 09:49 PM, Jesper Juhl wrote:
> 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.
>
Looks right to me - good spot. Only choice is whether a single exit
point makes sense rather than undwinding it here? Michael?
I'm happy with either solution, hence the ack.
> Signed-off-by: Jesper Juhl <jj@chaosbits.net>
Acked-by: Jonathan Cameron <jic23@cam.ac.uk>
> ---
> 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) {
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] [staging] iio, adc: Do not leak memory in ad7280_event_handler()
2011-11-06 21:49 ` Jonathan Cameron
@ 2011-11-07 7:37 ` Lars-Peter Clausen
0 siblings, 0 replies; 5+ messages in thread
From: Lars-Peter Clausen @ 2011-11-07 7:37 UTC (permalink / raw)
To: Jonathan Cameron
Cc: Jesper Juhl, linux-iio, devel, linux-kernel, Paul Gortmaker,
Michael Hennerich, Greg Kroah-Hartman, Jonathan Cameron
On 11/06/2011 10:49 PM, Jonathan Cameron wrote:
> On 11/06/2011 09:49 PM, Jesper Juhl wrote:
>> 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.
>>
> Looks right to me - good spot. Only choice is whether a single exit
> point makes sense rather than undwinding it here? Michael?
> I'm happy with either solution, hence the ack.
A similar patch has already been sent last week and should be in Gregs queue.
See: http://comments.gmane.org/gmane.linux.kernel.iio/2433
- Lars
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] [staging] iio, adc: Do not leak memory in ad7280_event_handler()
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-27 0:43 ` Greg KH
2011-12-05 22:48 ` Jesper Juhl
1 sibling, 1 reply; 5+ messages in thread
From: Greg KH @ 2011-11-27 0:43 UTC (permalink / raw)
To: Jesper Juhl
Cc: linux-iio, devel, linux-kernel, Paul Gortmaker, Michael Hennerich,
Greg Kroah-Hartman, Jonathan Cameron
On Sun, Nov 06, 2011 at 10:49:22PM +0100, Jesper Juhl wrote:
> 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.
This patch no longer applies to my tree, can you redo it against the
next linux-next release and resend it?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] [staging] iio, adc: Do not leak memory in ad7280_event_handler()
2011-11-27 0:43 ` Greg KH
@ 2011-12-05 22:48 ` Jesper Juhl
0 siblings, 0 replies; 5+ messages in thread
From: Jesper Juhl @ 2011-12-05 22:48 UTC (permalink / raw)
To: Greg KH
Cc: linux-iio, devel, linux-kernel, Paul Gortmaker, Michael Hennerich,
Greg Kroah-Hartman, Jonathan Cameron
On Sat, 26 Nov 2011, Greg KH wrote:
> On Sun, Nov 06, 2011 at 10:49:22PM +0100, Jesper Juhl wrote:
> > 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.
>
> This patch no longer applies to my tree, can you redo it against the
> next linux-next release and resend it?
>
> thanks,
>
> greg k-h
Sure. I'll take a look at it this weekend.
--
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 [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