]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ACPI: fan: Use ACPI handle when retrieving _FST
authorArmin Wolf <W_Armin@gmx.de>
Tue, 7 Oct 2025 23:41:44 +0000 (01:41 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Nov 2025 20:33:59 +0000 (15:33 -0500)
commit 58764259ebe0c9efd569194444629f6b26f86583 upstream.

Usage of the ACPI device should be phased out in the future, as
the driver itself is now using the platform bus.

Replace any usage of struct acpi_device in acpi_fan_get_fst() to
allow users to drop usage of struct acpi_device.

Also extend the integer check to all three package elements.

Signed-off-by: Armin Wolf <W_Armin@gmx.de>
Link: https://patch.msgid.link/20251007234149.2769-2-W_Armin@gmx.de
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/acpi/fan.h
drivers/acpi/fan_attr.c
drivers/acpi/fan_core.c
drivers/acpi/fan_hwmon.c

index db25a3898af710610c1b1b187fbe33bf6169868b..72a60c87e76f2244c3f7cfff764f19ecb5bec051 100644 (file)
@@ -47,6 +47,7 @@ struct acpi_fan_fst {
 };
 
 struct acpi_fan {
+       acpi_handle handle;
        bool acpi4;
        struct acpi_fan_fif fif;
        struct acpi_fan_fps *fps;
@@ -56,7 +57,7 @@ struct acpi_fan {
        struct device_attribute fine_grain_control;
 };
 
-int acpi_fan_get_fst(struct acpi_device *device, struct acpi_fan_fst *fst);
+int acpi_fan_get_fst(acpi_handle handle, struct acpi_fan_fst *fst);
 int acpi_fan_create_attributes(struct acpi_device *device);
 void acpi_fan_delete_attributes(struct acpi_device *device);
 
index f4f6e2381f1d3af4e3071d325da81dbf9d87ee01..c5f4b819ceded5c55c714de601aca0516ec8e347 100644 (file)
@@ -55,7 +55,7 @@ static ssize_t show_fan_speed(struct device *dev, struct device_attribute *attr,
        struct acpi_fan_fst fst;
        int status;
 
-       status = acpi_fan_get_fst(acpi_dev, &fst);
+       status = acpi_fan_get_fst(acpi_dev->handle, &fst);
        if (status)
                return status;
 
index 300e5d919986481cb769f6d80bb2a47a9a333402..cee8f1c78ee7121dc2f4ef95de6f18d96729ac05 100644 (file)
@@ -44,25 +44,30 @@ static int fan_get_max_state(struct thermal_cooling_device *cdev, unsigned long
        return 0;
 }
 
-int acpi_fan_get_fst(struct acpi_device *device, struct acpi_fan_fst *fst)
+int acpi_fan_get_fst(acpi_handle handle, struct acpi_fan_fst *fst)
 {
        struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
        union acpi_object *obj;
        acpi_status status;
        int ret = 0;
 
-       status = acpi_evaluate_object(device->handle, "_FST", NULL, &buffer);
-       if (ACPI_FAILURE(status)) {
-               dev_err(&device->dev, "Get fan state failed\n");
-               return -ENODEV;
-       }
+       status = acpi_evaluate_object(handle, "_FST", NULL, &buffer);
+       if (ACPI_FAILURE(status))
+               return -EIO;
 
        obj = buffer.pointer;
-       if (!obj || obj->type != ACPI_TYPE_PACKAGE ||
-           obj->package.count != 3 ||
-           obj->package.elements[1].type != ACPI_TYPE_INTEGER) {
-               dev_err(&device->dev, "Invalid _FST data\n");
-               ret = -EINVAL;
+       if (!obj)
+               return -ENODATA;
+
+       if (obj->type != ACPI_TYPE_PACKAGE || obj->package.count != 3) {
+               ret = -EPROTO;
+               goto err;
+       }
+
+       if (obj->package.elements[0].type != ACPI_TYPE_INTEGER ||
+           obj->package.elements[1].type != ACPI_TYPE_INTEGER ||
+           obj->package.elements[2].type != ACPI_TYPE_INTEGER) {
+               ret = -EPROTO;
                goto err;
        }
 
@@ -81,7 +86,7 @@ static int fan_get_state_acpi4(struct acpi_device *device, unsigned long *state)
        struct acpi_fan_fst fst;
        int status, i;
 
-       status = acpi_fan_get_fst(device, &fst);
+       status = acpi_fan_get_fst(device->handle, &fst);
        if (status)
                return status;
 
@@ -319,11 +324,16 @@ static int acpi_fan_probe(struct platform_device *pdev)
        struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
        char *name;
 
+       if (!device)
+               return -ENODEV;
+
        fan = devm_kzalloc(&pdev->dev, sizeof(*fan), GFP_KERNEL);
        if (!fan) {
                dev_err(&device->dev, "No memory for fan\n");
                return -ENOMEM;
        }
+
+       fan->handle = device->handle;
        device->driver_data = fan;
        platform_set_drvdata(pdev, fan);
 
index bd0d31a398fa59c926f8bc948d5ccfb10fbcf6df..787bf8f40077e574718f2f45371e49e6b3271b01 100644 (file)
@@ -85,13 +85,12 @@ static umode_t acpi_fan_hwmon_is_visible(const void *drvdata, enum hwmon_sensor_
 static int acpi_fan_hwmon_read(struct device *dev, enum hwmon_sensor_types type, u32 attr,
                               int channel, long *val)
 {
-       struct acpi_device *adev = to_acpi_device(dev->parent);
        struct acpi_fan *fan = dev_get_drvdata(dev);
        struct acpi_fan_fps *fps;
        struct acpi_fan_fst fst;
        int ret;
 
-       ret = acpi_fan_get_fst(adev, &fst);
+       ret = acpi_fan_get_fst(fan->handle, &fst);
        if (ret < 0)
                return ret;