diff options
author | Javier Carrasco <[email protected]> | 2024-02-07 22:17:08 +0100 |
---|---|---|
committer | Guenter Roeck <[email protected]> | 2024-02-25 12:37:38 -0800 |
commit | f16fb6d23b68699eed97fe1edee0d8eecde14a67 (patch) | |
tree | a733b626214095e8456574891fe798091a095340 | |
parent | 1b2ca93cd0592b1fcbc6f8b64e02552bc15f4bb4 (diff) |
hwmon: (chipcap2) fix uninitialized variable in cc2_get_reg_val()
The reg_val variable in cc2_get_reg_val() might be used without a known
value if cc2_read_reg() fails. That leads to a useless data conversion
because the returned error means the read operation failed and the data is
not relevant.
That makes its initial value irrelevant as well, so skip the data
conversion instead. If no error happens, a value is assigned to reg_val
and the data conversion is required.
Reported-by: Dan Carpenter <[email protected]>
Closes: https://lore.kernel.org/linux-hwmon/[email protected]/T/#t
Signed-off-by: Javier Carrasco <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Guenter Roeck <[email protected]>
-rw-r--r-- | drivers/hwmon/chipcap2.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/drivers/hwmon/chipcap2.c b/drivers/hwmon/chipcap2.c index a62c507b1042..3b604fc5d8ae 100644 --- a/drivers/hwmon/chipcap2.c +++ b/drivers/hwmon/chipcap2.c @@ -324,7 +324,9 @@ static int cc2_get_reg_val(struct cc2_data *data, u8 reg, long *val) int ret; ret = cc2_read_reg(data, reg, ®_val); - *val = cc2_rh_convert(reg_val); + if (!ret) + *val = cc2_rh_convert(reg_val); + cc2_disable(data); return ret; |