From: Andy Shevchenko <andy@kernel.org>
To: "Marek Behún" <kabel@kernel.org>
Cc: Gregory CLEMENT <gregory.clement@bootlin.com>,
Arnd Bergmann <arnd@arndb.de>,
soc@kernel.org, arm@kernel.org,
Linus Walleij <linus.walleij@linaro.org>,
Bartosz Golaszewski <brgl@bgdev.pl>,
linux-gpio@vger.kernel.org
Subject: Re: [PATCH v2 3/7] platform: cznic: turris-omnia-mcu: Add support for MCU connected GPIOs
Date: Fri, 22 Sep 2023 17:14:10 +0300 [thread overview]
Message-ID: <ZQ2hMkRENs97zOr+@smile.fi.intel.com> (raw)
In-Reply-To: <20230921204243.19c48136@thinkpad>
On Thu, Sep 21, 2023 at 08:42:43PM +0200, Marek Behún wrote:
> On Tue, 19 Sep 2023 16:00:39 +0300
> Andy Shevchenko <andy@kernel.org> wrote:
...
> > > + mutex_lock(&mcu->lock);
> > > +
> > > + if (ctl_mask)
> > > + err = omnia_ctl_cmd_unlocked(mcu, CMD_GENERAL_CONTROL, ctl,
> > > + ctl_mask);
> >
> > > + if (!err && ext_ctl_mask)
> > > + err = omnia_ctl_cmd_unlocked(mcu, CMD_EXT_CONTROL, ext_ctl,
> > > + ext_ctl_mask);
> >
> > Can it be
> >
> > if (err)
> > goto out_unlock;
> >
> > if (_mask)
> > ...
> >
> > ?
>
> Hi Andy,
>
> so I am refactoring this to use guard(mutex), but now I have this:
>
> guard(mutex, &mcu->lock);
>
> if (ctl_mask) {
> err = ...;
> if (err)
> goto out_err;
> }
>
> if (ext_ctl_mask) {
> err = ...;
> if (err)
> goto out_err;
> }
>
> return;
> out_err:
> dev_err(dev, "Cannot set GPIOs: %d\n", err);
>
> which clearly is not any better... or at least the original
...which rather means that the design of above is not so good, i.e.
why do you need the same message in the different situations?
> if (!err && ext_ctl_mask)
> is better IMO.
I disagree.
> Compare with:
>
> guard(mutex, &mcu->lock);
>
> if (ctl_mask)
> err = ...;
>
> if (!err && ext_ctl_mask)
> err = ...;
>
> if (err)
> dev_err(dev, "Cannot set GPIOs: %d\n", err);
>
>
> Do you have a better suggestion?
Use different messages (if even needed) for different situations.
With cleanup.h in place you shouldn't supposed to have goto:s
(in simple cases like yours).
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2023-09-22 14:14 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-19 10:38 [PATCH v2 0/7] Turris Omnia MCU driver Marek Behún
2023-09-19 10:38 ` [PATCH v2 1/7] dt-bindings: arm: add cznic,turris-omnia-mcu binding Marek Behún
2023-09-20 12:37 ` Krzysztof Kozlowski
2023-09-19 10:38 ` [PATCH v2 2/7] platform: cznic: Add preliminary support for Turris Omnia MCU Marek Behún
2023-09-19 12:29 ` Andy Shevchenko
2023-09-19 15:16 ` Marek Behún
2023-09-19 18:27 ` Andy Shevchenko
2023-09-20 14:19 ` Marek Behún
2023-09-20 14:47 ` Andy Shevchenko
2023-09-19 10:38 ` [PATCH v2 3/7] platform: cznic: turris-omnia-mcu: Add support for MCU connected GPIOs Marek Behún
2023-09-19 13:00 ` Andy Shevchenko
2023-09-20 17:08 ` Marek Behún
2023-09-21 9:55 ` Andy Shevchenko
2023-09-21 20:25 ` Marek Behún
2023-09-22 14:18 ` Andy Shevchenko
2023-09-25 10:03 ` Marek Behún
2023-09-25 10:29 ` Andy Shevchenko
2023-09-21 18:42 ` Marek Behún
2023-09-22 14:14 ` Andy Shevchenko [this message]
2023-09-20 11:58 ` Linus Walleij
2023-09-20 13:36 ` Andy Shevchenko
2023-09-21 19:45 ` Marek Behún
2023-09-21 20:14 ` Marek Behún
2023-09-22 14:21 ` Andy Shevchenko
2023-09-19 10:38 ` [PATCH v2 4/7] platform: cznic: turris-omnia-mcu: Add support for poweroff and wakeup Marek Behún
2023-09-19 10:38 ` [PATCH v2 5/7] platform: cznic: turris-omnia-mcu: Add support for MCU watchdog Marek Behún
2023-09-19 13:50 ` Guenter Roeck
2023-09-22 11:46 ` Marek Behún
2023-09-19 10:38 ` [PATCH v2 6/7] ARM: dts: turris-omnia: Add MCU system-controller node Marek Behún
2023-09-19 10:38 ` [PATCH v2 7/7] ARM: dts: turris-omnia: Add GPIO key node for front button Marek Behún
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=ZQ2hMkRENs97zOr+@smile.fi.intel.com \
--to=andy@kernel.org \
--cc=arm@kernel.org \
--cc=arnd@arndb.de \
--cc=brgl@bgdev.pl \
--cc=gregory.clement@bootlin.com \
--cc=kabel@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=soc@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