From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Marek Vasut <marex@nabladev.com>
Cc: linux-usb@vger.kernel.org, stable@vger.kernel.org,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jens Glathe <jens.glathe@oldschoolsolutions.biz>,
Sebastian Reichel <sebastian.reichel@collabora.com>,
kernel@dh-electronics.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] usb: typec: mux: Fix typec_switch_match()
Date: Mon, 24 Aug 2026 13:44:19 +0200 [thread overview]
Message-ID: <aowuk3WwJW2Jomz8@black.igk.intel.com> (raw)
In-Reply-To: <20260817182302.146546-1-marex@nabladev.com>
On Mon, Aug 17, 2026 at 08:22:39PM +0200, Marek Vasut wrote:
> The fwnode_typec_switch_get() sporadically returns NULL instead of an
> -EPROBE_DEFER for orientation-switch described in DT. This makes it
> impossible to discern whether the DT does describe an orientation-switch
> which did not probe yet, or whether the DT does not describe the switch.
> This happens with gpio-sbu-mux connected to an I2C GPIO expander.
>
> The class_find_device() on typec_switch_match() may return NULL in case
> the mux did not probe just yet early on boot. The sw_devs[] array can be
> empty on boot as well. If these two conditions occur, then the conditional
> if (to_typec_switch_dev(dev) == sw_devs[i]) evaluates to true and the match
> function returns NULL, which propagates to fwnode_typec_switch_get() which
> makes it look as if the orientation-switch was not described in DT.
>
> This is incorrect, because the mux driver will probe a bit later on, but
> at that point, the caller of fwnode_typec_switch_get() already got the
> NULL return value. The NULL return value also does not trigger IS_ERR(),
> therefore the caller driver interprets this as if the orientation-switch
> is not described in DT, and does not return -EPROBE_DEFER to try again,
> even if it should.
>
> Fix this by checking the class_find_device() return value, and return
> -EPROBE_DEFER if it is NULL right away. If the return value is not NULL,
> perform the deduplication test, and if that test passes, consider the
> return value to be already non-NULL.
>
> Fixes: a53b4f9c51a9 ("usb: typec: mux: avoid duplicated orientation switches")
> Cc: stable@vger.kernel.org
> Signed-off-by: Marek Vasut <marex@nabladev.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> ---
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Cc: Jens Glathe <jens.glathe@oldschoolsolutions.biz>
> Cc: Sebastian Reichel <sebastian.reichel@collabora.com>
> Cc: kernel@dh-electronics.com
> Cc: linux-kernel@vger.kernel.org
> Cc: linux-usb@vger.kernel.org
> ---
> NOTE: A similar change was reverted in
> f576c75f95a5 ("Revert "usb: typec: mux: avoid duplicated mux switches"")
> Maybe the orientation switch commit also needs a revert ?
> Or the mux switch revert can be undone and fixed using this NULL check ?
> ---
> drivers/usb/typec/mux.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c
> index 9b908c46bd7df..2bc7e8edb3cbd 100644
> --- a/drivers/usb/typec/mux.c
> +++ b/drivers/usb/typec/mux.c
> @@ -56,17 +56,19 @@ static void *typec_switch_match(const struct fwnode_handle *fwnode,
> * function "defers probe" for now.
> */
> dev = class_find_device(&typec_mux_class, NULL, fwnode,
> switch_fwnode_match);
> + if (!dev)
> + return ERR_PTR(-EPROBE_DEFER);
>
> /* Skip duplicates */
> for (i = 0; i < TYPEC_MUX_MAX_DEVS; i++)
> if (to_typec_switch_dev(dev) == sw_devs[i]) {
> put_device(dev);
> return NULL;
> }
>
> - return dev ? to_typec_switch_dev(dev) : ERR_PTR(-EPROBE_DEFER);
> + return to_typec_switch_dev(dev);
> }
>
> /**
> * fwnode_typec_switch_get - Find USB Type-C orientation switch
> --
> 2.53.0
--
heikki
prev parent reply other threads:[~2026-08-24 11:44 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-17 18:22 Marek Vasut
2026-08-18 8:32 ` Thorsten Leemhuis
2026-08-18 8:58 ` Marek Vasut
2026-08-18 16:24 ` Sebastian Reichel
2026-08-18 16:56 ` Marek Vasut
2026-08-18 17:05 ` Jens Glathe
2026-08-18 17:43 ` Marek Vasut
2026-08-21 19:20 ` Jens Glathe
2026-08-22 7:27 ` Marek Vasut
2026-08-18 17:01 ` Jens Glathe
2026-08-24 11:44 ` Heikki Krogerus [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=aowuk3WwJW2Jomz8@black.igk.intel.com \
--to=heikki.krogerus@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=jens.glathe@oldschoolsolutions.biz \
--cc=kernel@dh-electronics.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=marex@nabladev.com \
--cc=sebastian.reichel@collabora.com \
--cc=stable@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®