Re: [PATCH] usb: typec: mux: avoid duplicated mux switches

Sebastian Reichel <[email protected]>
Newsgroups org.kernel.vger.stable,org.kernel.vger.linux-kernel,org.kernel.vger.linux-usb
Message-ID <aow2wbpZzN2oyWCv@venus>
Hi,

On Sat, Aug 22, 2026 at 09:24:58AM +0200, Marek Vasut wrote:
> Some devices use combo PHYs (i.e. USB3 + DisplayPort), which also
> handle the lane muxing. These PHYs are referenced twice from
> the USB-C connector (USB super-speed lines and SBU/AUX lines)
> resulting in the mux being configured twice. Avoid this by
> dropping duplicates.
> 
> This is a re-application of b145c3f29d62 ("usb: typec: mux: avoid
> duplicated mux switches"), with fix derived from usb: typec: mux:
> Fix typec_switch_match() .
> 
> Fixes: f576c75f95a5 ("Revert "usb: typec: mux: avoid duplicated mux switches"")
> Cc: [email protected]
> Signed-off-by: Sebastian Reichel <[email protected]>
> Co-developed-by: Sebastian Reichel <[email protected]>
> Signed-off-by: Marek Vasut <[email protected]>
> ---
> Cc: Greg Kroah-Hartman <[email protected]>
> Cc: Heikki Krogerus <[email protected]>
> Cc: Jens Glathe <[email protected]>
> Cc: Sebastian Reichel <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Cc: [email protected]
> ---
> - Extensive test by Jens https://lore.kernel.org/all/[email protected]/

Thanks for the fixed version. It looks mostly good to me, but it
should also take the other fix into account and initialize
mux_devs to {} in fwnode_typec_mux_get():

https://lore.kernel.org/linux-usb/[email protected]/

Greetings,

-- Sebastian

> ---
>  drivers/usb/typec/mux.c | 17 +++++++++++++++--
>  1 file changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c
> index 2bc7e8edb3cbd..afa6fc1813978 100644
> --- a/drivers/usb/typec/mux.c
> +++ b/drivers/usb/typec/mux.c
> @@ -277,7 +277,9 @@ static int mux_fwnode_match(struct device *dev, const void *fwnode)
>  static void *typec_mux_match(const struct fwnode_handle *fwnode,
>  			     const char *id, void *data)
>  {
> +	struct typec_mux_dev **mux_devs = data;
>  	struct device *dev;
> +	int i;
>  
>  	/*
>  	 * Device graph (OF graph) does not give any means to identify the
> @@ -292,8 +294,18 @@ static void *typec_mux_match(const struct fwnode_handle *fwnode,
>  
>  	dev = class_find_device(&typec_mux_class, NULL, fwnode,
>  				mux_fwnode_match);
> +	if (!dev)
> +		return ERR_PTR(-EPROBE_DEFER);
>  
> -	return dev ? to_typec_mux_dev(dev) : ERR_PTR(-EPROBE_DEFER);
> +	/* Skip duplicates */
> +	for (i = 0; i < TYPEC_MUX_MAX_DEVS; i++)
> +		if (to_typec_mux_dev(dev) == mux_devs[i]) {
> +			put_device(dev);
> +			return NULL;
> +		}
> +
> +
> +	return to_typec_mux_dev(dev);
>  }
>  
>  /**
> @@ -318,7 +330,8 @@ struct typec_mux *fwnode_typec_mux_get(struct fwnode_handle *fwnode)
>  		return ERR_PTR(-ENOMEM);
>  
>  	count = fwnode_connection_find_matches(fwnode, "mode-switch",
> -					       NULL, typec_mux_match,
> +					       (void **)mux_devs,
> +					       typec_mux_match,
>  					       (void **)mux_devs,
>  					       ARRAY_SIZE(mux_devs));
>  	if (count <= 0) {
> -- 
> 2.53.0
>
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEE72YNB0Y/i3JqeVQT2O7X88g7+poFAmqMOVgACgkQ2O7X88g7
+pojhg//YZzo6unqhGvO9Hmxu0MNjXVlQetPuewYf8o0P7hEHF7ZwrWZ2cCowTkm
305UYsckiFGj8/X1CCHdOkdDKGnxDddVk0q/3UJBpUZU+kdMEOYEgAIq/XC3h9+y
KZOn3ddZjHTB6KHDW3qsfM0lkOvWDCgzNEGr+cNwy21zue/NBofdMB+BgxhLAWIP
rgEGz8r0xvuS5zpUcHi9Dq9iXicmh4X+1rmetN39Om6dJdAPXK7TTotZrVTY7+3c
ZK6dEZJTB5/A/KyOHYuRqsuADrLjTpnoBsr2BvL+BqPBLN/GjuFkt9rfI2y3+8Ag
f84Gai54zJ96sQiXlgb2PU5dKELaPT2XYF+smiWUG6XRJ62dA0vyium2bi9m1EGE
BM1sM8TdX+HcAy75g4/kT60tgir/1hxHCQoH84LE6w/q43fYkWBAcmMK/5072uO6
ezeU6Oln9rxGWDoq7eWC3Q37jIXShuhBQDv2bYW9lqIx4iWxgtC9Atn+ZY+juPZ+
6FHvWul3xxN5l3t1+N+dFglGgfO8cBY17fBc4P4T7LVzlFkR0XLC/2Df/bBpLbCD
MkUaEBWkLjion8a0CVpaJST+5bszsHhhfbqSWwjsmgAMHyws23vH75jx1VzhGCHl
yFIfpqcl6BkbPq6YSdZntzl4bGVTtNQfflqN271gFqfU79GNAMM=
=g7r5
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.