mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>,
	linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	Linus Walleij <linus.walleij@linaro.org>
Subject: Re: [PATCH v1 1/1] gpio: Use traditional pattern when checking error codes
Date: Thu, 31 Oct 2024 11:15:16 +0200	[thread overview]
Message-ID: <ZyNKpC_3E3GFsyXL@smile.fi.intel.com> (raw)
In-Reply-To: <CAMRc=Mc_PW32jNO+C5AEQK6ej_CsCSV-HY76aJoQ6bjZ=JPOtg@mail.gmail.com>

On Wed, Oct 30, 2024 at 09:20:45PM +0100, Bartosz Golaszewski wrote:
> On Mon, Oct 28, 2024 at 2:44 PM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> >
> > Instead of 'if (ret == 0)' switch to "check for the error first" rule.
> 
> Well there's much more to this patch than that and I have some issues with it.
> 
> > While it gives a "+" (plus) statistics it makes the code easier to read
> 
> Not only does it increase the footprint but it also adds completely
> unnecessary goto labels.

These pieces can be dropped.

...

> > and maintain (when, e.g., want to add somethning in between touched lines).
> 
> The single line calls to the notifier chain are unlikely to be
> extended anytime soon but even then I think we should cross that
> bridge when we get there.

Okay.

...

> > -       if (!ret)
> > -               gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_CONFIG);
> > +       if (ret)
> > +               return ret;
> >
> > -       return ret;
> > +       gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_CONFIG);
> > +       return 0;
> >  }
> 
> I really don't see how this makes it better. The logic here is: if the
> underlying set config worked fine - emit the event. Otherwise continue
> with the function (even if there's nothing there now). If anything
> you're making it more difficult to modify later because logically the
> notification is just an optional step on the way to returning from the
> function.

Optional steps are covered by flags, and not by checking the previous call for
failure. So, I barely see the "optionality" of the notifications in these calls.

...

> >         ret = gpiod_direction_input_nonotify(desc);
> > -       if (ret == 0)
> > -               gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_CONFIG);
> > +       if (ret)
> > +               return ret;
> 
> Ok, for consistency I could take it but please put this into a
> separate commit doing just that (here and elsewhere).

Based on the other comments from you in this email I'm not sure I understood
this correctly. Do you want to reject the complete patch, or do you agree on
some pieces out of it.

> > -       return ret;
> > +       gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_CONFIG);
> > +       return 0;

...

> >         ret = gpio_do_set_config(desc, config);
> > -       if (!ret) {
> > -               /* These are the only options we notify the userspace about. */
> > -               switch (pinconf_to_config_param(config)) {
> > -               case PIN_CONFIG_BIAS_DISABLE:
> > -               case PIN_CONFIG_BIAS_PULL_DOWN:
> > -               case PIN_CONFIG_BIAS_PULL_UP:
> > -               case PIN_CONFIG_DRIVE_OPEN_DRAIN:
> > -               case PIN_CONFIG_DRIVE_OPEN_SOURCE:
> > -               case PIN_CONFIG_DRIVE_PUSH_PULL:
> > -               case PIN_CONFIG_INPUT_DEBOUNCE:
> > -                       gpiod_line_state_notify(desc,
> > -                                               GPIO_V2_LINE_CHANGED_CONFIG);
> > -                       break;
> > -               default:
> > -                       break;
> > -               }
> 
> If you really want to get rid of one level of indentation here,
> I suggest moving it into a separate function.

Perhaps you suggested a separate change for that?

> > +       if (ret)
> > +               return ret;
> > +
> > +       /* These are the only options we notify the userspace about */
> > +       switch (pinconf_to_config_param(config)) {
> > +       case PIN_CONFIG_BIAS_DISABLE:
> > +       case PIN_CONFIG_BIAS_PULL_DOWN:
> > +       case PIN_CONFIG_BIAS_PULL_UP:
> > +       case PIN_CONFIG_DRIVE_OPEN_DRAIN:
> > +       case PIN_CONFIG_DRIVE_OPEN_SOURCE:
> > +       case PIN_CONFIG_DRIVE_PUSH_PULL:
> > +       case PIN_CONFIG_INPUT_DEBOUNCE:
> > +               gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_CONFIG);
> > +               break;
> > +       default:
> > +               break;
> >         }
> >
> > -       return ret;
> > +       return 0;

...

> Most of this is IMO pointless churn. You typically do a lot of great
> cleanups but this just doesn't make sense. Sorry but NAK.

OK, I do one change out of that with deduplication of the direction input call,
the rest is up to you, let's it be less readable.

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2024-10-31  9:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-28 13:43 Andy Shevchenko
2024-10-28 22:10 ` Linus Walleij
2024-10-30 20:20 ` Bartosz Golaszewski
2024-10-31  9:15   ` Andy Shevchenko [this message]
2024-10-31 18:23     ` 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=ZyNKpC_3E3GFsyXL@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=bartosz.golaszewski@linaro.org \
    --cc=brgl@bgdev.pl \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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

all inboxes | Powered by JetHome®