linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Andi Shyti <andi.shyti@kernel.org>
To: "Russell King (Oracle)" <linux@armlinux.org.uk>
Cc: "Alexandre Belloni" <alexandre.belloni@bootlin.com>,
	s.hauer@pengutronix.de, "Fabio Estevam" <festevam@gmail.com>,
	"Linus Walleij" <linus.walleij@linaro.org>,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	leoyang.li@nxp.com, "Wolfram Sang" <wsa@kernel.org>,
	o.rempel@pengutronix.de, linux-i2c@vger.kernel.org,
	"Pengutronix Kernel Team" <kernel@pengutronix.de>,
	"Claudiu Beznea" <claudiu.beznea@tuxon.dev>,
	"Codrin Ciubotariu" <codrin.ciubotariu@microchip.com>,
	"Oleksij Rempel" <linux@rempel-privat.de>,
	"Shawn Guo" <shawnguo@kernel.org>,
	"Ruan Jinjie" <ruanjinjie@huawei.com>,
	linux-arm-kernel@lists.infradead.org,
	"NXP Linux Team" <linux-imx@nxp.com>
Subject: Re: [PATCH -next v2 RESEND] I2C: Fix return value check for devm_pinctrl_get()
Date: Sat, 19 Aug 2023 16:45:33 +0200	[thread overview]
Message-ID: <20230819144533.dc3t777ggcnfq3rh@intel.intel> (raw)
In-Reply-To: <ZN/QDI9ZHZAWa575@shell.armlinux.org.uk>

Hi Russel,

> > > > >       i2c_imx->pinctrl = devm_pinctrl_get(&pdev->dev);
> > > > > -     if (!i2c_imx->pinctrl || IS_ERR(i2c_imx->pinctrl)) {
> > > > > +     if (IS_ERR(i2c_imx->pinctrl)) {
> > > > >               dev_info(&pdev->dev, "can't get pinctrl, bus recovery not supported\n");
> > > > >               return PTR_ERR(i2c_imx->pinctrl);
> > > > >       }
> > > >
> > > > I haven't looked at the AT91 version, but... isn't the original code
> > > > entirely correct?
> > > >
> > > > If pinctrl is not available (thus devm_pinctrl_get() returns NULL) then
> > > > recovery can't work, because we can't switch the I2C pins between the
> > > > I2C controller and GPIO. So, isn't it quite correct to print
> > > > "can't get pinctrl, bus recovery not supported" because the I2C bus
> > > > can't be recovered without pinctrl?
> > > >
> > > > The PTR_ERR() is also fine - because if pinctrl is not present and
> > > > returns NULL, we'll end up returning zero, which is exactly what we
> > > > want.
> > > 
> > > Oh, you're probably absolutely right about that.
> > > 
> > > > The alternative would be to open code that, maybe with a more accurate
> > > > message:
> > > >
> > > >         if (!i2c_imx->pinctrl) {
> > > >                 dev_info(&pdev->dev, "pinctrl unavailable, bus recovery not supported\n");
> > > >                 return 0;
> > > >         }
> > > >         if (IS_ERR(i2c_imx->pinctrl) {
> > > >                 ...
> > > 
> > > This is a way better patch. It makes the implicit explicit.
> > 
> > we could also use
> > 
> > 	if (IS_ERR_OR_NULL(i2c_imx->pinctrl))
> > 		...
> > 
> > without changing any logic in the driver.
> 
> IS_ERR_OR_NULL() - is a macro I personally hate, it causes a lot of
> trouble. I have mutt setup to mark IS_ERR_OR_NULL with a red background
> so it stands out in patches. It is utterly evil, and I really wish we
> could get rid of that damn macro.
> 
> It also looks wrong.
> 
> 	if (IS_ERR_OR_NULL(x))
> 		return PTR_ERR(x);
> 
> rings alarm bells for some people, because if x is NULL, then
> PTR_ERR(x) is zero.
> 
> While this may be what is intended in this case, for a great many
> places in the kernel, this is a bug. So I can guarantee that
> _someone_ will come along and want to "fix" that to make the NULL
> case return an error code, and in doing so end up breaking the
> driver.
> 
> So... no, just don't.
> 
> This is why having two if() statements are a good idea, and is
> what Linus means by "making the implicit explicit" - because it
> then becomes absolutely obvious what we want to do in the NULL
> case, and what we want to do in the error case.
> 
> There is none of this ambiguity that I point out above.

Yes, I fully agree, IS_ERR_OR_NULL() shoud be almost never be
used in an exit path (unless you are in a void function and few
other cases, like (borderline) this one).

I'm OK also if Ruan goes with what you suggested.

Andi

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2023-08-19 14:45 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-18  7:45 [PATCH -next v2 RESEND] I2C: Fix return value check for devm_pinctrl_get() Ruan Jinjie
2023-08-18  8:20 ` Russell King (Oracle)
2023-08-18 16:42   ` Linus Walleij
2023-08-18 19:20     ` Andi Shyti
2023-08-18 20:09       ` Russell King (Oracle)
2023-08-19 14:45         ` Andi Shyti [this message]
2023-08-21  2:56           ` Ruan Jinjie

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=20230819144533.dc3t777ggcnfq3rh@intel.intel \
    --to=andi.shyti@kernel.org \
    --cc=alexandre.belloni@bootlin.com \
    --cc=claudiu.beznea@tuxon.dev \
    --cc=codrin.ciubotariu@microchip.com \
    --cc=festevam@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=leoyang.li@nxp.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-imx@nxp.com \
    --cc=linux@armlinux.org.uk \
    --cc=linux@rempel-privat.de \
    --cc=o.rempel@pengutronix.de \
    --cc=ruanjinjie@huawei.com \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    --cc=u.kleine-koenig@pengutronix.de \
    --cc=wsa@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;
as well as URLs for NNTP newsgroup(s).