hwmon: (k10temp) Check return value of amd_smn_read()
authorYazen Ghannam <yazen.ghannam@amd.com>
Thu, 6 Jun 2024 16:12:56 +0000 (11:12 -0500)
committerBorislav Petkov (AMD) <bp@alien8.de>
Wed, 12 Jun 2024 09:33:46 +0000 (11:33 +0200)
commitc2d79cc5455c891de6c93e1e0c73d806e299c54f
treeb15979b544efbeeedca461d78934d399fe0bbb4e
parent5ac6293047cf5de6daca662347c19347e856c2a5
hwmon: (k10temp) Check return value of amd_smn_read()

Check the return value of amd_smn_read() before saving a value. This
ensures invalid values aren't saved or used.

There are three cases here with slightly different behavior:

1) read_tempreg_nb_zen():
This is a function pointer which does not include a return code.
In this case, set the register value to 0 on failure. This
enforces Read-as-Zero behavior.

2) k10temp_read_temp():
This function does have return codes, so return the error code
from the failed register read. Continued operation is not
necessary, since there is no valid data from the register.
Furthermore, if the register value was set to 0, then the
following operation would underflow.

3) k10temp_get_ccd_support():
This function reads the same register from multiple CCD
instances in a loop. And a bitmask is formed if a specific bit
is set in each register instance. The loop should continue on a
failed register read, skipping the bit check.

Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Link: https://lore.kernel.org/r/20240606-fix-smn-bad-read-v4-3-ffde21931c3f@amd.com
drivers/hwmon/k10temp.c