[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231203092518.38479-1-liuhaoran14@163.com>
Date: Sun, 3 Dec 2023 01:25:18 -0800
From: Haoran Liu <liuhaoran14@....com>
To: jdelvare@...e.com
Cc: linux@...ck-us.net, linux-hwmon@...r.kernel.org,
linux-kernel@...r.kernel.org, Haoran Liu <liuhaoran14@....com>
Subject: [PATCH] [hwmon] pcf8591: Add error handling for i2c_smbus_write_byte
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.
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;
}
--
2.17.1
Powered by blists - more mailing lists