This patch introduces error handling for the acpi_driver_data call in function acpi_fan_get_fif and acpi_fan_get_fps, within drivers/acpi/fan_core.c. Previously, there was no check for a null return from acpi_driver_data, which could lead to potential instability in scenarios where acpi_driver_data fails. Signed-off-by: Haoran Liu <liuhaoran14@xxxxxxx> --- drivers/acpi/fan_core.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/acpi/fan_core.c b/drivers/acpi/fan_core.c index 9dccbae9e8ea..f3228fb9c90f 100644 --- a/drivers/acpi/fan_core.c +++ b/drivers/acpi/fan_core.c @@ -215,6 +215,13 @@ static int acpi_fan_get_fif(struct acpi_device *device) { struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; struct acpi_fan *fan = acpi_driver_data(device); + + if (!fan) { + dev_err(&device->dev, "No ACPI fan data associated " + "with the device\n"); + return -EINVAL; + } + struct acpi_buffer format = { sizeof("NNNN"), "NNNN" }; u64 fields[4]; struct acpi_buffer fif = { sizeof(fields), fields }; @@ -265,6 +272,12 @@ static int acpi_fan_speed_cmp(const void *a, const void *b) static int acpi_fan_get_fps(struct acpi_device *device) { struct acpi_fan *fan = acpi_driver_data(device); + + if (!fan) { + dev_err(&device->dev, "Failed to retrieve ACPI fan data\n"); + return -ENODEV; + } + struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; union acpi_object *obj; acpi_status status; -- 2.17.1