[Skiboot] [PATCH 2/2] sensors: occ: Fix a bug when sensor values are zero

Gautham R. Shenoy ego at linux.vnet.ibm.com
Fri Apr 24 16:41:15 AEST 2020


From: "Gautham R. Shenoy" <ego at linux.vnet.ibm.com>

The commit 1b9a449d ("opal-api: add endian conversions to most opal
calls") modified the code in opal_read_sensor() to make it
Little-Endian safe. In the process, it changed the code so that if a
sensor value was zero, it would simply return OPAL_SUCCESS without
updating the return buffer. As a result, the return buffer contained
bogus values which were reflected on those sensors being read by the
Kernel.

This patch fixes it by ensuring that the return buffer is updated with
the value read from the sensor every time.

Thanks to Vaidyanathan Srinivasan <svaidy at linux.vnet.ibm.com> for
spotting the missing return-buffer update.

Fixes: commit 1b9a449d ("opal-api: add endian conversions to most opal
calls")
Reported-by: Pavaman Subramaniyam <pavsubra at in.ibm.com>
Tested-by: Pavaman Subramaniyam <pavsubra at in.ibm.com>
Signed-off-by: Gautham R. Shenoy <ego at linux.vnet.ibm.com>
---
 hw/occ-sensor.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/occ-sensor.c b/hw/occ-sensor.c
index a5d0974..76d63f3 100644
--- a/hw/occ-sensor.c
+++ b/hw/occ-sensor.c
@@ -276,7 +276,7 @@ int occ_sensor_read(u32 handle, __be64 *data)
 
 	d = read_sensor(buff, attr);
 	if (!d)
-		return OPAL_SUCCESS;
+		goto out_success;
 
 	md = get_names_block(hb);
 	if (be16_to_cpu(md[id].type) == OCC_SENSOR_TYPE_POWER && attr == SENSOR_ACCUMULATOR)
@@ -284,6 +284,7 @@ int occ_sensor_read(u32 handle, __be64 *data)
 	else
 		scale_sensor(&md[id], &d);
 
+out_success:
 	*data = cpu_to_be64(d);
 
 	return OPAL_SUCCESS;
-- 
1.9.4



More information about the Skiboot mailing list