From: Guenter Roeck <linux@roeck-us.net>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: MyungJoo Ham <myungjoo.ham@samsung.com>,
Chanwoo Choi <cw00.choi@samsung.com>,
Sebastian Reichel <sre@kernel.org>, Chen-Yu Tsai <wens@csie.org>,
Hans de Goede <hdegoede@redhat.com>,
Felipe Balbi <balbi@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Heikki Krogerus <heikki.krogerus@linux.intel.com>,
linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
linux-usb@vger.kernel.org, linux-omap@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] extcon: fix extcon_get_extcon_dev() error handling
Date: Thu, 18 Nov 2021 10:16:43 -0800 [thread overview]
Message-ID: <20211118181643.GB3320814@roeck-us.net> (raw)
In-Reply-To: <20211118145135.GO27562@kadam>
On Thu, Nov 18, 2021 at 05:51:35PM +0300, Dan Carpenter wrote:
> On Thu, Nov 18, 2021 at 06:22:58AM -0800, Guenter Roeck wrote:
> > On 11/18/21 3:32 AM, Dan Carpenter wrote:
> > > The extcon_get_extcon_dev() function returns error pointers on error
> > > and NULL when it's a -EPROBE_DEFER defer situation. There are eight
> > > callers and only two of them handled this correctly. In the other
> > > callers an error pointer return would lead to a crash.
> > >
> > > What prevents crashes is that errors can only happen in the case of
> > > a bug in the caller or if CONFIG_EXTCON is disabled. Six out of
> > > eight callers use the Kconfig to either depend on or select
> > > CONFIG_EXTCON. Thus the real life impact of these bugs is tiny.
> > >
> > > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > > ---
> > > The two callers where the drivers can be built without CONFIG_EXTCON
> > > are TYPEC_FUSB302 and CHARGER_MAX8997.
> > >
> > [ ... ]
> > > diff --git a/drivers/usb/typec/tcpm/fusb302.c b/drivers/usb/typec/tcpm/fusb302.c
> > > index 7a2a17866a82..8594b59bd527 100644
> > > --- a/drivers/usb/typec/tcpm/fusb302.c
> > > +++ b/drivers/usb/typec/tcpm/fusb302.c
> > > @@ -1706,8 +1706,8 @@ static int fusb302_probe(struct i2c_client *client,
> > > */
> > > if (device_property_read_string(dev, "linux,extcon-name", &name) == 0) {
> > > chip->extcon = extcon_get_extcon_dev(name);
> > > - if (!chip->extcon)
> > > - return -EPROBE_DEFER;
> > > + if (IS_ERR(chip->extcon))
> > > + return PTR_ERR(chip->extcon);
> >
> > Why does the code not need to return -EPROBE_DEFER ? The description states
> > that NULL is returned in that situation. Doesn't that mean that defer situations
> > are no longer handled with this patch in place ?
>
> I'm not sure I understand what you are saying here. In the original
> code, extcon_get_extcon_dev() would return NULL and relied on the
> callers to change NULL into a -EPROBE_DEFER. If extcon_get_extcon_dev()
> returned ERR_PTR(-EINVAL) (which is impossible as mentioned) the it
> would lead to a crash.
>
> In the new code, the extcon_get_extcon_dev() function returns
> -EPROBE_DEFER directly so the caller code is much simpler.
>
Misunderstanding on my side. I didn't get that extcon_get_extcon_dev()
now returns -EPROBE_DEFER.
> >
> > Also, with this patch in place, the code will no longer work if extcon is disabled,
> > because extcon_get_extcon_dev() will return -ENODEV and the above code will bail out.
> > The behavior of the code wasn't optimal in that case (it would wait until timeout
> > in tcpm_get_current_limit() before returning), but at least it didn't fail.
>
> Huh. You are right. Initialy I thought that tcpm_get_current_limit()
> would crash. This is one of the two drivers which I mentioned that can
> be built without CONFIG_EXTCON.
>
> I will modify the version of extcon_get_extcon_dev() where CONFIG_EXTCON
> is disabled to return NULL. That is the standard/correct way to write
> these. That will turn tcpm_get_current_limit() into a no-op.
>
> A belt and suspenders approach might be to modify the Kconfig so this
> driver selects CONFIG_EXTCON.
>
That would pull in unnecessary extra code, though, if the driver is supposed
to be able to work without it.
Thanks,
Guenter
> regards,
> dan carpenter
>
prev parent reply other threads:[~2021-11-18 18:16 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-18 11:32 [PATCH] extcon: fix extcon_get_extcon_dev() error handling Dan Carpenter
2021-11-18 12:22 ` Sebastian Reichel
2021-11-18 12:23 ` Hans de Goede
2021-11-18 13:13 ` Heikki Krogerus
2021-11-18 14:22 ` Guenter Roeck
2021-11-18 14:51 ` Dan Carpenter
2021-11-18 18:16 ` Guenter Roeck [this message]
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=20211118181643.GB3320814@roeck-us.net \
--to=linux@roeck-us.net \
--cc=balbi@kernel.org \
--cc=cw00.choi@samsung.com \
--cc=dan.carpenter@oracle.com \
--cc=gregkh@linuxfoundation.org \
--cc=hdegoede@redhat.com \
--cc=heikki.krogerus@linux.intel.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=myungjoo.ham@samsung.com \
--cc=sre@kernel.org \
--cc=wens@csie.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