Skip to content

Commit 966cca7

Browse files
mwilczyjwrdegoede
authored andcommitted
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: Ilpo Järvinen <[email protected]> Suggested-by: Pali Rohár <[email protected]> Fixes: 817a5cd ("dell-rbtn: Dell Airplane Mode Switch driver") Signed-off-by: Michal Wilczynski <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Acked-by: Rafael J. Wysocki <[email protected]> Reviewed-by: Pali Rohár <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Hans de Goede <[email protected]> Signed-off-by: Hans de Goede <[email protected]>
1 parent 9ce9308 commit 966cca7

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

drivers/platform/x86/dell/dell-rbtn.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -395,16 +395,16 @@ static int rbtn_add(struct acpi_device *device)
395395
return -EINVAL;
396396
}
397397

398+
rbtn_data = devm_kzalloc(&device->dev, sizeof(*rbtn_data), GFP_KERNEL);
399+
if (!rbtn_data)
400+
return -ENOMEM;
401+
398402
ret = rbtn_acquire(device, true);
399403
if (ret < 0) {
400404
dev_err(&device->dev, "Cannot enable device\n");
401405
return ret;
402406
}
403407

404-
rbtn_data = devm_kzalloc(&device->dev, sizeof(*rbtn_data), GFP_KERNEL);
405-
if (!rbtn_data)
406-
return -ENOMEM;
407-
408408
rbtn_data->type = type;
409409
device->driver_data = rbtn_data;
410410

@@ -420,10 +420,12 @@ static int rbtn_add(struct acpi_device *device)
420420
break;
421421
default:
422422
ret = -EINVAL;
423+
break;
423424
}
425+
if (ret)
426+
rbtn_acquire(device, false);
424427

425428
return ret;
426-
427429
}
428430

429431
static void rbtn_remove(struct acpi_device *device)
@@ -442,7 +444,6 @@ static void rbtn_remove(struct acpi_device *device)
442444
}
443445

444446
rbtn_acquire(device, false);
445-
device->driver_data = NULL;
446447
}
447448

448449
static void rbtn_notify(struct acpi_device *device, u32 event)

0 commit comments

Comments
 (0)