diff mbox series

[v2,2/2] sensors: occ: Fix a bug when sensor values are zero

Message ID 1587999401-3719-3-git-send-email-ego@linux.vnet.ibm.com
State New
Headers show
Series sensors: occ: Couple of fixes | expand

Commit Message

Gautham R. Shenoy April 27, 2020, 2:56 p.m. UTC
From: "Gautham R. Shenoy" <ego@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

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@linux.vnet.ibm.com> for
spotting the missing return-buffer update.

cc: skiboot-stable@lists.ozlabs.org
Fixes: commit 1b9a449d ("opal-api: add endian conversions to most opal
Reported-by: Pavaman Subramaniyam <pavsubra@in.ibm.com>
Tested-by: Pavaman Subramaniyam <pavsubra@in.ibm.com>
Reviewed-by: Vaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com>
Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
 hw/occ-sensor.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff mbox series


diff --git a/hw/occ-sensor.c b/hw/occ-sensor.c
index d97cc33..8605c40 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)
 		scale_sensor(&md[id], &d);
 	*data = cpu_to_be64(d);
 	return OPAL_SUCCESS;