* [PATCH v4 1/5] platform/x86: panasonic-laptop: Make pcc_register_optd_notifier() void
2026-03-20 10:29 [PATCH v4 0/5] platform/x86: panasonic-laptop: Bind to a platform device instead of an ACPI one Rafael J. Wysocki
@ 2026-03-20 10:30 ` Rafael J. Wysocki
2026-03-20 10:31 ` [PATCH v4 2/5] platform/x86: panasonic-laptop: Fix OPTD notifier registration and cleanup Rafael J. Wysocki
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Rafael J. Wysocki @ 2026-03-20 10:30 UTC (permalink / raw)
To: Ilpo Järvinen
Cc: LKML, Linux ACPI, Hans de Goede, platform-driver-x86,
Kenneth Chan
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Convert pcc_register_optd_notifier() whose return value is never used to
a void function.
No intentional functional impact.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
v3 -> v4: No changes
v2 -> v3: New patch
---
drivers/platform/x86/panasonic-laptop.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/drivers/platform/x86/panasonic-laptop.c b/drivers/platform/x86/panasonic-laptop.c
index d923ddaa4849..a481f2602ce3 100644
--- a/drivers/platform/x86/panasonic-laptop.c
+++ b/drivers/platform/x86/panasonic-laptop.c
@@ -891,7 +891,7 @@ static void pcc_optd_notify(acpi_handle handle, u32 event, void *data)
set_optd_power_state(0);
}
-static int pcc_register_optd_notifier(struct pcc_acpi *pcc, char *node)
+static void pcc_register_optd_notifier(struct pcc_acpi *pcc, char *node)
{
acpi_status status;
acpi_handle handle;
@@ -904,10 +904,7 @@ static int pcc_register_optd_notifier(struct pcc_acpi *pcc, char *node)
pcc_optd_notify, pcc);
if (ACPI_FAILURE(status))
pr_err("Failed to register notify on %s\n", node);
- } else
- return -ENODEV;
-
- return 0;
+ }
}
static void pcc_unregister_optd_notifier(struct pcc_acpi *pcc, char *node)
--
2.51.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v4 2/5] platform/x86: panasonic-laptop: Fix OPTD notifier registration and cleanup
2026-03-20 10:29 [PATCH v4 0/5] platform/x86: panasonic-laptop: Bind to a platform device instead of an ACPI one Rafael J. Wysocki
2026-03-20 10:30 ` [PATCH v4 1/5] platform/x86: panasonic-laptop: Make pcc_register_optd_notifier() void Rafael J. Wysocki
@ 2026-03-20 10:31 ` Rafael J. Wysocki
2026-03-20 10:33 ` [PATCH v4 3/5] platform/x86: panasonic-laptop: Remove redundant checks from 3 functions Rafael J. Wysocki
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Rafael J. Wysocki @ 2026-03-20 10:31 UTC (permalink / raw)
To: Ilpo Järvinen
Cc: LKML, Linux ACPI, Hans de Goede, platform-driver-x86,
Kenneth Chan
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
An ACPI notify handler is leaked if device_create_file() returns an
error in acpi_pcc_hotkey_add().
Also, it is pointless to call pcc_unregister_optd_notifier() in
acpi_pcc_hotkey_remove() if pcc->platform is NULL and it is better
to arrange the cleanup code in that function in the same order as
the rollback code in acpi_pcc_hotkey_add().
Address the above by placing the pcc_register_optd_notifier() call in
acpi_pcc_hotkey_add() after the device_create_file() return value
check and placing the pcc_unregister_optd_notifier() call in
acpi_pcc_hotkey_remove() right before the device_remove_file() call.
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@intel.com>
---
v3 -> v4: No changes
v2 -> v3: Do not fail probing on OPTD registration errors (note that it is
not a bug to attempt to unregister an ACPI notify handler that has not
been registered)
v1 -> v2: New patch
---
drivers/platform/x86/panasonic-laptop.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/platform/x86/panasonic-laptop.c b/drivers/platform/x86/panasonic-laptop.c
index a481f2602ce3..56b4e61d7e5c 100644
--- a/drivers/platform/x86/panasonic-laptop.c
+++ b/drivers/platform/x86/panasonic-laptop.c
@@ -1090,9 +1090,10 @@ 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;
+
+ pcc_register_optd_notifier(pcc, "\\_SB.PCI0.EHCI.ERHB.OPTD");
} else {
pcc->platform = NULL;
}
@@ -1126,10 +1127,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
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v4 3/5] platform/x86: panasonic-laptop: Remove redundant checks from 3 functions
2026-03-20 10:29 [PATCH v4 0/5] platform/x86: panasonic-laptop: Bind to a platform device instead of an ACPI one Rafael J. Wysocki
2026-03-20 10:30 ` [PATCH v4 1/5] platform/x86: panasonic-laptop: Make pcc_register_optd_notifier() void Rafael J. Wysocki
2026-03-20 10:31 ` [PATCH v4 2/5] platform/x86: panasonic-laptop: Fix OPTD notifier registration and cleanup Rafael J. Wysocki
@ 2026-03-20 10:33 ` Rafael J. Wysocki
2026-03-20 10:34 ` [PATCH v4 4/5] platform/x86: panasonic-laptop: Register ACPI notify handler directly Rafael J. Wysocki
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Rafael J. Wysocki @ 2026-03-20 10:33 UTC (permalink / raw)
To: Ilpo Järvinen
Cc: LKML, Linux ACPI, Hans de Goede, platform-driver-x86,
Kenneth Chan
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
The device pointer cannot be NULL in acpi_pcc_hotkey_add() and
acpi_pcc_hotkey_remove() because these functions are ACPI driver
callbacks and NULL is never passed to any of them as an argument.
Likewise, acpi_pcc_hotkey_resume() is a resume callback of a
device driver and NULL is never passed to it as an argument, so
the dev pointer in it cannot be NULL.
Moreover, since acpi_pcc_hotkey_remove() and acpi_pcc_hotkey_resume()
can only run after acpi_pcc_hotkey_add() has completed successfully,
the acpi_driver_data() of the device object used by them cannot be
NULL when they run.
Drop all of the redundant NULL checks of the pointers mentioned above.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
v1 -> v4: No changes
---
drivers/platform/x86/panasonic-laptop.c | 15 +--------------
1 file changed, 1 insertion(+), 14 deletions(-)
diff --git a/drivers/platform/x86/panasonic-laptop.c b/drivers/platform/x86/panasonic-laptop.c
index 56b4e61d7e5c..188ec597a14e 100644
--- a/drivers/platform/x86/panasonic-laptop.c
+++ b/drivers/platform/x86/panasonic-laptop.c
@@ -965,14 +965,7 @@ static int acpi_pcc_init_input(struct pcc_acpi *pcc)
#ifdef CONFIG_PM_SLEEP
static int acpi_pcc_hotkey_resume(struct device *dev)
{
- struct pcc_acpi *pcc;
-
- if (!dev)
- return -EINVAL;
-
- pcc = acpi_driver_data(to_acpi_device(dev));
- if (!pcc)
- return -EINVAL;
+ struct pcc_acpi *pcc = acpi_driver_data(to_acpi_device(dev));
if (pcc->num_sifr > SINF_MUTE)
acpi_pcc_write_sset(pcc, SINF_MUTE, pcc->mute);
@@ -994,9 +987,6 @@ static int acpi_pcc_hotkey_add(struct acpi_device *device)
struct pcc_acpi *pcc;
int num_sifr, result;
- if (!device)
- return -EINVAL;
-
num_sifr = acpi_pcc_get_sqty(device);
/*
@@ -1121,9 +1111,6 @@ static void acpi_pcc_hotkey_remove(struct acpi_device *device)
{
struct pcc_acpi *pcc = acpi_driver_data(device);
- if (!device || !pcc)
- return;
-
i8042_remove_filter(panasonic_i8042_filter);
if (pcc->platform) {
--
2.51.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v4 4/5] platform/x86: panasonic-laptop: Register ACPI notify handler directly
2026-03-20 10:29 [PATCH v4 0/5] platform/x86: panasonic-laptop: Bind to a platform device instead of an ACPI one Rafael J. Wysocki
` (2 preceding siblings ...)
2026-03-20 10:33 ` [PATCH v4 3/5] platform/x86: panasonic-laptop: Remove redundant checks from 3 functions Rafael J. Wysocki
@ 2026-03-20 10:34 ` Rafael J. Wysocki
2026-03-20 10:35 ` [PATCH v4 5/5] platform/x86: panasonic-laptop: Convert ACPI driver to a platform one Rafael J. Wysocki
2026-03-23 10:46 ` [PATCH v4 0/5] platform/x86: panasonic-laptop: Bind to a platform device instead of an ACPI one Ilpo Järvinen
5 siblings, 0 replies; 7+ messages in thread
From: Rafael J. Wysocki @ 2026-03-20 10:34 UTC (permalink / raw)
To: Ilpo Järvinen
Cc: LKML, Linux ACPI, Hans de Goede, platform-driver-x86,
Kenneth Chan
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
To facilitate subsequent conversion of the driver to a platform one,
make it install an ACPI notify handler directly instead of using
a .notify() callback in struct acpi_driver.
No intentional functional impact.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
v2 -> v4: No changes
v1 -> v2: Adjust remove code ordering to match probe rollback code
ordering (Ilpo)
---
drivers/platform/x86/panasonic-laptop.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/drivers/platform/x86/panasonic-laptop.c b/drivers/platform/x86/panasonic-laptop.c
index 188ec597a14e..e563298a6672 100644
--- a/drivers/platform/x86/panasonic-laptop.c
+++ b/drivers/platform/x86/panasonic-laptop.c
@@ -185,7 +185,7 @@ enum SINF_BITS { SINF_NUM_BATTERIES = 0,
static int acpi_pcc_hotkey_add(struct acpi_device *device);
static void acpi_pcc_hotkey_remove(struct acpi_device *device);
-static void acpi_pcc_hotkey_notify(struct acpi_device *device, u32 event);
+static void acpi_pcc_hotkey_notify(acpi_handle handle, u32 event, void *data);
static const struct acpi_device_id pcc_device_ids[] = {
{ "MAT0012", 0},
@@ -208,7 +208,6 @@ static struct acpi_driver acpi_pcc_driver = {
.ops = {
.add = acpi_pcc_hotkey_add,
.remove = acpi_pcc_hotkey_remove,
- .notify = acpi_pcc_hotkey_notify,
},
.drv.pm = &acpi_pcc_hotkey_pm,
};
@@ -869,9 +868,9 @@ static void acpi_pcc_generate_keyinput(struct pcc_acpi *pcc)
pr_err("Unknown hotkey event: 0x%04llx\n", result);
}
-static void acpi_pcc_hotkey_notify(struct acpi_device *device, u32 event)
+static void acpi_pcc_hotkey_notify(acpi_handle handle, u32 event, void *data)
{
- struct pcc_acpi *pcc = acpi_driver_data(device);
+ struct pcc_acpi *pcc = data;
switch (event) {
case HKEY_NOTIFY:
@@ -1070,13 +1069,18 @@ static int acpi_pcc_hotkey_add(struct acpi_device *device)
if (result)
goto out_backlight;
+ result = acpi_dev_install_notify_handler(device, ACPI_DEVICE_NOTIFY,
+ acpi_pcc_hotkey_notify, pcc);
+ if (result)
+ goto out_sysfs;
+
/* optical drive initialization */
if (ACPI_SUCCESS(check_optd_present())) {
pcc->platform = platform_device_register_simple("panasonic",
PLATFORM_DEVID_NONE, NULL, 0);
if (IS_ERR(pcc->platform)) {
result = PTR_ERR(pcc->platform);
- goto out_sysfs;
+ goto out_notify_handler;
}
result = device_create_file(&pcc->platform->dev,
&dev_attr_cdpower);
@@ -1093,6 +1097,9 @@ static int acpi_pcc_hotkey_add(struct acpi_device *device)
out_platform:
platform_device_unregister(pcc->platform);
+out_notify_handler:
+ acpi_dev_remove_notify_handler(device, ACPI_DEVICE_NOTIFY,
+ acpi_pcc_hotkey_notify);
out_sysfs:
sysfs_remove_group(&device->dev.kobj, &pcc_attr_group);
out_backlight:
@@ -1119,6 +1126,9 @@ static void acpi_pcc_hotkey_remove(struct acpi_device *device)
platform_device_unregister(pcc->platform);
}
+ acpi_dev_remove_notify_handler(device, ACPI_DEVICE_NOTIFY,
+ acpi_pcc_hotkey_notify);
+
sysfs_remove_group(&device->dev.kobj, &pcc_attr_group);
backlight_device_unregister(pcc->backlight);
--
2.51.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v4 5/5] platform/x86: panasonic-laptop: Convert ACPI driver to a platform one
2026-03-20 10:29 [PATCH v4 0/5] platform/x86: panasonic-laptop: Bind to a platform device instead of an ACPI one Rafael J. Wysocki
` (3 preceding siblings ...)
2026-03-20 10:34 ` [PATCH v4 4/5] platform/x86: panasonic-laptop: Register ACPI notify handler directly Rafael J. Wysocki
@ 2026-03-20 10:35 ` Rafael J. Wysocki
2026-03-23 10:46 ` [PATCH v4 0/5] platform/x86: panasonic-laptop: Bind to a platform device instead of an ACPI one Ilpo Järvinen
5 siblings, 0 replies; 7+ messages in thread
From: Rafael J. Wysocki @ 2026-03-20 10:35 UTC (permalink / raw)
To: Ilpo Järvinen
Cc: LKML, Linux ACPI, Hans de Goede, platform-driver-x86,
Kenneth Chan
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
In all cases in which a struct acpi_driver is used for binding a driver
to an ACPI device object, a corresponding platform device is created by
the ACPI core and that device is regarded as a proper representation of
underlying hardware. Accordingly, a struct platform_driver should be
used by driver code to bind to that device. There are multiple reasons
why drivers should not bind directly to ACPI device objects [1].
Overall, it is better to bind drivers to platform devices than to their
ACPI companions, so convert the Panasonic laptop ACPI driver to a platform
one.
While this is not expected to alter functionality, it changes sysfs
layout and so it will be visible to user space.
To maintain backwards compatibility with possibly existing user space,
the sysfs attributes created by the driver under the ACPI device object
used by it are not relocated. Accordingly, the driver will continue to
use the driver_data pointer in struct acpi_device which needs to be
cleared on driver removal.
Link: https://lore.kernel.org/all/2396510.ElGaqSPkdT@rafael.j.wysocki/ [1]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
v3 -> v4: Clear device->driver_data in the probe rollback path
v1 -> v3: No changes
---
drivers/platform/x86/panasonic-laptop.c | 34 ++++++++++++++-----------
1 file changed, 19 insertions(+), 15 deletions(-)
diff --git a/drivers/platform/x86/panasonic-laptop.c b/drivers/platform/x86/panasonic-laptop.c
index e563298a6672..1337f7c49805 100644
--- a/drivers/platform/x86/panasonic-laptop.c
+++ b/drivers/platform/x86/panasonic-laptop.c
@@ -183,8 +183,8 @@ enum SINF_BITS { SINF_NUM_BATTERIES = 0,
};
/* R1 handles SINF_AC_CUR_BRIGHT as SINF_CUR_BRIGHT, doesn't know AC state */
-static int acpi_pcc_hotkey_add(struct acpi_device *device);
-static void acpi_pcc_hotkey_remove(struct acpi_device *device);
+static int acpi_pcc_hotkey_probe(struct platform_device *pdev);
+static void acpi_pcc_hotkey_remove(struct platform_device *pdev);
static void acpi_pcc_hotkey_notify(acpi_handle handle, u32 event, void *data);
static const struct acpi_device_id pcc_device_ids[] = {
@@ -201,15 +201,14 @@ static int acpi_pcc_hotkey_resume(struct device *dev);
#endif
static SIMPLE_DEV_PM_OPS(acpi_pcc_hotkey_pm, NULL, acpi_pcc_hotkey_resume);
-static struct acpi_driver acpi_pcc_driver = {
- .name = ACPI_PCC_DRIVER_NAME,
- .class = ACPI_PCC_CLASS,
- .ids = pcc_device_ids,
- .ops = {
- .add = acpi_pcc_hotkey_add,
- .remove = acpi_pcc_hotkey_remove,
- },
- .drv.pm = &acpi_pcc_hotkey_pm,
+static struct platform_driver acpi_pcc_driver = {
+ .probe = acpi_pcc_hotkey_probe,
+ .remove = acpi_pcc_hotkey_remove,
+ .driver = {
+ .name = ACPI_PCC_DRIVER_NAME,
+ .acpi_match_table = pcc_device_ids,
+ .pm = &acpi_pcc_hotkey_pm,
+ },
};
static const struct key_entry panasonic_keymap[] = {
@@ -964,7 +963,7 @@ static int acpi_pcc_init_input(struct pcc_acpi *pcc)
#ifdef CONFIG_PM_SLEEP
static int acpi_pcc_hotkey_resume(struct device *dev)
{
- struct pcc_acpi *pcc = acpi_driver_data(to_acpi_device(dev));
+ struct pcc_acpi *pcc = acpi_driver_data(ACPI_COMPANION(dev));
if (pcc->num_sifr > SINF_MUTE)
acpi_pcc_write_sset(pcc, SINF_MUTE, pcc->mute);
@@ -980,8 +979,9 @@ static int acpi_pcc_hotkey_resume(struct device *dev)
}
#endif
-static int acpi_pcc_hotkey_add(struct acpi_device *device)
+static int acpi_pcc_hotkey_probe(struct platform_device *pdev)
{
+ struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
struct backlight_properties props;
struct pcc_acpi *pcc;
int num_sifr, result;
@@ -1107,6 +1107,7 @@ static int acpi_pcc_hotkey_add(struct acpi_device *device)
out_input:
input_unregister_device(pcc->input_dev);
out_sinf:
+ device->driver_data = NULL;
kfree(pcc->sinf);
out_hotkey:
kfree(pcc);
@@ -1114,8 +1115,9 @@ static int acpi_pcc_hotkey_add(struct acpi_device *device)
return result;
}
-static void acpi_pcc_hotkey_remove(struct acpi_device *device)
+static void acpi_pcc_hotkey_remove(struct platform_device *pdev)
{
+ struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
struct pcc_acpi *pcc = acpi_driver_data(device);
i8042_remove_filter(panasonic_i8042_filter);
@@ -1135,8 +1137,10 @@ static void acpi_pcc_hotkey_remove(struct acpi_device *device)
input_unregister_device(pcc->input_dev);
+ device->driver_data = NULL;
+
kfree(pcc->sinf);
kfree(pcc);
}
-module_acpi_driver(acpi_pcc_driver);
+module_platform_driver(acpi_pcc_driver);
--
2.51.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v4 0/5] platform/x86: panasonic-laptop: Bind to a platform device instead of an ACPI one
2026-03-20 10:29 [PATCH v4 0/5] platform/x86: panasonic-laptop: Bind to a platform device instead of an ACPI one Rafael J. Wysocki
` (4 preceding siblings ...)
2026-03-20 10:35 ` [PATCH v4 5/5] platform/x86: panasonic-laptop: Convert ACPI driver to a platform one Rafael J. Wysocki
@ 2026-03-23 10:46 ` Ilpo Järvinen
5 siblings, 0 replies; 7+ messages in thread
From: Ilpo Järvinen @ 2026-03-23 10:46 UTC (permalink / raw)
To: Rafael J. Wysocki
Cc: LKML, Linux ACPI, Hans de Goede, platform-driver-x86,
Kenneth Chan
On Fri, 20 Mar 2026 11:29:16 +0100, Rafael J. Wysocki wrote:
> This is an update of
>
> https://lore.kernel.org/linux-acpi/12863246.O9o76ZdvQC@rafael.j.wysocki/
>
> addressing a driver_data pointer leak in the last patch. The other patches
> in the series remain unchanged.
>
> [...]
Thank you for your contribution, it has been applied to my local
review-ilpo-next branch. Note it will show up in the public
platform-drivers-x86/review-ilpo-next branch only once I've pushed my
local branch there, which might take a while.
The list of commits applied:
[1/5] platform/x86: panasonic-laptop: Make pcc_register_optd_notifier() void
commit: e2b0cd5c265f01977ed4e7f04bd989cdb0b9eaed
[2/5] platform/x86: panasonic-laptop: Fix OPTD notifier registration and cleanup
commit: 8baeff2c1d33dad8572216c6ad3a7425852507d4
[3/5] platform/x86: panasonic-laptop: Remove redundant checks from 3 functions
commit: a347e11252c60bfce1bf15f2f86484cdb9bf6468
[4/5] platform/x86: panasonic-laptop: Register ACPI notify handler directly
commit: 0381b6a65716dae778fb4b5ee4ee42aca62402e9
[5/5] platform/x86: panasonic-laptop: Convert ACPI driver to a platform one
commit: de6837243af00dc22b5117f45a35ec20adbf62c5
--
i.
^ permalink raw reply [flat|nested] 7+ messages in thread