Commit 966cca72 authored by Michal Wilczynski's avatar Michal Wilczynski Committed by Hans de Goede

platform/x86/dell/dell-rbtn: Fix resources leaking on error path

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: default avatarIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Suggested-by: default avatarPali Rohár <pali@kernel.org>
Fixes: 817a5cdb ("dell-rbtn: Dell Airplane Mode Switch driver")
Signed-off-by: default avatarMichal Wilczynski <michal.wilczynski@intel.com>
Reviewed-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: default avatarRafael J. Wysocki <rafael@kernel.org>
Reviewed-by: default avatarPali Rohár <pali@kernel.org>
Link: https://lore.kernel.org/r/20230613084310.2775896-1-michal.wilczynski@intel.comReviewed-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
parent 9ce93086
...@@ -395,16 +395,16 @@ static int rbtn_add(struct acpi_device *device) ...@@ -395,16 +395,16 @@ static int rbtn_add(struct acpi_device *device)
return -EINVAL; return -EINVAL;
} }
rbtn_data = devm_kzalloc(&device->dev, sizeof(*rbtn_data), GFP_KERNEL);
if (!rbtn_data)
return -ENOMEM;
ret = rbtn_acquire(device, true); ret = rbtn_acquire(device, true);
if (ret < 0) { if (ret < 0) {
dev_err(&device->dev, "Cannot enable device\n"); dev_err(&device->dev, "Cannot enable device\n");
return ret; return ret;
} }
rbtn_data = devm_kzalloc(&device->dev, sizeof(*rbtn_data), GFP_KERNEL);
if (!rbtn_data)
return -ENOMEM;
rbtn_data->type = type; rbtn_data->type = type;
device->driver_data = rbtn_data; device->driver_data = rbtn_data;
...@@ -420,10 +420,12 @@ static int rbtn_add(struct acpi_device *device) ...@@ -420,10 +420,12 @@ static int rbtn_add(struct acpi_device *device)
break; break;
default: default:
ret = -EINVAL; ret = -EINVAL;
break;
} }
if (ret)
rbtn_acquire(device, false);
return ret; return ret;
} }
static void rbtn_remove(struct acpi_device *device) static void rbtn_remove(struct acpi_device *device)
...@@ -442,7 +444,6 @@ static void rbtn_remove(struct acpi_device *device) ...@@ -442,7 +444,6 @@ static void rbtn_remove(struct acpi_device *device)
} }
rbtn_acquire(device, false); rbtn_acquire(device, false);
device->driver_data = NULL;
} }
static void rbtn_notify(struct acpi_device *device, u32 event) static void rbtn_notify(struct acpi_device *device, u32 event)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment