Message ID | 20180605071337.22915-2-joel@jms.id.au |
---|---|
State | Accepted |
Headers | show |
Series | Misc fixes | expand |
On 06/05/2018 12:43 PM, Joel Stanley wrote: > 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@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++; > } > Thanks for the fix. Reviewed-by: Shilpasri G Bhat <shilpa.bhat@linux.vnet.ibm.com>
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++; }
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@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(-)