Re: [PATCH 2.6.27-rc3] led: driver for LEDs on PCEngines ALIX.2 and ALIX.3 boards

From: Willy Tarreau
Date: Fri Aug 22 2008 - 15:45:06 EST


Hi Andrew,

On Fri, Aug 22, 2008 at 11:51:50AM -0700, Andrew Morton wrote:
> On Tue, 19 Aug 2008 22:23:41 +0500
> Constantin Baranov <const@xxxxxxxxxxxxxx> wrote:
> > +static int __init alix_led_probe(struct platform_device *pdev)
> > +{
> > + int i;
> > + int ret = 0;
> > +
> > + for (i = 0; i < ARRAY_SIZE(alix_leds) && ret >= 0; i++)
> > + ret = led_classdev_register(&pdev->dev, &alix_leds[i].cdev);
> > +
> > + if (ret < 0) {
> > + for (i = i - 2; i >= 0; i--)
>
> this is off-by-one, surely.
>
> If we get here with i==1, we'll loop 4 billion times.

No we will not because i is signed. We'll simply not enter the loop.
However, the code looks suspicious and the reasoning behind i-2 isn't
quite clear.

Willy

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/