lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251113223739.akelb3tke24gpjpq@synopsys.com>
Date: Thu, 13 Nov 2025 22:37:40 +0000
From: Thinh Nguyen <Thinh.Nguyen@...opsys.com>
To: Xu Yang <xu.yang_2@....com>
CC: Thinh Nguyen <Thinh.Nguyen@...opsys.com>,
        "gregkh@...uxfoundation.org" <gregkh@...uxfoundation.org>,
        "shawnguo@...nel.org" <shawnguo@...nel.org>,
        "s.hauer@...gutronix.de" <s.hauer@...gutronix.de>,
        "kernel@...gutronix.de" <kernel@...gutronix.de>,
        "festevam@...il.com" <festevam@...il.com>,
        "linux-usb@...r.kernel.org" <linux-usb@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "imx@...ts.linux.dev" <imx@...ts.linux.dev>,
        "linux-arm-kernel@...ts.infradead.org" <linux-arm-kernel@...ts.infradead.org>,
        "jun.li@....com" <jun.li@....com>
Subject: Re: [PATCH 1/2] usb: dwc3: drd: extend dwc3_pre_set_role() to extcon
 and otg usecase

On Wed, Nov 05, 2025, Xu Yang wrote:
> Extend dwc3_pre_set_role() to extcon and otg usecase, so that the glue
> driver can do proper action in case of role changes.
> 
> Signed-off-by: Xu Yang <xu.yang_2@....com>
> ---
>  drivers/usb/dwc3/drd.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c
> index 589bbeb27454..031cfd12300a 100644
> --- a/drivers/usb/dwc3/drd.c
> +++ b/drivers/usb/dwc3/drd.c
> @@ -381,6 +381,7 @@ void dwc3_otg_update(struct dwc3 *dwc, bool ignore_idstatus)
>  		dwc3_otgregs_init(dwc);
>  		dwc3_otg_host_init(dwc);
>  		spin_unlock_irqrestore(&dwc->lock, flags);
> +		dwc3_pre_set_role(dwc, USB_ROLE_HOST);
>  		ret = dwc3_host_init(dwc);
>  		if (ret) {
>  			dev_err(dwc->dev, "failed to initialize host\n");
> @@ -406,6 +407,7 @@ void dwc3_otg_update(struct dwc3 *dwc, bool ignore_idstatus)
>  			otg_set_vbus(dwc->usb2_phy->otg, false);
>  		if (dwc->usb2_generic_phy[0])
>  			phy_set_mode(dwc->usb2_generic_phy[0], PHY_MODE_USB_DEVICE);
> +		dwc3_pre_set_role(dwc, USB_ROLE_DEVICE);
>  		ret = dwc3_gadget_init(dwc);
>  		if (ret)
>  			dev_err(dwc->dev, "failed to initialize peripheral\n");
> @@ -433,10 +435,12 @@ static int dwc3_drd_notifier(struct notifier_block *nb,
>  			     unsigned long event, void *ptr)
>  {
>  	struct dwc3 *dwc = container_of(nb, struct dwc3, edev_nb);
> +	u32 mode = event ? DWC3_GCTL_PRTCAP_HOST : DWC3_GCTL_PRTCAP_DEVICE;
> +	enum usb_role role = mode == DWC3_GCTL_PRTCAP_HOST ?
> +				     USB_ROLE_HOST : USB_ROLE_DEVICE;
>  
> -	dwc3_set_mode(dwc, event ?
> -		      DWC3_GCTL_PRTCAP_HOST :
> -		      DWC3_GCTL_PRTCAP_DEVICE);
> +	dwc3_pre_set_role(dwc, role);
> +	dwc3_set_mode(dwc, mode);
>  
>  	return NOTIFY_DONE;
>  }
> -- 
> 2.34.1
> 

I don't like how the ternary operator is used here and how we've done it
previously, especially when we're treating the event as if it's a
boolean.

Regardless, it's a minor nit.

Acked-by: Thinh Nguyen <Thinh.Nguyen@...opsys.com>

BR,
Thinh

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ