Skip to content

Commit 5876425

Browse files
Wer-Wolfrafaeljw
authored andcommitted
ACPI: fan: Use ACPI handle when retrieving _FST
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 <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 211ddde commit 5876425

4 files changed

Lines changed: 26 additions & 16 deletions

File tree

drivers/acpi/fan.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ struct acpi_fan_fst {
4949
};
5050

5151
struct acpi_fan {
52+
acpi_handle handle;
5253
bool acpi4;
5354
bool has_fst;
5455
struct acpi_fan_fif fif;
@@ -59,7 +60,7 @@ struct acpi_fan {
5960
struct device_attribute fine_grain_control;
6061
};
6162

62-
int acpi_fan_get_fst(struct acpi_device *device, struct acpi_fan_fst *fst);
63+
int acpi_fan_get_fst(acpi_handle handle, struct acpi_fan_fst *fst);
6364
int acpi_fan_create_attributes(struct acpi_device *device);
6465
void acpi_fan_delete_attributes(struct acpi_device *device);
6566

drivers/acpi/fan_attr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static ssize_t show_fan_speed(struct device *dev, struct device_attribute *attr,
5555
struct acpi_fan_fst fst;
5656
int status;
5757

58-
status = acpi_fan_get_fst(acpi_dev, &fst);
58+
status = acpi_fan_get_fst(acpi_dev->handle, &fst);
5959
if (status)
6060
return status;
6161

drivers/acpi/fan_core.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,30 @@ static int fan_get_max_state(struct thermal_cooling_device *cdev, unsigned long
4444
return 0;
4545
}
4646

47-
int acpi_fan_get_fst(struct acpi_device *device, struct acpi_fan_fst *fst)
47+
int acpi_fan_get_fst(acpi_handle handle, struct acpi_fan_fst *fst)
4848
{
4949
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
5050
union acpi_object *obj;
5151
acpi_status status;
5252
int ret = 0;
5353

54-
status = acpi_evaluate_object(device->handle, "_FST", NULL, &buffer);
55-
if (ACPI_FAILURE(status)) {
56-
dev_err(&device->dev, "Get fan state failed\n");
57-
return -ENODEV;
58-
}
54+
status = acpi_evaluate_object(handle, "_FST", NULL, &buffer);
55+
if (ACPI_FAILURE(status))
56+
return -EIO;
5957

6058
obj = buffer.pointer;
61-
if (!obj || obj->type != ACPI_TYPE_PACKAGE ||
62-
obj->package.count != 3 ||
63-
obj->package.elements[1].type != ACPI_TYPE_INTEGER) {
64-
dev_err(&device->dev, "Invalid _FST data\n");
65-
ret = -EINVAL;
59+
if (!obj)
60+
return -ENODATA;
61+
62+
if (obj->type != ACPI_TYPE_PACKAGE || obj->package.count != 3) {
63+
ret = -EPROTO;
64+
goto err;
65+
}
66+
67+
if (obj->package.elements[0].type != ACPI_TYPE_INTEGER ||
68+
obj->package.elements[1].type != ACPI_TYPE_INTEGER ||
69+
obj->package.elements[2].type != ACPI_TYPE_INTEGER) {
70+
ret = -EPROTO;
6671
goto err;
6772
}
6873

@@ -81,7 +86,7 @@ static int fan_get_state_acpi4(struct acpi_device *device, unsigned long *state)
8186
struct acpi_fan_fst fst;
8287
int status, i;
8388

84-
status = acpi_fan_get_fst(device, &fst);
89+
status = acpi_fan_get_fst(device->handle, &fst);
8590
if (status)
8691
return status;
8792

@@ -311,11 +316,16 @@ static int acpi_fan_probe(struct platform_device *pdev)
311316
struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
312317
char *name;
313318

319+
if (!device)
320+
return -ENODEV;
321+
314322
fan = devm_kzalloc(&pdev->dev, sizeof(*fan), GFP_KERNEL);
315323
if (!fan) {
316324
dev_err(&device->dev, "No memory for fan\n");
317325
return -ENOMEM;
318326
}
327+
328+
fan->handle = device->handle;
319329
device->driver_data = fan;
320330
platform_set_drvdata(pdev, fan);
321331

drivers/acpi/fan_hwmon.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,12 @@ static umode_t acpi_fan_hwmon_is_visible(const void *drvdata, enum hwmon_sensor_
9393
static int acpi_fan_hwmon_read(struct device *dev, enum hwmon_sensor_types type, u32 attr,
9494
int channel, long *val)
9595
{
96-
struct acpi_device *adev = to_acpi_device(dev->parent);
9796
struct acpi_fan *fan = dev_get_drvdata(dev);
9897
struct acpi_fan_fps *fps;
9998
struct acpi_fan_fst fst;
10099
int ret;
101100

102-
ret = acpi_fan_get_fst(adev, &fst);
101+
ret = acpi_fan_get_fst(fan->handle, &fst);
103102
if (ret < 0)
104103
return ret;
105104

0 commit comments

Comments
 (0)