linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert@linux-m68k.org>
To: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Linus Walleij <linus.walleij@linaro.org>,
	Andy Shevchenko <andy@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Mitchell Levy <levymitchell0@gmail.com>
Subject: guard coding style (was: Re: [PATCH v1 05/10] gpio: pca953x: Simplify code with cleanup helpers)
Date: Thu, 14 Sep 2023 09:47:07 +0200	[thread overview]
Message-ID: <CAMuHMdVYDSPGP48OXxi-s4GFegfzUu900ASBnRmMo=18UzmCrQ@mail.gmail.com> (raw)
In-Reply-To: <CAMRc=Merdmv_gFm58y1iHWmYmT=t_OmXyQgOXCxqwr7wsmjjYQ@mail.gmail.com>

Hi Bartosz,

On Wed, Sep 13, 2023 at 5:27 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> On Wed, Sep 13, 2023 at 4:35 PM Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> > On Fri, 1 Sep 2023, Andy Shevchenko wrote:
> > > Use macros defined in linux/cleanup.h to automate resource lifetime
> > > control in gpio-pca953x.
> > >
> > > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> >
> > Thanks for your patch, which is now commit 8e471b784a720f6f
> > ("gpio: pca953x: Simplify code with cleanup helpers") in
> > gpio/gpio/for-next.
> >
> > > --- a/drivers/gpio/gpio-pca953x.c
> > > +++ b/drivers/gpio/gpio-pca953x.c
> > > @@ -557,9 +554,8 @@ static int pca953x_gpio_get_value(struct gpio_chip *gc, unsigned off)
> > >       u32 reg_val;
> > >       int ret;
> > >
> > > -     mutex_lock(&chip->i2c_lock);
> > > -     ret = regmap_read(chip->regmap, inreg, &reg_val);
> > > -     mutex_unlock(&chip->i2c_lock);
> > > +     scoped_guard(mutex, &chip->i2c_lock)
> > > +             ret = regmap_read(chip->regmap, inreg, &reg_val);
> >
> > I can't say I'm thrilled about the lack of curly braces.  I was also
> > surprised to discover that checkpatch nor gcc W=1 complain about the
> > indentation change.
> > I know we don't use curly braces in single-statement for_each_*() loops,
> > but at least these have the familiar "for"-prefix.  And having the scope
> > is very important here, so using braces, this would stand out more.
> >
> > Hence can we please get curly braces, like
> >
> >      scoped_guard(mutex, &chip->i2c_lock) {
> >             ret = regmap_read(chip->regmap, inreg, &reg_val);
> >      }
> >
> > ?
> >
> > Thanks! ;-)
>
> I strongly disagree. The scope here is very clear - just like it is in
> a for loop, in a while loop or in an if block:
>
> if (foo)
>     bar()
>
> if (foo) {
>     bar();
>     baz();
> }
>
> Only compound statements need curly braces in the kernel and it has
> been like this forever. I don't really see a need to make it an
> exception.
>
> That being said - I don't think the coding style for guard has ever
> been addressed yet, so maybe bring it up with Peter Zijlstra?

That's a good idea!

I see Peter always used curly braces (but he didn't have any
single-statement blocks, except for one with an "if", and we do tend
to use curly braces in "for"-statements containing a single "if", too),
but he does put a space after the "scoped_guard", as is also
shown in the template in include/linux/cleanup.h:

    scoped_guard (name, args...) { }:

Then, "guard" does not get a space (but it is funny syntax
anyway, with the double set of parentheses ;-).  The template in
include/linux/cleanup.h doesn't match actual usage as it lacks the
second set of parentheses:

    guard(name):

Peter: care to comment?
Or do you have a different bikeshed to paint today? ;-)

Thanks!

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

  reply	other threads:[~2023-09-14  7:47 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-01 13:40 [PATCH v1 01/10] gpio: pca953x: Drop unused fields in struct pca953x_platform_data Andy Shevchenko
2023-09-01 13:40 ` [PATCH v1 02/10] gpio: pca953x: Fully convert to device managed resources Andy Shevchenko
2023-09-01 13:40 ` [PATCH v1 03/10] gpio: pca953x: Utilise dev_err_probe() where it makes sense Andy Shevchenko
2023-09-01 13:40 ` [PATCH v1 04/10] gpio: pca953x: Split pca953x_restore_context() and pca953x_save_context() Andy Shevchenko
2023-09-01 13:40 ` [PATCH v1 05/10] gpio: pca953x: Simplify code with cleanup helpers Andy Shevchenko
2023-09-13 14:35   ` Geert Uytterhoeven
2023-09-13 15:27     ` Bartosz Golaszewski
2023-09-14  7:47       ` Geert Uytterhoeven [this message]
2023-09-14 20:51         ` guard coding style (was: Re: [PATCH v1 05/10] gpio: pca953x: Simplify code with cleanup helpers) Mitchell Levy
2023-09-14 22:26           ` Peter Zijlstra
2023-09-14 22:41             ` Peter Zijlstra
2023-09-14 22:17         ` Peter Zijlstra
2023-09-14 22:30         ` Peter Zijlstra
2023-09-01 13:40 ` [PATCH v1 06/10] gpio: pca953x: Utilise temporary variable for struct device Andy Shevchenko
2023-09-01 13:40 ` [PATCH v1 07/10] gpio: pca953x: Utilise temporary variable for struct gpio_chip Andy Shevchenko
2023-09-01 13:40 ` [PATCH v1 08/10] gpio: pca953x: Switch to DEFINE_SIMPLE_DEV_PM_OPS() Andy Shevchenko
2023-09-01 13:40 ` [PATCH v1 09/10] gpio: pca953x: Get rid of useless goto label Andy Shevchenko
2023-09-04  7:41   ` Bartosz Golaszewski
2023-09-04  8:38     ` Andy Shevchenko
2023-09-01 13:40 ` [PATCH v1 10/10] gpio: pca953x: Revisit header inclusions Andy Shevchenko
2023-09-04  7:43 ` [PATCH v1 01/10] gpio: pca953x: Drop unused fields in struct pca953x_platform_data Bartosz Golaszewski
2023-09-06 16:26   ` Andy Shevchenko
2023-09-11  7:01 ` Bartosz Golaszewski
2023-09-12  7:50 ` Linus Walleij
2023-09-12  9:31   ` Andy Shevchenko
2023-09-12  9:48     ` Bartosz Golaszewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMuHMdVYDSPGP48OXxi-s4GFegfzUu900ASBnRmMo=18UzmCrQ@mail.gmail.com' \
    --to=geert@linux-m68k.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=andy@kernel.org \
    --cc=brgl@bgdev.pl \
    --cc=levymitchell0@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).