[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20230613164001.5vdk4pajbrwgdam4@pali>
Date: Tue, 13 Jun 2023 18:40:01 +0200
From: Pali Rohár <pali@...nel.org>
To: Michal Wilczynski <michal.wilczynski@...el.com>
Cc: linux-acpi@...r.kernel.org, rafael@...nel.org,
andriy.shevchenko@...el.com, ilpo.jarvinen@...ux.intel.com,
hdegoede@...hat.com, markgross@...nel.org, fengguang.wu@...el.com,
dvhart@...ux.intel.com, platform-driver-x86@...r.kernel.org,
linux-kernel@...r.kernel.org,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Subject: Re: [PATCH v2] platform/x86/dell/dell-rbtn: Fix resources leaking on
error path
On Tuesday 13 June 2023 11:43:10 Michal Wilczynski wrote:
> Currently rbtn_add() in case of failure is leaking resources. Fix this
> by adding a proper rollback. Move devm_kzalloc() before rbtn_acquire(),
> so it doesn't require rollback in case of failure. While at it, remove
> unnecessary assignment of NULL to device->driver_data and unnecessary
> whitespace, plus add a break for the default case in a switch.
>
> Suggested-by: Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>
> Fixes: 817a5cdb40c8 ("dell-rbtn: Dell Airplane Mode Switch driver")
> Signed-off-by: Michal Wilczynski <michal.wilczynski@...el.com>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
> Acked-by: Rafael J. Wysocki <rafael@...nel.org>
Looks good,
Reviewed-by: Pali Rohár <pali@...nel.org>
> ---
> v2:
> - move devm_kzalloc before rbtn_acquire as suggested
>
> drivers/platform/x86/dell/dell-rbtn.c | 13 +++++++------
> 1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/platform/x86/dell/dell-rbtn.c b/drivers/platform/x86/dell/dell-rbtn.c
> index aa0e6c907494..c8fcb537fd65 100644
> --- a/drivers/platform/x86/dell/dell-rbtn.c
> +++ b/drivers/platform/x86/dell/dell-rbtn.c
> @@ -395,16 +395,16 @@ static int rbtn_add(struct acpi_device *device)
> return -EINVAL;
> }
>
> + rbtn_data = devm_kzalloc(&device->dev, sizeof(*rbtn_data), GFP_KERNEL);
> + if (!rbtn_data)
> + return -ENOMEM;
> +
> ret = rbtn_acquire(device, true);
> if (ret < 0) {
> dev_err(&device->dev, "Cannot enable device\n");
> return ret;
> }
>
> - rbtn_data = devm_kzalloc(&device->dev, sizeof(*rbtn_data), GFP_KERNEL);
> - if (!rbtn_data)
> - return -ENOMEM;
> -
> rbtn_data->type = type;
> device->driver_data = rbtn_data;
>
> @@ -420,10 +420,12 @@ static int rbtn_add(struct acpi_device *device)
> break;
> default:
> ret = -EINVAL;
> + break;
> }
> + if (ret)
> + rbtn_acquire(device, false);
>
> return ret;
> -
> }
>
> static void rbtn_remove(struct acpi_device *device)
> @@ -442,7 +444,6 @@ static void rbtn_remove(struct acpi_device *device)
> }
>
> rbtn_acquire(device, false);
> - device->driver_data = NULL;
> }
>
> static void rbtn_notify(struct acpi_device *device, u32 event)
> --
> 2.41.0
>
Powered by blists - more mailing lists