Re: [PATCH v1 1/1] gpiolib: Deduplicate cleanup for-loop in gpiochip_add_data_with_key()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Feb 22, 2024 at 02:30:03PM +0100, Bartosz Golaszewski wrote:
> On Thu, Feb 22, 2024 at 2:28 PM Andy Shevchenko
> <andriy.shevchenko@xxxxxxxxxxxxxxx> wrote:
> > On Thu, Feb 22, 2024 at 10:48:00AM +0100, Bartosz Golaszewski wrote:
> > > On Wed, Feb 21, 2024 at 8:36 PM Andy Shevchenko
> > > <andriy.shevchenko@xxxxxxxxxxxxxxx> wrote:

...

> > > > +       while (desc_index--)
> > >
> > > What about gdev->descs[0]?
> >
> > What about it? :-)
> >
> > for (i = i - 1; i >= 0; i--)
> > while (--i >= 0)
> > while (i--)
> >
> > are all equivalents.
> >
> > The difference is what the value will i get _after_ the loop.
> 
> Ugh of course. But the first one is more readable given I got tricked
> by variant #3 at a quick glance but the for loop says out loud what it
> does.

I disagree. `while (i--)` is very well known cleanup pattern.
Less letters to parse, easier to understand.

-- 
With Best Regards,
Andy Shevchenko






[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux