]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ACPI: driver: Check ACPI_COMPANION() against NULL during probe
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 8 May 2026 18:04:33 +0000 (20:04 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 11 May 2026 16:50:06 +0000 (18:50 +0200)
Since every platform driver can be forced to match a device that doesn't
match its list of device IDs because of device_match_driver_override(),
platform drivers that rely on the existence of a device's ACPI companion
object should verify its presence.

Accordingly, add requisite ACPI_COMPANION() or ACPI_HANDLE() checks
against NULL to 13 platform drivers handling core ACPI devices.

Also change the value returned by the ACPI thermal zone driver when
the device's ACPI companion is not present to -ENODEV for consistency
with the other drivers.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Hans de Goede <johannes.goede@oss.qualcomm.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://patch.msgid.link/4516068.ejJDZkT8p0@rafael.j.wysocki
Cc: 7.0+ <stable@vger.kernel.org> # 7.0+
14 files changed:
drivers/acpi/ac.c
drivers/acpi/acpi_pad.c
drivers/acpi/acpi_tad.c
drivers/acpi/battery.c
drivers/acpi/button.c
drivers/acpi/ec.c
drivers/acpi/hed.c
drivers/acpi/nfit/core.c
drivers/acpi/pfr_telemetry.c
drivers/acpi/pfr_update.c
drivers/acpi/sbs.c
drivers/acpi/sbshc.c
drivers/acpi/thermal.c
drivers/acpi/tiny-power-button.c

index e9e970fd8f33e682d4c9e57d3a2a5cc4c12b6d1b..27f31744f29e23e6e921cd5b68d69d2f77b7b8a4 100644 (file)
@@ -192,11 +192,15 @@ static const struct dmi_system_id ac_dmi_table[]  __initconst = {
 
 static int acpi_ac_probe(struct platform_device *pdev)
 {
-       struct acpi_device *adev = ACPI_COMPANION(&pdev->dev);
        struct power_supply_config psy_cfg = {};
+       struct acpi_device *adev;
        struct acpi_ac *ac;
        int result;
 
+       adev = ACPI_COMPANION(&pdev->dev);
+       if (!adev)
+               return -ENODEV;
+
        ac = kzalloc_obj(struct acpi_ac);
        if (!ac)
                return -ENOMEM;
index 0a8e02bc8c8b6a7eed537ade1af73e6eaeab2c78..ec94b09bb747167a724a7a5718a71990773ffe58 100644 (file)
@@ -423,7 +423,11 @@ static void acpi_pad_notify(acpi_handle handle, u32 event, void *data)
 
 static int acpi_pad_probe(struct platform_device *pdev)
 {
-       struct acpi_device *adev = ACPI_COMPANION(&pdev->dev);
+       struct acpi_device *adev;
+
+       adev = ACPI_COMPANION(&pdev->dev);
+       if (!adev)
+               return -ENODEV;
 
        return acpi_dev_install_notify_handler(adev, ACPI_DEVICE_NOTIFY,
                                               acpi_pad_notify, adev);
index cac07e997028a3c0f4ea281f29d7280552b0ba75..386fc1abcbdcb577128f2ca97eb3021bcd52416f 100644 (file)
@@ -815,12 +815,16 @@ static void acpi_tad_remove(void *data)
 static int acpi_tad_probe(struct platform_device *pdev)
 {
        struct device *dev = &pdev->dev;
-       acpi_handle handle = ACPI_HANDLE(dev);
        struct acpi_tad_driver_data *dd;
+       acpi_handle handle;
        acpi_status status;
        unsigned long long caps;
        int ret;
 
+       handle = ACPI_HANDLE(dev);
+       if (!handle)
+               return -ENODEV;
+
        /*
         * Initialization failure messages are mostly about firmware issues, so
         * print them at the "info" level.
index b4c25474f42f4d2cd516b8dafe3c5a5e2793c454..d4ae21a7100796304d8e865f154382845c6bb9ed 100644 (file)
@@ -1214,10 +1214,14 @@ static void sysfs_battery_cleanup(struct acpi_battery *battery)
 
 static int acpi_battery_probe(struct platform_device *pdev)
 {
-       struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
        struct acpi_battery *battery;
+       struct acpi_device *device;
        int result;
 
+       device = ACPI_COMPANION(&pdev->dev);
+       if (!device)
+               return -ENODEV;
+
        if (device->dep_unmet)
                return -EPROBE_DEFER;
 
index dc064a388c23ea9123038bb25515bd3c2a77e0c7..b47301ee4c8a829a3be39de07ef97810d4929165 100644 (file)
@@ -531,15 +531,20 @@ static int acpi_lid_input_open(struct input_dev *input)
 
 static int acpi_button_probe(struct platform_device *pdev)
 {
-       struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
        acpi_notify_handler handler;
+       struct acpi_device *device;
        struct acpi_button *button;
        struct input_dev *input;
-       const char *hid = acpi_device_hid(device);
        acpi_status status;
        char *name, *class;
+       const char *hid;
        int error = 0;
 
+       device = ACPI_COMPANION(&pdev->dev);
+       if (!device)
+               return -ENODEV;
+
+       hid = acpi_device_hid(device);
        if (!strcmp(hid, ACPI_BUTTON_HID_LID) &&
             lid_init_state == ACPI_BUTTON_LID_INIT_DISABLED)
                return -ENODEV;
index 45204538ed874e6bebfb055edef134e3eb5fe20a..64ad4cfa6208bd3d1f8f606004ed120170a0638d 100644 (file)
@@ -1676,10 +1676,14 @@ static int acpi_ec_setup(struct acpi_ec *ec, struct acpi_device *device, bool ca
 
 static int acpi_ec_probe(struct platform_device *pdev)
 {
-       struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
+       struct acpi_device *device;
        struct acpi_ec *ec;
        int ret;
 
+       device = ACPI_COMPANION(&pdev->dev);
+       if (!device)
+               return -ENODEV;
+
        if (boot_ec && (boot_ec->handle == device->handle ||
            !strcmp(acpi_device_hid(device), ACPI_ECDT_HID))) {
                /* Fast path: this device corresponds to the boot EC. */
index 4d5e12ed6f3c256e05fac120d9e209c1f9566418..060e8d670f5d37e8a583d2712d7afe27b81a9b07 100644 (file)
@@ -50,9 +50,13 @@ static void acpi_hed_notify(acpi_handle handle, u32 event, void *data)
 
 static int acpi_hed_probe(struct platform_device *pdev)
 {
-       struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
+       struct acpi_device *device;
        int err;
 
+       device = ACPI_COMPANION(&pdev->dev);
+       if (!device)
+               return -ENODEV;
+
        /* Only one hardware error device */
        if (hed_handle)
                return -EINVAL;
index d13264fb9e026b8e2216d6cd16dedf0a663db3da..9304ac996d41adc8f6b3cff2f29a642842fd451e 100644 (file)
@@ -3341,12 +3341,16 @@ static int acpi_nfit_probe(struct platform_device *pdev)
        struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER, NULL };
        struct acpi_nfit_desc *acpi_desc;
        struct device *dev = &pdev->dev;
-       struct acpi_device *adev = ACPI_COMPANION(dev);
        struct acpi_table_header *tbl;
+       struct acpi_device *adev;
        acpi_status status = AE_OK;
        acpi_size sz;
        int rc = 0;
 
+       adev = ACPI_COMPANION(&pdev->dev);
+       if (!adev)
+               return -ENODEV;
+
        rc = acpi_dev_install_notify_handler(adev, ACPI_DEVICE_NOTIFY,
                                             acpi_nfit_notify, dev);
        if (rc)
index 32bdf8cbe8f237b6ba0989e929b39cf53091f9a1..2387376832a1b61dc0c270b98a13770dc5258125 100644 (file)
@@ -360,10 +360,14 @@ static void pfrt_log_put_idx(void *data)
 
 static int acpi_pfrt_log_probe(struct platform_device *pdev)
 {
-       acpi_handle handle = ACPI_HANDLE(&pdev->dev);
        struct pfrt_log_device *pfrt_log_dev;
+       acpi_handle handle;
        int ret;
 
+       handle = ACPI_HANDLE(&pdev->dev);
+       if (!handle)
+               return -ENODEV;
+
        if (!acpi_has_method(handle, "_DSM")) {
                dev_dbg(&pdev->dev, "Missing _DSM\n");
                return -ENODEV;
index 11b1c282800525fd113e08a98c7da6f8dc351638..6283105bb0e8b2ae76cf733a28f665eec6d83e52 100644 (file)
@@ -538,10 +538,14 @@ static void pfru_put_idx(void *data)
 
 static int acpi_pfru_probe(struct platform_device *pdev)
 {
-       acpi_handle handle = ACPI_HANDLE(&pdev->dev);
        struct pfru_device *pfru_dev;
+       acpi_handle handle;
        int ret;
 
+       handle = ACPI_HANDLE(&pdev->dev);
+       if (!handle)
+               return -ENODEV;
+
        if (!acpi_has_method(handle, "_DSM")) {
                dev_dbg(&pdev->dev, "Missing _DSM\n");
                return -ENODEV;
index 440f1d69aca86cf30b5d7a751d9841fb740edbdd..86b7c797585263e3310179eb1bbc48e1bf88aca0 100644 (file)
@@ -629,11 +629,15 @@ static void acpi_sbs_callback(void *context)
 
 static int acpi_sbs_probe(struct platform_device *pdev)
 {
-       struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
+       struct acpi_device *device;
        struct acpi_sbs *sbs;
        int result = 0;
        int id;
 
+       device = ACPI_COMPANION(&pdev->dev);
+       if (!device)
+               return -ENODEV;
+
        sbs = kzalloc_obj(struct acpi_sbs);
        if (!sbs) {
                result = -ENOMEM;
index f413270415b687e00add06cef1cb627a63f89bb3..c0ffa267f96cd51a68b7f1e8fdfba1ec993085d4 100644 (file)
@@ -237,11 +237,15 @@ static int smbus_alarm(void *context)
 
 static int acpi_smbus_hc_probe(struct platform_device *pdev)
 {
-       struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
+       struct acpi_device *device;
        int status;
        unsigned long long val;
        struct acpi_smb_hc *hc;
 
+       device = ACPI_COMPANION(&pdev->dev);
+       if (!device)
+               return -ENODEV;
+
        status = acpi_evaluate_integer(device->handle, "_EC", NULL, &val);
        if (ACPI_FAILURE(status)) {
                pr_err("error obtaining _EC.\n");
index b8b487d89d25b128cf422e896d99dccae2bb8c5d..dfc7daa809b50f16239c38b8a57bcadb507a58ff 100644 (file)
@@ -789,7 +789,7 @@ static int acpi_thermal_probe(struct platform_device *pdev)
        int i;
 
        if (!device)
-               return -EINVAL;
+               return -ENODEV;
 
        tz = kzalloc_obj(struct acpi_thermal);
        if (!tz)
index 531e65b01bcbe1f22cb31fef20d4b59f0f37e695..92516ef84b021650397d2f0185ddfca81670ca31 100644 (file)
@@ -38,9 +38,13 @@ static u32 acpi_tiny_power_button_event(void *not_used)
 
 static int acpi_tiny_power_button_probe(struct platform_device *pdev)
 {
-       struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
+       struct acpi_device *device;
        acpi_status status;
 
+       device = ACPI_COMPANION(&pdev->dev);
+       if (!device)
+               return -ENODEV;
+
        if (device->device_type == ACPI_BUS_TYPE_POWER_BUTTON) {
                status = acpi_install_fixed_event_handler(ACPI_EVENT_POWER_BUTTON,
                                                          acpi_tiny_power_button_event,