All of lore.kernel.org
 help / color / mirror / Atom feed
* [lm-sensors] [PATCH] hwmon: Don't leak info in adm1275_probe
@ 2011-07-02 20:04 ` Jesper Juhl
  0 siblings, 0 replies; 6+ messages in thread
From: Jesper Juhl @ 2011-07-02 20:04 UTC (permalink / raw)
  To: linux-kernel; +Cc: lm-sensors, Guenter Roeck, Jean Delvare

In drivers/hwmon/adm1275.c:adm1275_probe() we'll leak the memory
allocated to 'info' if the call to i2c_smbus_read_byte_data() returns
less than zero.

This patch fixes the leak by simply calling kfree(info) when needed.
I also considered just moving the 'info' memory allocation below the
call to i2c_smbus_read_byte_data(), but I was not sure if it mattered
to get the -ENOMEM first in that case or if it would be bad to first
have a successful i2c_smbus_read_byte_data() call and then fail the
mem alloc, so I stuck with the safe option.

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

  Compile tested only.

diff --git a/drivers/hwmon/adm1275.c b/drivers/hwmon/adm1275.c
index c2ee204..2ebf255 100644
--- a/drivers/hwmon/adm1275.c
+++ b/drivers/hwmon/adm1275.c
@@ -43,8 +43,10 @@ static int adm1275_probe(struct i2c_client *client,
 		return -ENOMEM;
 
 	config = i2c_smbus_read_byte_data(client, ADM1275_PMON_CONFIG);
-	if (config < 0)
+	if (config < 0) {
+		kfree(info);
 		return config;
+	}
 
 	info->pages = 1;
 	info->direct[PSC_VOLTAGE_IN] = true;
-- 
1.7.6


-- 
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.


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

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

* [PATCH] hwmon: Don't leak info in adm1275_probe
@ 2011-07-02 20:04 ` Jesper Juhl
  0 siblings, 0 replies; 6+ messages in thread
From: Jesper Juhl @ 2011-07-02 20:04 UTC (permalink / raw)
  To: linux-kernel; +Cc: lm-sensors, Guenter Roeck, Jean Delvare

In drivers/hwmon/adm1275.c:adm1275_probe() we'll leak the memory
allocated to 'info' if the call to i2c_smbus_read_byte_data() returns
less than zero.

This patch fixes the leak by simply calling kfree(info) when needed.
I also considered just moving the 'info' memory allocation below the
call to i2c_smbus_read_byte_data(), but I was not sure if it mattered
to get the -ENOMEM first in that case or if it would be bad to first
have a successful i2c_smbus_read_byte_data() call and then fail the
mem alloc, so I stuck with the safe option.

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

  Compile tested only.

diff --git a/drivers/hwmon/adm1275.c b/drivers/hwmon/adm1275.c
index c2ee204..2ebf255 100644
--- a/drivers/hwmon/adm1275.c
+++ b/drivers/hwmon/adm1275.c
@@ -43,8 +43,10 @@ static int adm1275_probe(struct i2c_client *client,
 		return -ENOMEM;
 
 	config = i2c_smbus_read_byte_data(client, ADM1275_PMON_CONFIG);
-	if (config < 0)
+	if (config < 0) {
+		kfree(info);
 		return config;
+	}
 
 	info->pages = 1;
 	info->direct[PSC_VOLTAGE_IN] = true;
-- 
1.7.6


-- 
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] 6+ messages in thread

* Re: [lm-sensors] [PATCH] hwmon: Don't leak info in adm1275_probe
  2011-07-02 20:04 ` Jesper Juhl
@ 2011-07-02 21:14   ` Guenter Roeck
  -1 siblings, 0 replies; 6+ messages in thread
From: Guenter Roeck @ 2011-07-02 21:14 UTC (permalink / raw)
  To: Jesper Juhl
  Cc: linux-kernel@vger.kernel.org, lm-sensors@lm-sensors.org,
	Jean Delvare

On Sat, Jul 02, 2011 at 04:04:29PM -0400, Jesper Juhl wrote:
> In drivers/hwmon/adm1275.c:adm1275_probe() we'll leak the memory
> allocated to 'info' if the call to i2c_smbus_read_byte_data() returns
> less than zero.
> 
> This patch fixes the leak by simply calling kfree(info) when needed.
> I also considered just moving the 'info' memory allocation below the
> call to i2c_smbus_read_byte_data(), but I was not sure if it mattered
> to get the -ENOMEM first in that case or if it would be bad to first
> have a successful i2c_smbus_read_byte_data() call and then fail the
> mem alloc, so I stuck with the safe option.
> 
> Signed-off-by: Jesper Juhl <jj@chaosbits.net>

Hi Jesper,

the fix for this problem is already enqueued as 
"hwmon: (adm1275) Free allocated memory if probe function fails".

There is also a second error condition, which occurs if pmbus_do_probe() 
returns an error.

Thanks,
Guenter

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

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

* Re: [PATCH] hwmon: Don't leak info in adm1275_probe
@ 2011-07-02 21:14   ` Guenter Roeck
  0 siblings, 0 replies; 6+ messages in thread
From: Guenter Roeck @ 2011-07-02 21:14 UTC (permalink / raw)
  To: Jesper Juhl
  Cc: linux-kernel@vger.kernel.org, lm-sensors@lm-sensors.org,
	Jean Delvare

On Sat, Jul 02, 2011 at 04:04:29PM -0400, Jesper Juhl wrote:
> In drivers/hwmon/adm1275.c:adm1275_probe() we'll leak the memory
> allocated to 'info' if the call to i2c_smbus_read_byte_data() returns
> less than zero.
> 
> This patch fixes the leak by simply calling kfree(info) when needed.
> I also considered just moving the 'info' memory allocation below the
> call to i2c_smbus_read_byte_data(), but I was not sure if it mattered
> to get the -ENOMEM first in that case or if it would be bad to first
> have a successful i2c_smbus_read_byte_data() call and then fail the
> mem alloc, so I stuck with the safe option.
> 
> Signed-off-by: Jesper Juhl <jj@chaosbits.net>

Hi Jesper,

the fix for this problem is already enqueued as 
"hwmon: (adm1275) Free allocated memory if probe function fails".

There is also a second error condition, which occurs if pmbus_do_probe() 
returns an error.

Thanks,
Guenter

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

* Re: [lm-sensors] [PATCH] hwmon: Don't leak info in adm1275_probe
  2011-07-02 21:14   ` Guenter Roeck
@ 2011-07-02 21:18     ` Jesper Juhl
  -1 siblings, 0 replies; 6+ messages in thread
From: Jesper Juhl @ 2011-07-02 21:18 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: linux-kernel@vger.kernel.org, lm-sensors@lm-sensors.org,
	Jean Delvare

On Sat, 2 Jul 2011, Guenter Roeck wrote:

> On Sat, Jul 02, 2011 at 04:04:29PM -0400, Jesper Juhl wrote:
> > In drivers/hwmon/adm1275.c:adm1275_probe() we'll leak the memory
> > allocated to 'info' if the call to i2c_smbus_read_byte_data() returns
> > less than zero.
> > 
> > This patch fixes the leak by simply calling kfree(info) when needed.
> > I also considered just moving the 'info' memory allocation below the
> > call to i2c_smbus_read_byte_data(), but I was not sure if it mattered
> > to get the -ENOMEM first in that case or if it would be bad to first
> > have a successful i2c_smbus_read_byte_data() call and then fail the
> > mem alloc, so I stuck with the safe option.
> > 
> > Signed-off-by: Jesper Juhl <jj@chaosbits.net>
> 
> Hi Jesper,
> 
> the fix for this problem is already enqueued as 
> "hwmon: (adm1275) Free allocated memory if probe function fails".
> 
> There is also a second error condition, which occurs if pmbus_do_probe() 
> returns an error.
> 

Ok, cool, then that's taken care of. I'll just drop the patch from my 
personal queue. Thanks.

-- 
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.


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

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

* Re: [PATCH] hwmon: Don't leak info in adm1275_probe
@ 2011-07-02 21:18     ` Jesper Juhl
  0 siblings, 0 replies; 6+ messages in thread
From: Jesper Juhl @ 2011-07-02 21:18 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: linux-kernel@vger.kernel.org, lm-sensors@lm-sensors.org,
	Jean Delvare

On Sat, 2 Jul 2011, Guenter Roeck wrote:

> On Sat, Jul 02, 2011 at 04:04:29PM -0400, Jesper Juhl wrote:
> > In drivers/hwmon/adm1275.c:adm1275_probe() we'll leak the memory
> > allocated to 'info' if the call to i2c_smbus_read_byte_data() returns
> > less than zero.
> > 
> > This patch fixes the leak by simply calling kfree(info) when needed.
> > I also considered just moving the 'info' memory allocation below the
> > call to i2c_smbus_read_byte_data(), but I was not sure if it mattered
> > to get the -ENOMEM first in that case or if it would be bad to first
> > have a successful i2c_smbus_read_byte_data() call and then fail the
> > mem alloc, so I stuck with the safe option.
> > 
> > Signed-off-by: Jesper Juhl <jj@chaosbits.net>
> 
> Hi Jesper,
> 
> the fix for this problem is already enqueued as 
> "hwmon: (adm1275) Free allocated memory if probe function fails".
> 
> There is also a second error condition, which occurs if pmbus_do_probe() 
> returns an error.
> 

Ok, cool, then that's taken care of. I'll just drop the patch from my 
personal queue. Thanks.

-- 
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] 6+ messages in thread

end of thread, other threads:[~2011-07-02 21:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-02 20:04 [lm-sensors] [PATCH] hwmon: Don't leak info in adm1275_probe Jesper Juhl
2011-07-02 20:04 ` Jesper Juhl
2011-07-02 21:14 ` [lm-sensors] " Guenter Roeck
2011-07-02 21:14   ` Guenter Roeck
2011-07-02 21:18   ` [lm-sensors] " Jesper Juhl
2011-07-02 21:18     ` Jesper Juhl

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.