[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <36d2316c-5482-4c27-b887-8d8a7543494f@roeck-us.net>
Date: Sun, 3 Dec 2023 07:00:24 -0800
From: Guenter Roeck <linux@...ck-us.net>
To: Haoran Liu <liuhaoran14@....com>, jdelvare@...e.com
Cc: linux-hwmon@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] [hwmon] pcf8591: Add error handling for
i2c_smbus_write_byte
On 12/3/23 01:25, Haoran Liu wrote:
> This patch adds error handling to the out0_enable_store function in
> drivers/hwmon/pcf8591.c for the i2c_smbus_write_byte call. This issue was
> identified through static analysis, which indicated that the function
> previously did not handle potential failures of i2c_smbus_write_byte.
> The lack of error handling could lead to silent failures and unpredictable
> behavior in the PCF8591 driver.
>
> Although the error addressed by this patch may not occur in the current
> environment, I still suggest implementing these error handling routines
> if the function is not highly time-sensitive. As the environment evolves
> or the code gets reused in different contexts, there's a possibility that
> these errors might occur. In case you find this addition unnecessary, I
> completely understand and respect your perspective. My intention was to
> enhance the robustness of the code, but I acknowledge that practical
> considerations and current functionality might not warrant this change
> at this point.
>
I don't mind the patch, but the above does not belong into its description.
Guenter
> Signed-off-by: Haoran Liu <liuhaoran14@....com>
> ---
> drivers/hwmon/pcf8591.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/hwmon/pcf8591.c b/drivers/hwmon/pcf8591.c
> index 66c76b28c9e0..2a12b024214c 100644
> --- a/drivers/hwmon/pcf8591.c
> +++ b/drivers/hwmon/pcf8591.c
> @@ -147,8 +147,12 @@ static ssize_t out0_enable_store(struct device *dev,
> data->control |= PCF8591_CONTROL_AOEF;
> else
> data->control &= ~PCF8591_CONTROL_AOEF;
> - i2c_smbus_write_byte(client, data->control);
> + err = i2c_smbus_write_byte(client, data->control);
> mutex_unlock(&data->update_lock);
> +
> + if (err)
> + return err;
> +
> return count;
> }
>
Powered by blists - more mailing lists