Linux-Hwmon Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] hwmon: (acpi_power_meter) Fix potential memory leak in acpi_power_meter_add()
@ 2020-06-25  4:32 Misono Tomohiro
  2020-06-25 13:51 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Misono Tomohiro @ 2020-06-25  4:32 UTC (permalink / raw)
  To: linux, linux-hwmon; +Cc: misono.tomohiro

Although it rarely happens, we should call free_capabilities()
if error happens after read_capabilities() to free allocated strings.

Fixes: commit de584afa5e188 ("hwmon driver for ACPI 4.0 power meters")
Signed-off-by: Misono Tomohiro <misono.tomohiro@jp.fujitsu.com>
---
 drivers/hwmon/acpi_power_meter.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
index 0db8ef4fd6e1..a270b975e90b 100644
--- a/drivers/hwmon/acpi_power_meter.c
+++ b/drivers/hwmon/acpi_power_meter.c
@@ -883,7 +883,7 @@ static int acpi_power_meter_add(struct acpi_device *device)
 
 	res = setup_attrs(resource);
 	if (res)
-		goto exit_free;
+		goto exit_free_capability;
 
 	resource->hwmon_dev = hwmon_device_register(&device->dev);
 	if (IS_ERR(resource->hwmon_dev)) {
@@ -896,6 +896,8 @@ static int acpi_power_meter_add(struct acpi_device *device)
 
 exit_remove:
 	remove_attrs(resource);
+exit_free_capability:
+	free_capabilities(resource);
 exit_free:
 	kfree(resource);
 exit:
-- 
2.21.3


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

* Re: [PATCH] hwmon: (acpi_power_meter) Fix potential memory leak in acpi_power_meter_add()
  2020-06-25  4:32 [PATCH] hwmon: (acpi_power_meter) Fix potential memory leak in acpi_power_meter_add() Misono Tomohiro
@ 2020-06-25 13:51 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2020-06-25 13:51 UTC (permalink / raw)
  To: Misono Tomohiro; +Cc: linux-hwmon

On Thu, Jun 25, 2020 at 01:32:42PM +0900, Misono Tomohiro wrote:
> Although it rarely happens, we should call free_capabilities()
> if error happens after read_capabilities() to free allocated strings.
> 
> Fixes: commit de584afa5e188 ("hwmon driver for ACPI 4.0 power meters")
> Signed-off-by: Misono Tomohiro <misono.tomohiro@jp.fujitsu.com>

Applied.

Thanks,
Guenter

> ---
>  drivers/hwmon/acpi_power_meter.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
> index 0db8ef4fd6e1..a270b975e90b 100644
> --- a/drivers/hwmon/acpi_power_meter.c
> +++ b/drivers/hwmon/acpi_power_meter.c
> @@ -883,7 +883,7 @@ static int acpi_power_meter_add(struct acpi_device *device)
>  
>  	res = setup_attrs(resource);
>  	if (res)
> -		goto exit_free;
> +		goto exit_free_capability;
>  
>  	resource->hwmon_dev = hwmon_device_register(&device->dev);
>  	if (IS_ERR(resource->hwmon_dev)) {
> @@ -896,6 +896,8 @@ static int acpi_power_meter_add(struct acpi_device *device)
>  
>  exit_remove:
>  	remove_attrs(resource);
> +exit_free_capability:
> +	free_capabilities(resource);
>  exit_free:
>  	kfree(resource);
>  exit:

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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-25  4:32 [PATCH] hwmon: (acpi_power_meter) Fix potential memory leak in acpi_power_meter_add() Misono Tomohiro
2020-06-25 13:51 ` Guenter Roeck

Linux-Hwmon Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-hwmon/0 linux-hwmon/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-hwmon linux-hwmon/ https://lore.kernel.org/linux-hwmon \
		linux-hwmon@vger.kernel.org
	public-inbox-index linux-hwmon

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-hwmon


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git