mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Frank Li <Frank.li@nxp.com>
To: Xu Yang <xu.yang_2@nxp.com>
Cc: peter.chen@kernel.org, gregkh@linuxfoundation.org,
	jun.li@nxp.com, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org, imx@lists.linux.dev
Subject: Re: [PATCH 3/3] usb: chipidea: core: convert ci_role_switch to local variable
Date: Tue, 21 Apr 2026 22:29:42 -0400	[thread overview]
Message-ID: <aegyltY3LiX7YU0T@lizhi-Precision-Tower-5810> (raw)
In-Reply-To: <20260421082436.1264442-3-xu.yang_2@nxp.com>

On Tue, Apr 21, 2026 at 04:24:36PM +0800, Xu Yang wrote:
> When a system contains multiple USB controllers, the global ci_role_switch
> variable may be overwritten by subsequent driver initialization code.
>
> This can cause issues in the following cases:
>  - The 2nd ci_hdrc_probe() sees ci_role_switch.fwnode as non-NULL even
>    though the "usb-role-switch" property is not present for the controller.
>  - When the ci_hdrc device is unbound and bound again, ci_role_switch
>    fwnode will not be reassigned, and the old value will be used instead.
>
> Convert ci_role_switch to a local variable to fix these issues.
>
> Fixes: 05559f10ed79 ("usb: chipidea: add role switch class support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
> ---
Reviewed-by: Frank Li <Frank.Li@nxp.com>
>  drivers/usb/chipidea/core.c | 16 ++++++----------
>  1 file changed, 6 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
> index 95d9db159ce8..07563be0013f 100644
> --- a/drivers/usb/chipidea/core.c
> +++ b/drivers/usb/chipidea/core.c
> @@ -655,12 +655,6 @@ static enum ci_role ci_get_role(struct ci_hdrc *ci)
>  	return role;
>  }
>
> -static struct usb_role_switch_desc ci_role_switch = {
> -	.set = ci_usb_role_switch_set,
> -	.get = ci_usb_role_switch_get,
> -	.allow_userspace_control = true,
> -};
> -
>  static int ci_get_platdata(struct device *dev,
>  		struct ci_hdrc_platform_data *platdata)
>  {
> @@ -787,9 +781,6 @@ static int ci_get_platdata(struct device *dev,
>  			cable->connected = false;
>  	}
>
> -	if (device_property_read_bool(dev, "usb-role-switch"))
> -		ci_role_switch.fwnode = dev->fwnode;
> -
>  	platdata->pctl = devm_pinctrl_get(dev);
>  	if (!IS_ERR(platdata->pctl)) {
>  		struct pinctrl_state *p;
> @@ -1033,6 +1024,7 @@ ATTRIBUTE_GROUPS(ci);
>
>  static int ci_hdrc_probe(struct platform_device *pdev)
>  {
> +	struct usb_role_switch_desc ci_role_switch = {};
>  	struct device	*dev = &pdev->dev;
>  	struct ci_hdrc	*ci;
>  	struct resource	*res;
> @@ -1179,7 +1171,11 @@ static int ci_hdrc_probe(struct platform_device *pdev)
>  		}
>  	}
>
> -	if (ci_role_switch.fwnode) {
> +	if (device_property_read_bool(dev, "usb-role-switch")) {
> +		ci_role_switch.set = ci_usb_role_switch_set;
> +		ci_role_switch.get = ci_usb_role_switch_get;
> +		ci_role_switch.allow_userspace_control = true;
> +		ci_role_switch.fwnode = dev_fwnode(dev);
>  		ci_role_switch.driver_data = ci;
>  		ci->role_switch = usb_role_switch_register(dev,
>  					&ci_role_switch);
> --
> 2.34.1
>

  reply	other threads:[~2026-04-22  2:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-21  8:24 [PATCH 1/3] usb: chipidea: udc: add a helper ci_udc_enable_vbus_irq() Xu Yang
2026-04-21  8:24 ` [PATCH 2/3] usb: chipidea: udc: support dynamic gadget add/remove Xu Yang
2026-04-22  2:58   ` Peter Chen (CIX)
2026-04-22  3:05   ` Frank Li
2026-04-23 10:02     ` Xu Yang
2026-04-21  8:24 ` [PATCH 3/3] usb: chipidea: core: convert ci_role_switch to local variable Xu Yang
2026-04-22  2:29   ` Frank Li [this message]
2026-04-22  2:59   ` Peter Chen (CIX)
2026-04-21  9:28 ` [PATCH 1/3] usb: chipidea: udc: add a helper ci_udc_enable_vbus_irq() Frank Li
2026-04-22  1:17 ` Peter Chen (CIX)

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=aegyltY3LiX7YU0T@lizhi-Precision-Tower-5810 \
    --to=frank.li@nxp.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=imx@lists.linux.dev \
    --cc=jun.li@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=peter.chen@kernel.org \
    --cc=xu.yang_2@nxp.com \
    /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®