diff mbox series

[ACPI] fan_core: Add error handling in fan_set_state_acpi4

Message ID 20231129071514.31486-1-liuhaoran14@163.com
State New
Headers show
Series [ACPI] fan_core: Add error handling in fan_set_state_acpi4 | expand

Commit Message

Haoran Liu Nov. 29, 2023, 7:15 a.m. UTC
This patch introduces error handling for the acpi_driver_data
call within the fan_set_state_acpi4 function in
drivers/acpi/fan_core.c. Previously, the function did not account
for potential null returns from acpi_driver_data, which could
lead to instability if encountered.

Signed-off-by: Haoran Liu <liuhaoran14@163.com>
---
 drivers/acpi/fan_core.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Rafael J. Wysocki Dec. 6, 2023, 8:06 p.m. UTC | #1
On Wed, Nov 29, 2023 at 8:15 AM Haoran Liu <liuhaoran14@163.com> wrote:
>
> This patch introduces error handling for the acpi_driver_data
> call within the fan_set_state_acpi4 function in
> drivers/acpi/fan_core.c. Previously, the function did not account
> for potential null returns from acpi_driver_data, which could
> lead to instability if encountered.

This needs to explain why/how it is possible for acpi_driver_data() to
return NULL in fan_set_state_acpi4().

> Signed-off-by: Haoran Liu <liuhaoran14@163.com>
> ---
>  drivers/acpi/fan_core.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/drivers/acpi/fan_core.c b/drivers/acpi/fan_core.c
> index 9dccbae9e8ea..f2553a47a705 100644
> --- a/drivers/acpi/fan_core.c
> +++ b/drivers/acpi/fan_core.c
> @@ -154,6 +154,12 @@ static int fan_set_state_acpi4(struct acpi_device *device, unsigned long state)
>         u64 value = state;
>         int max_state;
>
> +       if (!fan) {
> +               pr_err("%s: No ACPI fan data "
> +                       "associated with the device\n", __func__);
> +               return -ENODEV;
> +       }
> +
>         if (fan->fif.fine_grain_ctrl)
>                 max_state = 100 / fan->fif.step_size;
>         else
> --
> 2.17.1
>
diff mbox series

Patch

diff --git a/drivers/acpi/fan_core.c b/drivers/acpi/fan_core.c
index 9dccbae9e8ea..f2553a47a705 100644
--- a/drivers/acpi/fan_core.c
+++ b/drivers/acpi/fan_core.c
@@ -154,6 +154,12 @@  static int fan_set_state_acpi4(struct acpi_device *device, unsigned long state)
 	u64 value = state;
 	int max_state;
 
+	if (!fan) {
+		pr_err("%s: No ACPI fan data "
+			"associated with the device\n", __func__);
+		return -ENODEV;
+	}
+
 	if (fan->fif.fine_grain_ctrl)
 		max_state = 100 / fan->fif.step_size;
 	else