Function xive_native_get_ipi() might uses chip_id without it being
initialized. This gives the following error on 'smatch' tool:
error: uninitialized symbol 'chip_id'
This patch simply sets chip_id initial value to 0.
CC: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Breno Leitao <leitao@debian.org>
---
arch/powerpc/sysdev/xive/native.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: Michael Ellerman <mpe@ellerman.id.au> Date: 2018-08-23 03:24:06
Hi Breno,
Breno Leitao [off-list ref] writes:
Function xive_native_get_ipi() might uses chip_id without it being
initialized. This gives the following error on 'smatch' tool:
error: uninitialized symbol 'chip_id'
Which is correct, it can be used uninitialised. I'm surprised GCC
doesn't warn about it.
This patch simply sets chip_id initial value to 0.
I'd prefer we fixed it differently, by explicitly initialising to zero
at the appropriate place in the code.
@@ -239,7 +239,7 @@ static bool xive_native_match(struct device_node *node)staticintxive_native_get_ipi(unsignedintcpu,structxive_cpu*xc){structdevice_node*np;-unsignedintchip_id;+unsignedintchip_id=0;s64irq;/* Find the chip ID */
The current code is:
/* Find the chip ID */
np = of_get_cpu_node(cpu, NULL);
if (np) {
if (of_property_read_u32(np, "ibm,chip-id", &chip_id) < 0)
chip_id = 0;
}
Where if np is NULL then we don't initialise chip_id.
Which could be:
np = of_get_cpu_node(cpu, NULL);
if (of_property_read_u32(np, "ibm,chip-id", &chip_id) < 0)
chip_id = 0;
Because of_property_read_u32() will just return an error if np is NULL.
It's also missing an of_node_put() of np, you should do a separate patch
to fix that. You can just do it unconditionally after the
of_property_read_u32().
cheers
static int xive_native_get_ipi(unsigned int cpu, struct xive_cpu *xc)
{
struct device_node *np;
- unsigned int chip_id;
+ unsigned int chip_id =3D 0;
s64 irq;
=20=20
/* Find the chip ID */
=20
The current code is:
=20
/* Find the chip ID */
np =3D of_get_cpu_node(cpu, NULL);
if (np) {
if (of_property_read_u32(np, "ibm,chip-id", &chip_id) < 0)
chip_id =3D 0;
}
=20
Where if np is NULL then we don't initialise chip_id.
=20
Which could be:
=20
np =3D of_get_cpu_node(cpu, NULL);
if (of_property_read_u32(np, "ibm,chip-id", &chip_id) < 0)
chip_id =3D 0;
=20
Because of_property_read_u32() will just return an error if np is NULL.
=20
It's also missing an of_node_put() of np, you should do a separate patch
to fix that. You can just do it unconditionally after the
of_property_read_u32().
I think we can simply get rid of the OF code under xive_native_get_ipi()
and use xc->chip_id instead. It should be safe to use as xive_prepare_cpu=
()=20
should have initialized ->chip_id by the time xive_native_get_ipi() is=20
called.=20
From: Cédric Le Goater <clg@kaod.org> Date: 2018-08-23 12:34:48
On 08/23/2018 05:24 AM, Michael Ellerman wrote:
Hi Breno,
Breno Leitao [off-list ref] writes:
quoted
Function xive_native_get_ipi() might uses chip_id without it being
initialized. This gives the following error on 'smatch' tool:
error: uninitialized symbol 'chip_id'
Which is correct, it can be used uninitialised. I'm surprised GCC
doesn't warn about it.
quoted
This patch simply sets chip_id initial value to 0.
I'd prefer we fixed it differently, by explicitly initialising to zero
at the appropriate place in the code.
@@ -239,7 +239,7 @@ static bool xive_native_match(struct device_node *node)staticintxive_native_get_ipi(unsignedintcpu,structxive_cpu*xc){structdevice_node*np;-unsignedintchip_id;+unsignedintchip_id=0;s64irq;/* Find the chip ID */
The current code is:
/* Find the chip ID */
np = of_get_cpu_node(cpu, NULL);
if (np) {
if (of_property_read_u32(np, "ibm,chip-id", &chip_id) < 0)
chip_id = 0;
}
Where if np is NULL then we don't initialise chip_id.
Which could be:
np = of_get_cpu_node(cpu, NULL);
if (of_property_read_u32(np, "ibm,chip-id", &chip_id) < 0)
chip_id = 0;
Because of_property_read_u32() will just return an error if np is NULL.
It's also missing an of_node_put() of np, you should do a separate patch
to fix that. You can just do it unconditionally after the
of_property_read_u32().
I think we can simply get rid of the OF code under xive_native_get_ipi()
and use xc->chip_id instead. It should be safe to use as xive_prepare_cpu()
should have initialized ->chip_id by the time xive_native_get_ipi() is
called.
Cheers,
C.
@@ -238,20 +238,11 @@ static bool xive_native_match(struct device_node *node)#ifdef CONFIG_SMPstaticintxive_native_get_ipi(unsignedintcpu,structxive_cpu*xc){-structdevice_node*np;-unsignedintchip_id;s64irq;-/* Find the chip ID */-np=of_get_cpu_node(cpu,NULL);-if(np){-if(of_property_read_u32(np,"ibm,chip-id",&chip_id)<0)-chip_id=0;-}-/* Allocate an IPI and populate info about it */for(;;){-irq=opal_xive_allocate_irq(chip_id);+irq=opal_xive_allocate_irq(xc->chip_id);if(irq==OPAL_BUSY){msleep(1);continue;
From: Cédric Le Goater <clg@kaod.org> Date: 2018-08-24 10:37:08
On 08/24/2018 01:26 AM, Breno Leitao wrote:
From: Breno Leitao <redacted>
Function xive_native_get_ipi() might uses chip_id without it being
initialized.
This gives the following error on 'smatch' tool:
error: uninitialized symbol 'chip_id'
The suggestion is using xc->chip_id instead of consulting the OF for chip id,
which is safe since xive_prepare_cpu() should have initialized ->chip_id by
the time xive_native_get_ipi() is called.
CC: Cédric Le Goater <clg@kaod.org>
Signed-off-by: Breno Leitao <leitao@debian.org>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Thanks,
C.
@@ -238,20 +238,11 @@ static bool xive_native_match(struct device_node *node)#ifdef CONFIG_SMPstaticintxive_native_get_ipi(unsignedintcpu,structxive_cpu*xc){-structdevice_node*np;-unsignedintchip_id;s64irq;-/* Find the chip ID */-np=of_get_cpu_node(cpu,NULL);-if(np){-if(of_property_read_u32(np,"ibm,chip-id",&chip_id)<0)-chip_id=0;-}-/* Allocate an IPI and populate info about it */for(;;){-irq=opal_xive_allocate_irq(chip_id);+irq=opal_xive_allocate_irq(xc->chip_id);if(irq==OPAL_BUSY){msleep(1);continue;
From: Michael Ellerman <hidden> Date: 2018-09-20 04:21:00
On Thu, 2018-08-23 at 23:26:39 UTC, Breno Leitao wrote:
From: Breno Leitao <redacted>
Function xive_native_get_ipi() might uses chip_id without it being
initialized.
This gives the following error on 'smatch' tool:
error: uninitialized symbol 'chip_id'
The suggestion is using xc->chip_id instead of consulting the OF for chip id,
which is safe since xive_prepare_cpu() should have initialized ->chip_id by
the time xive_native_get_ipi() is called.
CC: C��dric Le Goater <clg@kaod.org>
Signed-off-by: Breno Leitao <leitao@debian.org>
Reviewed-by: C��dric Le Goater <clg@kaod.org>