[PATCH v2 1/4] platform/x86: panasonic-laptop: Fix rollback path in acpi_pcc_hotkey_add()
From: Rafael J. Wysocki
Date: Wed Mar 18 2026 - 15:44:55 EST
From: "Rafael J. Wysocki" <rafael.j.wysocki@xxxxxxxxx>
The rollback ordering in acpi_pcc_hotkey_add() is different from the
cleanup ordering in acpi_pcc_hotkey_remove(). Moreover, the latter
calls pcc_unregister_optd_notifier() unconditionally while the former
never calls it and the OPTD notifier is only registered if pcc->platform
is not NULL.
Address that by:
* moving the pcc_register_optd_notifier() call after the device_create_file()
return value check,
* adding a new label to the acpi_pcc_hotkey_add() rollback code for
pcc_register_optd_notifier() error handling,
* moving the pcc_unregister_optd_notifier() call in acpi_pcc_hotkey_remove()
before the removal of the cdpower sysfs attribute.
Also update pcc_register_optd_notifier() to return an error when
acpi_install_notify_handler() fails.
Fixes: d5a81d8e864b ("platform/x86: panasonic-laptop: Add support for optical driver power in Y and W series")
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>
---
v1 -> v2: New patch
---
drivers/platform/x86/panasonic-laptop.c | 23 ++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/drivers/platform/x86/panasonic-laptop.c b/drivers/platform/x86/panasonic-laptop.c
index d923ddaa4849..debab5916782 100644
--- a/drivers/platform/x86/panasonic-laptop.c
+++ b/drivers/platform/x86/panasonic-laptop.c
@@ -897,15 +897,15 @@ static int pcc_register_optd_notifier(struct pcc_acpi *pcc, char *node)
acpi_handle handle;
status = acpi_get_handle(NULL, node, &handle);
+ if (ACPI_FAILURE(status))
+ return -ENODEV;
- if (ACPI_SUCCESS(status)) {
- status = acpi_install_notify_handler(handle,
- ACPI_SYSTEM_NOTIFY,
- pcc_optd_notify, pcc);
- if (ACPI_FAILURE(status))
- pr_err("Failed to register notify on %s\n", node);
- } else
+ status = acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
+ pcc_optd_notify, pcc);
+ if (ACPI_FAILURE(status)) {
+ pr_err("Failed to register notify on %s\n", node);
return -ENODEV;
+ }
return 0;
}
@@ -1093,9 +1093,12 @@ static int acpi_pcc_hotkey_add(struct acpi_device *device)
}
result = device_create_file(&pcc->platform->dev,
&dev_attr_cdpower);
- pcc_register_optd_notifier(pcc, "\\_SB.PCI0.EHCI.ERHB.OPTD");
if (result)
goto out_platform;
+
+ result = pcc_register_optd_notifier(pcc, "\\_SB.PCI0.EHCI.ERHB.OPTD");
+ if (result)
+ goto out_cdpower;
} else {
pcc->platform = NULL;
}
@@ -1103,6 +1106,8 @@ static int acpi_pcc_hotkey_add(struct acpi_device *device)
i8042_install_filter(panasonic_i8042_filter, NULL);
return 0;
+out_cdpower:
+ device_remove_file(&pcc->platform->dev, &dev_attr_cdpower);
out_platform:
platform_device_unregister(pcc->platform);
out_sysfs:
@@ -1129,10 +1134,10 @@ static void acpi_pcc_hotkey_remove(struct acpi_device *device)
i8042_remove_filter(panasonic_i8042_filter);
if (pcc->platform) {
+ pcc_unregister_optd_notifier(pcc, "\\_SB.PCI0.EHCI.ERHB.OPTD");
device_remove_file(&pcc->platform->dev, &dev_attr_cdpower);
platform_device_unregister(pcc->platform);
}
- pcc_unregister_optd_notifier(pcc, "\\_SB.PCI0.EHCI.ERHB.OPTD");
sysfs_remove_group(&device->dev.kobj, &pcc_attr_group);
--
2.51.0