From 79d867c2e683f7080a8724a54a4a12ac0ce1f837 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Thu, 5 May 2016 16:59:12 -0700 Subject: usb: ehci-mx6: allow board_ehci_hcd_init to fail There could be runtime determined board specific reason why a EHCI initialization fails (e.g. ENODEV if a Port is not available). In this case, properly return the error code. While at it, that function (board_ehci_hcd_init) has actually two documentation blocks... Use the correct function name for the documentation block of board_usb_phy_mode. Signed-off-by: Stefan Agner --- drivers/usb/host/ehci-mx6.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/usb/host/ehci-mx6.c b/drivers/usb/host/ehci-mx6.c index a981b50..bb48d0d 100644 --- a/drivers/usb/host/ehci-mx6.c +++ b/drivers/usb/host/ehci-mx6.c @@ -254,7 +254,7 @@ static void usb_oc_config(int index) } /** - * board_ehci_hcd_init - override usb phy mode + * board_usb_phy_mode - override usb phy mode * @port: usb host/otg port * * Target board specific, override usb_phy_mode. @@ -310,6 +310,7 @@ int ehci_hcd_init(int index, enum usb_init_type init, #endif struct usb_ehci *ehci = (struct usb_ehci *)(USB_BASE_ADDR + (controller_spacing * index)); + int ret; if (index > 3) return -EINVAL; @@ -317,7 +318,9 @@ int ehci_hcd_init(int index, enum usb_init_type init, mdelay(1); /* Do board specific initialization */ - board_ehci_hcd_init(index); + ret = board_ehci_hcd_init(index); + if (ret) + return ret; usb_power_config(index); usb_oc_config(index); -- cgit v1.1 From 2bf352f0c1b7f58d4610bc0777e8febbd2dfd5ff Mon Sep 17 00:00:00 2001 From: Stefan Roese Date: Fri, 6 May 2016 13:53:37 +0200 Subject: usb: dwc2: Add delay to fix the USB detection problem on SoCFPGA With patch c998da0d (usb: Change power-on / scanning timeout handling), the USB scanning is started earlier and with a smaller timeout. This resulted on SoCFPGA (using the DWC2 driver) in some USB sticks not getting detected any more. This patch now adds a 1 second delay (in the host mode only) to the DWC2 driver before the scanning is started. With this delay, now all problematic USB keys are detected successfully again. And there is no need any more to change the delay / timeout in the common USB code (usb_hub.c). Signed-off-by: Stefan Roese Cc: Chin Liang See Cc: Dinh Nguyen Cc: Hans de Goede Cc: Stephen Warren Cc: Marek Vasut --- drivers/usb/host/dwc2.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'drivers') diff --git a/drivers/usb/host/dwc2.c b/drivers/usb/host/dwc2.c index 30b51b3..d08879d 100644 --- a/drivers/usb/host/dwc2.c +++ b/drivers/usb/host/dwc2.c @@ -1088,6 +1088,15 @@ static int dwc2_init_common(struct dwc2_priv *priv) } } + /* + * Add a 1 second delay here. This gives the host controller + * a bit time before the comminucation with the USB devices + * is started (the bus is scanned) and fixes the USB detection + * problems with some problematic USB keys. + */ + if (readl(®s->gintsts) & DWC2_GINTSTS_CURMODE_HOST) + mdelay(1000); + return 0; } -- cgit v1.1 From 5d8fae79163e94671956c99654abf48cf49757ba Mon Sep 17 00:00:00 2001 From: Peng Fan Date: Tue, 3 May 2016 10:24:52 +0800 Subject: dfu: avoid memory leak MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When dfu_fill_entity fail, need to free dfu to avoid memory leak. Reported by Coverity: " Resource leak (RESOURCE_LEAK) leaked_storage: Variable dfu going out of scope leaks the storage it points to. " Signed-off-by: Peng Fan Cc: "Łukasz Majewski" Cc: Marek Vasut --- drivers/dfu/dfu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c index 8f5915e..20dfcbb 100644 --- a/drivers/dfu/dfu.c +++ b/drivers/dfu/dfu.c @@ -468,8 +468,10 @@ int dfu_config_entities(char *env, char *interface, char *devstr) s = strsep(&env, ";"); ret = dfu_fill_entity(&dfu[i], s, alt_num_cnt, interface, devstr); - if (ret) + if (ret) { + free(dfu); return -1; + } list_add_tail(&dfu[i].list, &dfu_list); alt_num_cnt++; -- cgit v1.1 From 12ff19dbfd93abdb62b7b326fee3f5bfa659a75e Mon Sep 17 00:00:00 2001 From: Peng Fan Date: Tue, 3 May 2016 10:25:22 +0800 Subject: usb: gadget: dfu: discard dead code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reported by Coverity: Logically dead code (DEADCODE) dead_error_line: Execution cannot reach this statement: (f_dfu->strings + --i).s = .... If calloc failed, i is still 0 and no need to call free, so discard the dead code. Signed-off-by: Peng Fan Cc: "Łukasz Majewski" Cc: Marek Vasut --- drivers/usb/gadget/f_dfu.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'drivers') diff --git a/drivers/usb/gadget/f_dfu.c b/drivers/usb/gadget/f_dfu.c index 7d88008..8e7c981 100644 --- a/drivers/usb/gadget/f_dfu.c +++ b/drivers/usb/gadget/f_dfu.c @@ -636,7 +636,7 @@ dfu_prepare_strings(struct f_dfu *f_dfu, int n) f_dfu->strings = calloc(sizeof(struct usb_string), n + 1); if (!f_dfu->strings) - goto enomem; + return -ENOMEM; for (i = 0; i < n; ++i) { de = dfu_get_entity(i); @@ -647,14 +647,6 @@ dfu_prepare_strings(struct f_dfu *f_dfu, int n) f_dfu->strings[i].s = NULL; return 0; - -enomem: - while (i) - f_dfu->strings[--i].s = NULL; - - free(f_dfu->strings); - - return -ENOMEM; } static int dfu_prepare_function(struct f_dfu *f_dfu, int n) -- cgit v1.1