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: <Pine.LNX.4.44L0.1504071140040.1430-100000@iolanthe.rowland.org>
Date:	Tue, 7 Apr 2015 11:52:39 -0400 (EDT)
From:	Alan Stern <stern@...land.harvard.edu>
To:	Ramneek Mehresh <ramneek.mehresh@...escale.com>
cc:	linux-kernel@...r.kernel.org, <linux-usb@...r.kernel.org>,
	<balbi@...com>, <gregkh@...uxfoundation.org>
Subject: Re: [PATCH 2/9][v2]usb:fsl:otg: Add support to add/remove usb host
 driver

On Tue, 7 Apr 2015, Ramneek Mehresh wrote:

> Add workqueue to add/remove host driver (outside interrupt context)
> upon each id change

This patch needs to be fixed.  See below.

> Signed-off-by: Ramneek Mehresh <ramneek.mehresh@...escale.com>
> ---
>  drivers/usb/host/ehci-fsl.c | 107 ++++++++++++++++++++++++++++++++++++--------
>  drivers/usb/host/ehci.h     |   1 -
>  2 files changed, 88 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
> index ab4eee3..9c91fbe 100644
> --- a/drivers/usb/host/ehci-fsl.c
> +++ b/drivers/usb/host/ehci-fsl.c
> @@ -33,6 +33,58 @@
>  
>  #include "ehci-fsl.h"
>  
> +struct ehci_fsl {
> +	struct ehci_hcd ehci;
> +
> +#ifdef CONFIG_PM
> +	/* Saved USB PHY settings, need to restore after deep sleep. */
> +	u32 usb_ctrl;
> +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
> +	struct work_struct change_hcd_work;
> +#endif
> +#endif
> +
> +	/* store current hcd state for otg;
> +	 * have_hcd is true when host drv al already part of otg framework,
> +	 * otherwise false;
> +	 * hcd_add is true when otg framework wants to add host
> +	 * drv as part of otg;flase when it wants to remove it
> +	 */
> +	unsigned have_hcd:1;
> +	unsigned hcd_add:1;
> +};

This is the wrong way to connect platform-private data with the
ehci_hcd structure.  The right way is to use an ehci_driver_overrides
structure, like in ehci-omap.c and quite a few other EHCI platform
drivers.

> +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
> +static struct ehci_fsl *hcd_to_ehci_fsl(struct usb_hcd *hcd)
> +{
> +	struct ehci_hcd *ehci = hcd_to_ehci(hcd);
> +
> +	return container_of(ehci, struct ehci_fsl, ehci);
> +}

This is bound to fail no matter what, because the ehci_hcd structure is 
already embedded in the usb_hcd structure.  It can't be embedded in an 
ehci_fsl structure too.

(Of course, this won't matter when you switch to the approved way of 
connecting private data.)

> +static void do_change_hcd(struct work_struct *work)
> +{
> +	struct ehci_fsl *ehci_fsl = container_of(work, struct ehci_fsl,
> +					change_hcd_work);
> +	struct ehci_hcd *ehci = &ehci_fsl->ehci;
> +	struct usb_hcd *hcd = ehci_to_hcd(ehci);
> +
> +	void __iomem *non_ehci = hcd->regs;
> +	int retval;
> +
> +	if (ehci_fsl->hcd_add && !ehci_fsl->have_hcd) {
> +		writel(USBMODE_CM_HOST, non_ehci + FSL_SOC_USB_USBMODE);
> +		/* host, gadget and otg share same int line */
> +		retval = usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
> +		if (retval == 0)
> +			ehci_fsl->have_hcd = 1;
> +	} else if (!ehci_fsl->hcd_add && ehci_fsl->have_hcd) {
> +		usb_remove_hcd(hcd);
> +		ehci_fsl->have_hcd = 0;
> +	}
> +}

Does this really work right?  What about things like 
device_wakeup_enable()?  Don't you need to disable the controller when 
leaving host mode and enable it when entering host mode?

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ