Skip to content

Commit a5355e9

Browse files
committed
Merge tag 'acpi-6.18-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
Pull ACPI fixes from Rafael Wysocki: "These fix three ACPI driver issues and add version checks to two ACPI table parsers: - Call input_free_device() on failing input device registration as necessary (and mentioned in the input subsystem documentation) in the ACPI button driver (Kaushlendra Kumar) - Fix use-after-free in acpi_video_switch_brightness() by canceling a delayed work during tear-down (Yuhao Jiang) - Use platform device for devres-related actions in the ACPI fan driver to allow device-managed resources to be cleaned up properly (Armin Wolf) - Add version checks to the MRRM and SPCR table parsers (Tony Luck and Punit Agrawal)" * tag 'acpi-6.18-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: ACPI: SPCR: Check for table version when using precise baudrate ACPI: MRRM: Check revision of MRRM table ACPI: fan: Use platform device for devres-related actions ACPI: fan: Use ACPI handle when retrieving _FST ACPI: video: Fix use-after-free in acpi_video_switch_brightness() ACPI: button: Call input_free_device() on failing input device registration
2 parents a5dbbb3 + 8907226 commit a5355e9

File tree

8 files changed

+43
-26
lines changed

8 files changed

+43
-26
lines changed

drivers/acpi/acpi_mrrm.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ static __init int acpi_parse_mrrm(struct acpi_table_header *table)
6363
if (!mrrm)
6464
return -ENODEV;
6565

66+
if (mrrm->header.revision != 1)
67+
return -EINVAL;
68+
6669
if (mrrm->flags & ACPI_MRRM_FLAGS_REGION_ASSIGNMENT_OS)
6770
return -EOPNOTSUPP;
6871

drivers/acpi/acpi_video.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1959,8 +1959,10 @@ static void acpi_video_bus_remove_notify_handler(struct acpi_video_bus *video)
19591959
struct acpi_video_device *dev;
19601960

19611961
mutex_lock(&video->device_list_lock);
1962-
list_for_each_entry(dev, &video->video_device_list, entry)
1962+
list_for_each_entry(dev, &video->video_device_list, entry) {
19631963
acpi_video_dev_remove_notify_handler(dev);
1964+
cancel_delayed_work_sync(&dev->switch_brightness_work);
1965+
}
19641966
mutex_unlock(&video->device_list_lock);
19651967

19661968
acpi_video_bus_stop_devices(video);

drivers/acpi/button.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,8 +619,10 @@ static int acpi_button_add(struct acpi_device *device)
619619

620620
input_set_drvdata(input, device);
621621
error = input_register_device(input);
622-
if (error)
622+
if (error) {
623+
input_free_device(input);
623624
goto err_remove_fs;
625+
}
624626

625627
switch (device->device_type) {
626628
case ACPI_BUS_TYPE_POWER_BUTTON:

drivers/acpi/fan.h

Lines changed: 4 additions & 3 deletions
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,14 +60,14 @@ 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

6667
#if IS_REACHABLE(CONFIG_HWMON)
67-
int devm_acpi_fan_create_hwmon(struct acpi_device *device);
68+
int devm_acpi_fan_create_hwmon(struct device *dev);
6869
#else
69-
static inline int devm_acpi_fan_create_hwmon(struct acpi_device *device) { return 0; };
70+
static inline int devm_acpi_fan_create_hwmon(struct device *dev) { return 0; };
7071
#endif
7172

7273
#endif

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: 23 additions & 13 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

@@ -337,7 +347,7 @@ static int acpi_fan_probe(struct platform_device *pdev)
337347
}
338348

339349
if (fan->has_fst) {
340-
result = devm_acpi_fan_create_hwmon(device);
350+
result = devm_acpi_fan_create_hwmon(&pdev->dev);
341351
if (result)
342352
return result;
343353

drivers/acpi/fan_hwmon.c

Lines changed: 5 additions & 6 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

@@ -167,12 +166,12 @@ static const struct hwmon_chip_info acpi_fan_hwmon_chip_info = {
167166
.info = acpi_fan_hwmon_info,
168167
};
169168

170-
int devm_acpi_fan_create_hwmon(struct acpi_device *device)
169+
int devm_acpi_fan_create_hwmon(struct device *dev)
171170
{
172-
struct acpi_fan *fan = acpi_driver_data(device);
171+
struct acpi_fan *fan = dev_get_drvdata(dev);
173172
struct device *hdev;
174173

175-
hdev = devm_hwmon_device_register_with_info(&device->dev, "acpi_fan", fan,
176-
&acpi_fan_hwmon_chip_info, NULL);
174+
hdev = devm_hwmon_device_register_with_info(dev, "acpi_fan", fan, &acpi_fan_hwmon_chip_info,
175+
NULL);
177176
return PTR_ERR_OR_ZERO(hdev);
178177
}

drivers/acpi/spcr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ int __init acpi_parse_spcr(bool enable_earlycon, bool enable_console)
155155
* Baud Rate field. If this field is zero or not present, Configured
156156
* Baud Rate is used.
157157
*/
158-
if (table->precise_baudrate)
158+
if (table->header.revision >= 4 && table->precise_baudrate)
159159
baud_rate = table->precise_baudrate;
160160
else switch (table->baud_rate) {
161161
case 0:

0 commit comments

Comments
 (0)