Skip to content

Commit f16fb6d

Browse files
javiercarrascocruzgroeck
authored andcommitted
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]>
1 parent 1b2ca93 commit f16fb6d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/hwmon/chipcap2.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,9 @@ static int cc2_get_reg_val(struct cc2_data *data, u8 reg, long *val)
324324
int ret;
325325

326326
ret = cc2_read_reg(data, reg, &reg_val);
327-
*val = cc2_rh_convert(reg_val);
327+
if (!ret)
328+
*val = cc2_rh_convert(reg_val);
329+
328330
cc2_disable(data);
329331

330332
return ret;

0 commit comments

Comments
 (0)