linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tcpm: allow looking for role_sw device in the main node
@ 2025-11-27 14:04 Arnaud Ferraris
  2025-12-15  9:55 ` Dragan Simic
  2025-12-23  9:45 ` Heikki Krogerus
  0 siblings, 2 replies; 3+ messages in thread
From: Arnaud Ferraris @ 2025-11-27 14:04 UTC (permalink / raw)
  To: Badhri Jagan Sridharan, Heikki Krogerus, Greg Kroah-Hartman,
	Michael Grzeschik
  Cc: linux-usb, linux-kernel, stable, Arnaud Ferraris

When ports are defined in the tcpc main node, fwnode_usb_role_switch_get
returns an error, meaning usb_role_switch_get (which would succeed)
never gets a chance to run as port->role_sw isn't NULL, causing a
regression on devices where this is the case.

Fix this by turning the NULL check into IS_ERR_OR_NULL, so
usb_role_switch_get can actually run and the device get properly probed.

Fixes: 2d8713f807a4 ("tcpm: switch check for role_sw device with fw_node")
Cc: stable@vger.kernel.org
Signed-off-by: Arnaud Ferraris <arnaud.ferraris@collabora.com>
---
 drivers/usb/typec/tcpm/tcpm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index cc78770509dbc..37698204d48d2 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -7877,7 +7877,7 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc)
 	port->partner_desc.identity = &port->partner_ident;
 
 	port->role_sw = fwnode_usb_role_switch_get(tcpc->fwnode);
-	if (!port->role_sw)
+	if (IS_ERR_OR_NULL(port->role_sw))
 		port->role_sw = usb_role_switch_get(port->dev);
 	if (IS_ERR(port->role_sw)) {
 		err = PTR_ERR(port->role_sw);

---
base-commit: 765e56e41a5af2d456ddda6cbd617b9d3295ab4e
change-id: 20251127-fix-ppp-power-6d47f3a746f8

Best regards,
-- 
Arnaud Ferraris <arnaud.ferraris@collabora.com>


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] tcpm: allow looking for role_sw device in the main node
  2025-11-27 14:04 [PATCH] tcpm: allow looking for role_sw device in the main node Arnaud Ferraris
@ 2025-12-15  9:55 ` Dragan Simic
  2025-12-23  9:45 ` Heikki Krogerus
  1 sibling, 0 replies; 3+ messages in thread
From: Dragan Simic @ 2025-12-15  9:55 UTC (permalink / raw)
  To: arnaud.ferraris
  Cc: badhri, gregkh, heikki.krogerus, linux-kernel, linux-usb,
	m.grzeschik, stable

Hello Arnaud,

Thanks for this patch!  Please, see some comments below.

On Thu, 27 Nov 2025 15:04:15 +0100, Arnaud Ferraris <arnaud.ferraris@collabora.com> wrote:
> When ports are defined in the tcpc main node, fwnode_usb_role_switch_get
> returns an error, meaning usb_role_switch_get (which would succeed)
> never gets a chance to run as port->role_sw isn't NULL, causing a
> regression on devices where this is the case.
> 
> Fix this by turning the NULL check into IS_ERR_OR_NULL, so
> usb_role_switch_get can actually run and the device get properly probed.

It's usual to denote functions by always appending a pair of braces
to their names, so we'd have "fwnode_usb_role_switch_get()" in the
patch description above, for example.

> Fixes: 2d8713f807a4 ("tcpm: switch check for role_sw device with fw_node")
> Cc: stable@vger.kernel.org
> Signed-off-by: Arnaud Ferraris <arnaud.ferraris@collabora.com>
> ---
>  drivers/usb/typec/tcpm/tcpm.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index cc78770509dbc..37698204d48d2 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -7877,7 +7877,7 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc)
>  	port->partner_desc.identity = &port->partner_ident;
>  
>  	port->role_sw = fwnode_usb_role_switch_get(tcpc->fwnode);
> -	if (!port->role_sw)
> +	if (IS_ERR_OR_NULL(port->role_sw))
>  		port->role_sw = usb_role_switch_get(port->dev);
>  	if (IS_ERR(port->role_sw)) {
>  		err = PTR_ERR(port->role_sw);

This is looking good to me.  The usb_role_switch_is_parent() function,
invoked by fwnode_usb_role_switch_get(), can return -EPROBE_DEFER, so
using IS_ERR_OR_NULL() is the way to go.  It's already used in the
fwnode_usb_role_switch_get() function itself for checking against error
conditions, which solidifies this as a proper regression fix.

With the above-mentioned nitpicks addressed, please feel free to include

Reviewed-by: Dragan Simic <dsimic@manjaro.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] tcpm: allow looking for role_sw device in the main node
  2025-11-27 14:04 [PATCH] tcpm: allow looking for role_sw device in the main node Arnaud Ferraris
  2025-12-15  9:55 ` Dragan Simic
@ 2025-12-23  9:45 ` Heikki Krogerus
  1 sibling, 0 replies; 3+ messages in thread
From: Heikki Krogerus @ 2025-12-23  9:45 UTC (permalink / raw)
  To: Arnaud Ferraris
  Cc: Badhri Jagan Sridharan, Greg Kroah-Hartman, Michael Grzeschik,
	linux-usb, linux-kernel, stable

Thu, Nov 27, 2025 at 03:04:15PM +0100, Arnaud Ferraris kirjoitti:
> When ports are defined in the tcpc main node, fwnode_usb_role_switch_get
> returns an error, meaning usb_role_switch_get (which would succeed)
> never gets a chance to run as port->role_sw isn't NULL, causing a
> regression on devices where this is the case.
> 
> Fix this by turning the NULL check into IS_ERR_OR_NULL, so
> usb_role_switch_get can actually run and the device get properly probed.
> 
> Fixes: 2d8713f807a4 ("tcpm: switch check for role_sw device with fw_node")
> Cc: stable@vger.kernel.org
> Signed-off-by: Arnaud Ferraris <arnaud.ferraris@collabora.com>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/usb/typec/tcpm/tcpm.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index cc78770509dbc..37698204d48d2 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -7877,7 +7877,7 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc)
>  	port->partner_desc.identity = &port->partner_ident;
>  
>  	port->role_sw = fwnode_usb_role_switch_get(tcpc->fwnode);
> -	if (!port->role_sw)
> +	if (IS_ERR_OR_NULL(port->role_sw))
>  		port->role_sw = usb_role_switch_get(port->dev);
>  	if (IS_ERR(port->role_sw)) {
>  		err = PTR_ERR(port->role_sw);
> 
> ---
> base-commit: 765e56e41a5af2d456ddda6cbd617b9d3295ab4e
> change-id: 20251127-fix-ppp-power-6d47f3a746f8
> 
> Best regards,
> -- 
> Arnaud Ferraris <arnaud.ferraris@collabora.com>

-- 
heikki

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-12-23  9:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-27 14:04 [PATCH] tcpm: allow looking for role_sw device in the main node Arnaud Ferraris
2025-12-15  9:55 ` Dragan Simic
2025-12-23  9:45 ` Heikki Krogerus

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).