2015-06-08 11:10:40

by David Binderman

[permalink] [raw]
Subject: linux-4.1-rc7/drivers/irqchip/irq-renesas-intc-irqpin.c:418: array index used before limits check ?

Hello there,

[linux-4.1-rc7/drivers/irqchip/irq-renesas-intc-irqpin.c:418]: (style) Array ind
ex 'k' is used before limits check.

?? if (!io[k] && k < INTC_IRQPIN_REG_NR_MANDATORY) {

Suggest sanity check array index before use.

Regards

David Binderman

-


2015-06-08 13:10:53

by Thomas Gleixner

[permalink] [raw]
Subject: Re: linux-4.1-rc7/drivers/irqchip/irq-renesas-intc-irqpin.c:418: array index used before limits check ?

On Mon, 8 Jun 2015, David Binderman wrote:

> Hello there,
>
> [linux-4.1-rc7/drivers/irqchip/irq-renesas-intc-irqpin.c:418]: (style) Array ind
> ex 'k' is used before limits check.
>
> ?? if (!io[k] && k < INTC_IRQPIN_REG_NR_MANDATORY) {
>
> Suggest sanity check array index before use.

Which version of gcc is being stupid here?

Thanks,

tglx

2015-06-08 13:16:30

by David Binderman

[permalink] [raw]
Subject: RE: linux-4.1-rc7/drivers/irqchip/irq-renesas-intc-irqpin.c:418: array index used before limits check ?

Hello there Thomas,

----------------------------------------
>> [linux-4.1-rc7/drivers/irqchip/irq-renesas-intc-irqpin.c:418]: (style) Array ind
>> ex 'k' is used before limits check.
>>
>> if (!io[k] && k < INTC_IRQPIN_REG_NR_MANDATORY) {
>>
>> Suggest sanity check array index before use.
>
> Which version of gcc is being stupid here?

None of them.

The original "(style)" message is from a static analysis tool called cppcheck.

I can't think of a situation where, if an array index needs checking, then
it should be checked *after* use.


Regards

David Binderman


-

2015-06-08 13:26:18

by Thomas Gleixner

[permalink] [raw]
Subject: RE: linux-4.1-rc7/drivers/irqchip/irq-renesas-intc-irqpin.c:418: array index used before limits check ?

On Mon, 8 Jun 2015, David Binderman wrote:
> ----------------------------------------
> >> [linux-4.1-rc7/drivers/irqchip/irq-renesas-intc-irqpin.c:418]: (style) Array ind
> >> ex 'k' is used before limits check.
> >>
> >> if (!io[k] && k < INTC_IRQPIN_REG_NR_MANDATORY) {
> >>
> >> Suggest sanity check array index before use.
> >
> > Which version of gcc is being stupid here?
>
> None of them.
>
> The original "(style)" message is from a static analysis tool called cppcheck.
>
> I can't think of a situation where, if an array index needs checking, then
> it should be checked *after* use.

It does not check the array index. Read the complete code:

for (k = 0; k < INTC_IRQPIN_REG_NR; k++) {
io[k] = platform_get_resource(pdev, IORESOURCE_MEM, k);
if (!io[k] && k < INTC_IRQPIN_REG_NR_MANDATORY) {

The array bound is INTC_IRQPIN_REG_NR and the check about which that
tool complains has nothing to do with array bounds. Completely valid
code.

Thanks,

tglx



2015-06-08 16:40:48

by David Binderman

[permalink] [raw]
Subject: RE: linux-4.1-rc7/drivers/irqchip/irq-renesas-intc-irqpin.c:418: array index used before limits check ?

Hello there Thomas,

----------------------------------------
>> I can't think of a situation where, if an array index needs checking, then
>> it should be checked *after* use.
>
> It does not check the array index. Read the complete code:
>
> for (k = 0; k < INTC_IRQPIN_REG_NR; k++) {
> io[k] = platform_get_resource(pdev, IORESOURCE_MEM, k);
> if (!io[k] && k < INTC_IRQPIN_REG_NR_MANDATORY) {
>
> The array bound is INTC_IRQPIN_REG_NR and the check about which that
> tool complains has nothing to do with array bounds. Completely valid
> code.

After a deeper look at the code, agreed. False positive by the tool.

I also checked the rest of the /irqchip/ directory for other messages by
the tool and couldn't see anything else suspicious.

Regards

David Binderman

-