From abbdf22e0a8f23207cedf9065512620971794ff5 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Fri, 6 Feb 2026 22:28:12 +0100 Subject: [PATCH 1/7] ACPI: battery: Drop redundant check from acpi_battery_notify() The battery pointer check against NULL in acpi_battery_notify() is redundant because the value of that pointer is the one passed to acpi_dev_install_notify_handler() in acpi_battery_probe() as the last argument which is not NULL. Drop the redundant check. No intentional functional impact. Closes: https://lore.kernel.org/linux-acpi/aYXvS1h3Bxf_5sCj@stanley.mountain/ Signed-off-by: Rafael J. Wysocki Link: https://patch.msgid.link/5981321.DvuYhMxLoT@rafael.j.wysocki --- drivers/acpi/battery.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index 3bbddd6f622c..a094763113bc 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -1066,9 +1066,6 @@ static void acpi_battery_notify(acpi_handle handle, u32 event, void *data) struct acpi_device *device = battery->device; struct power_supply *old; - if (!battery) - return; - guard(mutex)(&battery->update_lock); old = battery->bat; From e91f8c5305b92b63c8bac315f95c535d5c1e8fec Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Sun, 8 Feb 2026 15:13:26 +0100 Subject: [PATCH 2/7] ACPI: button: Call device_init_wakeup() earlier during probe Calling device_init_wakeup() after installing a notify handler in which wakeup events are signaled may cause a wakeup event to be missed if the device is probed right before a system suspend. To avoid this, move the device_init_wakeup() call in acpi_button_probe() before the notify handler installation and add a corresponding cleanup to the error path. Also carry out wakeup cleanup for the button in acpi_button_remove() because after that point the notify handler will not run for it and wakeup events coming from it will not be signaled. Fixes: 0d51157dfaac ("ACPI: button: Eliminate the driver notify callback") Signed-off-by: Rafael J. Wysocki Link: https://patch.msgid.link/12854922.O9o76ZdvQC@rafael.j.wysocki --- drivers/acpi/button.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c index b899b8745fed..38bc64d6bdaf 100644 --- a/drivers/acpi/button.c +++ b/drivers/acpi/button.c @@ -625,6 +625,8 @@ static int acpi_button_probe(struct platform_device *pdev) goto err_remove_fs; } + device_init_wakeup(&pdev->dev, true); + switch (device->device_type) { case ACPI_BUS_TYPE_POWER_BUTTON: status = acpi_install_fixed_event_handler(ACPI_EVENT_POWER_BUTTON, @@ -655,11 +657,11 @@ static int acpi_button_probe(struct platform_device *pdev) lid_device = device; } - device_init_wakeup(&pdev->dev, true); pr_info("%s [%s]\n", name, acpi_device_bid(device)); return 0; err_input_unregister: + device_init_wakeup(&pdev->dev, false); input_unregister_device(input); err_remove_fs: acpi_button_remove_fs(button); @@ -691,6 +693,8 @@ static void acpi_button_remove(struct platform_device *pdev) } acpi_os_wait_events_complete(); + device_init_wakeup(&pdev->dev, false); + acpi_button_remove_fs(button); input_unregister_device(button->input); kfree(button); From b83afb7e8c3388dc82b5ea5b15d328d569a6fc41 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Thu, 12 Feb 2026 14:26:54 +0100 Subject: [PATCH 3/7] ACPI: battery: Drop redundant checks from acpi_battery_remove() In acpi_battery_remove(), "battery" cannot be NULL because it is the driver data of the platform device passed to that function and it has been set by acpi_battery_probe(), so drop the redundant check of it against NULL. Moreover, getting the ACPI device pointer from battery->device is slightly less overhead than using the ACPI_COMPANION() macro on the platform device to retrieve it, so do that and drop the check of that pointer against NULL which is also redundant. No intentional functional impact. Signed-off-by: Rafael J. Wysocki Link: https://patch.msgid.link/12836976.O9o76ZdvQC@rafael.j.wysocki --- drivers/acpi/battery.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index a094763113bc..8fbad8bc4650 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -1271,13 +1271,9 @@ static int acpi_battery_probe(struct platform_device *pdev) static void acpi_battery_remove(struct platform_device *pdev) { - struct acpi_device *device = ACPI_COMPANION(&pdev->dev); struct acpi_battery *battery = platform_get_drvdata(pdev); - if (!device || !battery) - return; - - acpi_dev_remove_notify_handler(device, ACPI_ALL_NOTIFY, + acpi_dev_remove_notify_handler(battery->device, ACPI_ALL_NOTIFY, acpi_battery_notify); device_init_wakeup(&pdev->dev, false); From d323436b13f34b1df8261eb68989abda47e1785b Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Thu, 12 Feb 2026 14:31:33 +0100 Subject: [PATCH 4/7] ACPI: button: Tweak system wakeup handling Modify struct acpi_button to hold a struct device pointer instead of a struct platform_device one to avoid unnecessary pointer dereferences and use that pointer consistently for system wakeup initialization, handling and cleanup. No intentional functional impact. Signed-off-by: Rafael J. Wysocki Link: https://patch.msgid.link/1948258.tdWV9SEqCh@rafael.j.wysocki --- drivers/acpi/button.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c index 38bc64d6bdaf..17d56f01e40a 100644 --- a/drivers/acpi/button.c +++ b/drivers/acpi/button.c @@ -170,7 +170,7 @@ static struct platform_driver acpi_button_driver = { struct acpi_button { struct acpi_device *adev; - struct platform_device *pdev; + struct device *dev; /* physical button device */ unsigned int type; struct input_dev *input; char phys[32]; /* for input device */ @@ -398,7 +398,7 @@ static int acpi_lid_update_state(struct acpi_button *button, return state; if (state && signal_wakeup) - acpi_pm_wakeup_event(&button->pdev->dev); + acpi_pm_wakeup_event(button->dev); return acpi_lid_notify_state(button, state); } @@ -455,7 +455,7 @@ static void acpi_button_notify(acpi_handle handle, u32 event, void *data) return; } - acpi_pm_wakeup_event(&button->pdev->dev); + acpi_pm_wakeup_event(button->dev); if (button->suspended || event == ACPI_BUTTON_NOTIFY_WAKE) return; @@ -550,7 +550,7 @@ static int acpi_button_probe(struct platform_device *pdev) platform_set_drvdata(pdev, button); - button->pdev = pdev; + button->dev = &pdev->dev; button->adev = device; button->input = input = input_allocate_device(); if (!input) { @@ -625,7 +625,7 @@ static int acpi_button_probe(struct platform_device *pdev) goto err_remove_fs; } - device_init_wakeup(&pdev->dev, true); + device_init_wakeup(button->dev, true); switch (device->device_type) { case ACPI_BUS_TYPE_POWER_BUTTON: @@ -661,7 +661,7 @@ static int acpi_button_probe(struct platform_device *pdev) return 0; err_input_unregister: - device_init_wakeup(&pdev->dev, false); + device_init_wakeup(button->dev, false); input_unregister_device(input); err_remove_fs: acpi_button_remove_fs(button); @@ -693,7 +693,7 @@ static void acpi_button_remove(struct platform_device *pdev) } acpi_os_wait_events_complete(); - device_init_wakeup(&pdev->dev, false); + device_init_wakeup(button->dev, false); acpi_button_remove_fs(button); input_unregister_device(button->input); From 1abdf9e7967f154b3d4bfe0681dd38b8e036ee63 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Thu, 12 Feb 2026 14:33:00 +0100 Subject: [PATCH 5/7] ACPI: button: Tweak acpi_button_remove() Modify acpi_button_remove() to get the ACPI device object pointer from button->adev instead of retrieving it with the help of the ACPI_COMPANION() macro to reduce overhead slightly. While at it, rename the struct acpi_device pointer variable in acpi_button_remove() to adev. No intentional functional impact. Signed-off-by: Rafael J. Wysocki Link: https://patch.msgid.link/13948466.uLZWGnKmhe@rafael.j.wysocki --- drivers/acpi/button.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c index 17d56f01e40a..7a06194d078b 100644 --- a/drivers/acpi/button.c +++ b/drivers/acpi/button.c @@ -672,10 +672,10 @@ static int acpi_button_probe(struct platform_device *pdev) static void acpi_button_remove(struct platform_device *pdev) { - struct acpi_device *device = ACPI_COMPANION(&pdev->dev); struct acpi_button *button = platform_get_drvdata(pdev); + struct acpi_device *adev = button->adev; - switch (device->device_type) { + switch (adev->device_type) { case ACPI_BUS_TYPE_POWER_BUTTON: acpi_remove_fixed_event_handler(ACPI_EVENT_POWER_BUTTON, acpi_button_event); @@ -685,7 +685,7 @@ static void acpi_button_remove(struct platform_device *pdev) acpi_button_event); break; default: - acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY, + acpi_remove_notify_handler(adev->handle, ACPI_DEVICE_NOTIFY, button->type == ACPI_BUTTON_TYPE_LID ? acpi_lid_notify : acpi_button_notify); From 2995e713d8a76249bde325b464183430e21266aa Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Fri, 13 Feb 2026 19:25:43 +0100 Subject: [PATCH 6/7] ACPI: video: Clear driver_data pointer on remove After commit 02c057ddefef ("ACPI: video: Convert the driver to a platform one") the driver_data pointer in the ACPI companion device object is not cleared automatically on driver remove any more, so clear it directly in acpi_video_bus_remove(). Fixes: 02c057ddefef ("ACPI: video: Convert the driver to a platform one") Signed-off-by: Rafael J. Wysocki Link: https://patch.msgid.link/12840288.O9o76ZdvQC@rafael.j.wysocki --- drivers/acpi/acpi_video.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/acpi/acpi_video.c b/drivers/acpi/acpi_video.c index 69469757b965..3d6e7306f29a 100644 --- a/drivers/acpi/acpi_video.c +++ b/drivers/acpi/acpi_video.c @@ -2116,6 +2116,7 @@ static void acpi_video_bus_remove(struct platform_device *pdev) kfree(video->attached_array); kfree(video); + device->driver_data = NULL; } static int __init is_i740(struct pci_dev *dev) From 85d0bd1d4cccd8e91e11de2d5dddf9691d780468 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Fri, 13 Feb 2026 19:26:48 +0100 Subject: [PATCH 7/7] ACPI: driver: Drop driver_data pointer clearing from two drivers It is not necessary to clear the driver_data pointer in the ACPI companion device object on driver remove in the EC and SMBUS HC ACPI drivers because that pointer is not used there any more after recent changes. Drop the unnecessary statements. Signed-off-by: Rafael J. Wysocki Link: https://patch.msgid.link/6242843.lOV4Wx5bFT@rafael.j.wysocki --- drivers/acpi/ec.c | 2 -- drivers/acpi/sbshc.c | 2 -- 2 files changed, 4 deletions(-) diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index 197970339edc..f7edc664e064 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -1754,12 +1754,10 @@ static int acpi_ec_probe(struct platform_device *pdev) static void acpi_ec_remove(struct platform_device *pdev) { - struct acpi_device *device = ACPI_COMPANION(&pdev->dev); struct acpi_ec *ec = platform_get_drvdata(pdev); release_region(ec->data_addr, 1); release_region(ec->command_addr, 1); - device->driver_data = NULL; if (ec != boot_ec) { ec_remove_handlers(ec); acpi_ec_free(ec); diff --git a/drivers/acpi/sbshc.c b/drivers/acpi/sbshc.c index 7fc8ae7396d3..cb60d1d52e3e 100644 --- a/drivers/acpi/sbshc.c +++ b/drivers/acpi/sbshc.c @@ -275,13 +275,11 @@ static int acpi_smbus_hc_probe(struct platform_device *pdev) static void acpi_smbus_hc_remove(struct platform_device *pdev) { - struct acpi_device *device = ACPI_COMPANION(&pdev->dev); struct acpi_smb_hc *hc = platform_get_drvdata(pdev); acpi_ec_remove_query_handler(hc->ec, hc->query_bit); acpi_os_wait_events_complete(); kfree(hc); - device->driver_data = NULL; } module_platform_driver(acpi_smb_hc_driver);