From: George Cherian <george.cherian@ti.com>
To: linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org,
linux-omap@vger.kernel.org, linux-usb@vger.kernel.org
Cc: mark.rutland@arm.com, George Cherian <george.cherian@ti.com>,
kgene.kim@samsung.com, linux@arm.linux.org.uk,
ben-linux@fluff.org, mathias.nyman@intel.com,
ijc+devicetree@hellion.org.uk, tony@atomide.com,
gregkh@linuxfoundation.org, sojka@merica.cz, balbi@ti.com,
robh+dt@kernel.org, pawel.moll@arm.com, peter.chen@freescale.com,
bcousson@baylibre.com, galak@codeaurora.org
Subject: [PATCH 02/19] usb: host xhci: fix up deallocation code
Date: Tue, 25 Nov 2014 18:41:38 +0530 [thread overview]
Message-ID: <1416921115-10467-3-git-send-email-george.cherian@ti.com> (raw)
In-Reply-To: <1416921115-10467-1-git-send-email-george.cherian@ti.com>
This fixes up the deallocation code in the xhci driver, so that
usb_add_hcd()/usb_remove_hcd() can be called repeatedly without
crashing.
In case of DRD mode, the DRD library calls /usb_remove_hcd() while
switching from HOST mode to Device mode, but it doesnot call usb_put_hcd().
We need to preserve the already allocated xhci struct for the subsequent
call of usb_add_hcd() from the DRD library.
A new quirk flag XHCI_DRD_SUPPORT is added to differentiate between
normal usb_remove_hcd and drd specific call.
Signed-off-by: George Cherian <george.cherian@ti.com>
---
drivers/usb/host/xhci.c | 22 ++++++++++++++++------
drivers/usb/host/xhci.h | 1 +
2 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 2a5d45b..d4196f8 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -666,7 +666,8 @@ static void xhci_only_stop_hcd(struct usb_hcd *hcd)
* calls this function when allocation fails in usb_add_hcd(), or
* usb_remove_hcd() is called). So we need to unset xHCI's pointer.
*/
- xhci->shared_hcd = NULL;
+ if (!(xhci->quirks & XHCI_DRD_SUPPORT))
+ xhci->shared_hcd = NULL;
spin_unlock_irq(&xhci->lock);
}
@@ -4815,6 +4816,7 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks)
struct xhci_hcd *xhci;
struct device *dev = hcd->self.controller;
int retval;
+ bool allocated = false;
/* Accept arbitrarily long scatter-gather lists */
hcd->self.sg_tablesize = ~0;
@@ -4826,10 +4828,15 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks)
hcd->self.no_stop_on_short = 1;
if (usb_hcd_is_primary_hcd(hcd)) {
- xhci = kzalloc(sizeof(struct xhci_hcd), GFP_KERNEL);
- if (!xhci)
- return -ENOMEM;
- *((struct xhci_hcd **) hcd->hcd_priv) = xhci;
+ if (*((struct xhci_hcd **)hcd->hcd_priv) == NULL) {
+ xhci = kzalloc(sizeof(struct xhci_hcd), GFP_KERNEL);
+ if (!xhci)
+ return -ENOMEM;
+ *((struct xhci_hcd **)hcd->hcd_priv) = xhci;
+ allocated = true;
+ } else {
+ xhci = *((struct xhci_hcd **)hcd->hcd_priv);
+ }
xhci->main_hcd = hcd;
/* Mark the first roothub as being USB 2.0.
* The xHCI driver will register the USB 3.0 roothub.
@@ -4902,7 +4909,10 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks)
xhci_dbg(xhci, "Called HCD init\n");
return 0;
error:
- kfree(xhci);
+ if (allocated) {
+ *((struct xhci_hcd **)hcd->hcd_priv) = NULL;
+ kfree(xhci);
+ }
return retval;
}
EXPORT_SYMBOL_GPL(xhci_gen_setup);
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index df76d64..2248058 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1560,6 +1560,7 @@ struct xhci_hcd {
#define XHCI_SPURIOUS_WAKEUP (1 << 18)
/* For controllers with a broken beyond repair streams implementation */
#define XHCI_BROKEN_STREAMS (1 << 19)
+#define XHCI_DRD_SUPPORT (1 << 20)
unsigned int num_active_eps;
unsigned int limit_active_eps;
/* There are two roothubs to keep track of bus suspend info for */
--
1.8.3.1
next prev parent reply other threads:[~2014-11-25 13:11 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-25 13:11 [PATCH 00/19] Add Support for USB DRD in AM437x George Cherian
2014-11-25 13:11 ` [PATCH 01/19] usb: common: drd-lib: Add DRD lib for USB George Cherian
2014-11-26 5:14 ` Peter Chen
2014-11-25 13:11 ` George Cherian [this message]
2014-11-25 13:11 ` [PATCH 03/19] usb: host: xhci-plat: Add support to pass XHCI_DRD_SUPPORT quirk George Cherian
2014-11-25 13:11 ` [PATCH 04/19] usb: host xhci: Add XHCI_NEEDS_LHC_RESET quirk George Cherian
2014-11-25 13:11 ` [PATCH 05/19] usb: host: xhci-plat: Add support to pass " George Cherian
2014-11-25 13:11 ` [PATCH 06/19] usb: dwc3: host: Pass the XHCI_DRD_SUPPORT and " George Cherian
2014-11-27 2:00 ` Lu, Baolu
2014-11-25 13:11 ` [PATCH 07/19] usb: host: xhci: Adapt xhci to use usb drd library George Cherian
2014-11-25 13:11 ` [PATCH 08/19] usb: dwc3: core: Add dwc3_drd_helper function George Cherian
2014-11-25 13:11 ` [PATCH 09/19] usb: dwc3: dwc3-omap: Make the wrapper interrupt shared George Cherian
2014-11-25 13:11 ` [PATCH 10/19] usb: dwc3: core: Adapt to named interrupts George Cherian
2014-11-25 13:11 ` [PATCH 11/19] usb: dwc3: Add seperate dwc3_gadget object to support gadget release George Cherian
2014-11-25 13:11 ` [PATCH 12/19] usb: dwc3: gadget: Adapt gadget to drd library George Cherian
2014-11-25 13:11 ` [PATCH 13/19] usb: dwc3: core: Add DWC3 OTG specific register defines George Cherian
2014-11-25 13:11 ` [PATCH 14/19] usb: dwc3: otg: Add the initial otg driver for dwc3 George Cherian
2014-11-25 13:11 ` [PATCH 15/19] arm: dts: am4372: Add named interrupt property " George Cherian
2014-11-25 13:11 ` [PATCH 16/19] arm: dts: omap5: " George Cherian
2014-11-25 13:11 ` [PATCH 17/19] arm: dts: dra7: " George Cherian
2014-11-25 13:11 ` [PATCH 18/19] arm: dts: exynos5250: " George Cherian
2014-11-25 13:11 ` [PATCH 19/19] arm: dts: am43x evms: Make usb1 as OTG George Cherian
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=1416921115-10467-3-git-send-email-george.cherian@ti.com \
--to=george.cherian@ti.com \
--cc=balbi@ti.com \
--cc=bcousson@baylibre.com \
--cc=ben-linux@fluff.org \
--cc=galak@codeaurora.org \
--cc=gregkh@linuxfoundation.org \
--cc=ijc+devicetree@hellion.org.uk \
--cc=kgene.kim@samsung.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=linux@arm.linux.org.uk \
--cc=mark.rutland@arm.com \
--cc=mathias.nyman@intel.com \
--cc=pawel.moll@arm.com \
--cc=peter.chen@freescale.com \
--cc=robh+dt@kernel.org \
--cc=sojka@merica.cz \
--cc=tony@atomide.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;
as well as URLs for NNTP newsgroup(s).