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

Willy Tarreau
2008-08-22T19:45:05Z

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@const.mimas.ru> 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