[Skiboot] [PATCH 1/4] occ-sensor: Avoid using uninitialised struct cpu_thread
Joel Stanley
joel at jms.id.au
Tue Jun 5 17:13:34 AEST 2018
When adding the sensors in occ_sensors_init, if the type is not
OCC_SENSOR_LOC_CORE, then the loop to find 'c' will not be executed.
Then c->pir is used for both of the the add_sensor_node calls below.
This provides a default value of 0 instead.
Found using scan-build.
Signed-off-by: Joel Stanley <joel at jms.id.au>
---
It may not be the correct fix. Please review closely.
---
hw/occ-sensor.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/hw/occ-sensor.c b/hw/occ-sensor.c
index a31a2a5d6dea..783f75740c42 100644
--- a/hw/occ-sensor.c
+++ b/hw/occ-sensor.c
@@ -543,6 +543,7 @@ bool occ_sensors_init(void)
for (i = 0; i < hb->nr_sensors; i++) {
const char *type, *loc;
struct cpu_thread *c = NULL;
+ uint32_t pir = 0;
if (md[i].structure_type != OCC_SENSOR_READING_FULL)
continue;
@@ -565,6 +566,7 @@ bool occ_sensors_init(void)
break;
if (!c)
continue;
+ pir = c->pir;
}
type = get_sensor_type_string(md[i].type);
@@ -572,7 +574,7 @@ bool occ_sensors_init(void)
add_sensor_node(loc, type, i, SENSOR_SAMPLE, &md[i],
&phandles[phcount], &ptype[phcount],
- c->pir, occ_num, chip->id);
+ pir, occ_num, chip->id);
phcount++;
/* Add energy sensors */
@@ -581,7 +583,7 @@ bool occ_sensors_init(void)
add_sensor_node(loc, "energy", i,
SENSOR_ACCUMULATOR, &md[i],
&phandles[phcount], &ptype[phcount],
- c->pir, occ_num, chip->id);
+ pir, occ_num, chip->id);
phcount++;
}
--
2.17.0
More information about the Skiboot
mailing list