diff mbox series

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

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

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success Successfully applied on branch master (0f1937ef40fca0c3212a9dff1010b832a24fb063)
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot success Test snowpatch/job/snowpatch-skiboot on branch master
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot-dco success Signed-off-by present

Commit Message

Gautham R Shenoy April 24, 2020, 6:41 a.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
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@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@in.ibm.com>
Tested-by: Pavaman Subramaniyam <pavsubra@in.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(-)

Comments

Vaidyanathan Srinivasan April 24, 2020, 9:29 a.m. UTC | #1
* Gautham R Shenoy <ego@linux.vnet.ibm.com> [2020-04-24 12:11:15]:

> 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
> 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@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@in.ibm.com>
> Tested-by: Pavaman Subramaniyam <pavsubra@in.ibm.com>
> Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>

Reviewed-by: Vaidyanathan Srinivasan <svaidy@linux.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;

Perfect and working fix for a subtle bug :)

Thanks,
Vaidy
diff mbox series

Patch

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;