Re: [PATCH] [hwmon] pcf8591: Add error handling for i2c_smbus_write_byte

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxx>
---
  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;
  }





[Index of Archives]     [LM Sensors]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux