Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1986753imu; Fri, 14 Dec 2018 04:07:03 -0800 (PST) X-Google-Smtp-Source: AFSGD/WptHljsrGu1L/Ll69Wz+aodG/7NnJb50YF6sxCNLbj0JnWdWDdIw9JqexTzouOKjan6vXY X-Received: by 2002:a17:902:f01:: with SMTP id 1mr2527186ply.143.1544789223025; Fri, 14 Dec 2018 04:07:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544789222; cv=none; d=google.com; s=arc-20160816; b=gvnHpFKqT90Ke9OvLDRC5Fiopnanuwz5cnU7yk7gCcGxappZfATIA11gT/qznLK5Am FChAKa1subPmaRR7NiSoWLrXNFTAY0BcQKYNp4LKEhCxIQY99YelevdHkb8ww7y3zEPC M5tVPFT4S2DW6xScP5xJ71+6kmnS5iy+eui6g24/aYUGq94F36KXUbaOrVEr7El29jAT +E5zm81sjKLVr3g0fyDJU6wx+XmmTIYbzhOjRaHxdFtpIAsAngZBfo6LuvbEjW/+dED/ PGRclCujgSzskT9oOSPUZrTf6aIbFadXHO30uw94o3qwyF6VV3i/3GTMGDH692pRBd56 qqAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=egS/m4BdQEly7dJJiyVHysvOVJps/E1wWAYj53jJRzA=; b=HaGvRNBMdc5pQxuC34FRZs5drfhpoQnhJJK7R/IVN3ASU8+8zzIA13YORc13bWFyaW xOVrS2ha7k8AeJhwfoteC3YY7hIu+ukHSKyxKsO8ZeBjo0LBvodMgeXpGxBsujXDndKp GHy4uojwjtCAPUrjJxwG4bG4ngKEoSbfPzvXenROGT9kcoE0/BGkfNrkKa/7bbxtBZMM rEPqhKShKBcJkARL6igFhtyQtfai0wuFDOtbgDkYvMIwZxYZ9I55vFaGRa6dzopwsC1m xmfKDnUq2/qdLGZfQcWsK8CM5IacoOxEfJDFI032RDnTOTZAKwf65eRkZix+A4seXpoH UXxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Erd8rVfD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u11si4145063plm.8.2018.12.14.04.06.48; Fri, 14 Dec 2018 04:07:02 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Erd8rVfD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730002AbeLNMEl (ORCPT + 99 others); Fri, 14 Dec 2018 07:04:41 -0500 Received: from mail.kernel.org ([198.145.29.99]:49362 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729788AbeLNMEj (ORCPT ); Fri, 14 Dec 2018 07:04:39 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 67D1F2147D; Fri, 14 Dec 2018 12:04:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544789077; bh=/ea1sVZVlnFhV+Il91RsO7gXWlbBMAVgNhg5IDQlT+g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Erd8rVfDs3LbVSuEc9l6pSLVqmhSzzWQSrtgRJEH/ZyBQXj0nIGQqGLesUOYrPywf 8+8Z+YfIAq3zZkNQgtRDievAVEsNMSj+FpdTAZ2gpROkupqux+AuBBBnmvCp038y0k MiEfzL7Z1ikX96hZwj+Z2L3G/FwcTkwYYDcGBuGA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Aaro Koskinen , Felipe Balbi , Sasha Levin Subject: [PATCH 4.19 086/142] USB: omap_udc: fix crashes on probe error and module removal Date: Fri, 14 Dec 2018 12:59:31 +0100 Message-Id: <20181214115750.500715419@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181214115747.053633987@linuxfoundation.org> References: <20181214115747.053633987@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 99f700366fcea1aa2fa3c49c99f371670c3c62f8 ] We currently crash if usb_add_gadget_udc_release() fails, since the udc->done is not initialized until in the remove function. Furthermore, on module removal the udc data is accessed although the release function is already triggered by usb_del_gadget_udc() early in the function. Fix by rewriting the release and remove functions, basically moving all the cleanup into the release function, and doing the completion only in the module removal case. The patch fixes omap_udc module probe with a failing gadged, and also allows the removal of omap_udc. Tested by running "modprobe omap_udc; modprobe -r omap_udc" in a loop. Signed-off-by: Aaro Koskinen Signed-off-by: Felipe Balbi Signed-off-by: Sasha Levin --- drivers/usb/gadget/udc/omap_udc.c | 50 ++++++++++++------------------- 1 file changed, 19 insertions(+), 31 deletions(-) diff --git a/drivers/usb/gadget/udc/omap_udc.c b/drivers/usb/gadget/udc/omap_udc.c index 1c77218c82af..240ccba44592 100644 --- a/drivers/usb/gadget/udc/omap_udc.c +++ b/drivers/usb/gadget/udc/omap_udc.c @@ -2593,9 +2593,22 @@ omap_ep_setup(char *name, u8 addr, u8 type, static void omap_udc_release(struct device *dev) { - complete(udc->done); + pullup_disable(udc); + if (!IS_ERR_OR_NULL(udc->transceiver)) { + usb_put_phy(udc->transceiver); + udc->transceiver = NULL; + } + omap_writew(0, UDC_SYSCON1); + remove_proc_file(); + if (udc->dc_clk) { + if (udc->clk_requested) + omap_udc_enable_clock(0); + clk_put(udc->hhc_clk); + clk_put(udc->dc_clk); + } + if (udc->done) + complete(udc->done); kfree(udc); - udc = NULL; } static int @@ -2900,12 +2913,8 @@ static int omap_udc_probe(struct platform_device *pdev) } create_proc_file(); - status = usb_add_gadget_udc_release(&pdev->dev, &udc->gadget, - omap_udc_release); - if (!status) - return 0; - - remove_proc_file(); + return usb_add_gadget_udc_release(&pdev->dev, &udc->gadget, + omap_udc_release); cleanup1: kfree(udc); @@ -2932,36 +2941,15 @@ static int omap_udc_remove(struct platform_device *pdev) { DECLARE_COMPLETION_ONSTACK(done); - if (!udc) - return -ENODEV; - - usb_del_gadget_udc(&udc->gadget); - if (udc->driver) - return -EBUSY; - udc->done = &done; - pullup_disable(udc); - if (!IS_ERR_OR_NULL(udc->transceiver)) { - usb_put_phy(udc->transceiver); - udc->transceiver = NULL; - } - omap_writew(0, UDC_SYSCON1); - - remove_proc_file(); + usb_del_gadget_udc(&udc->gadget); - if (udc->dc_clk) { - if (udc->clk_requested) - omap_udc_enable_clock(0); - clk_put(udc->hhc_clk); - clk_put(udc->dc_clk); - } + wait_for_completion(&done); release_mem_region(pdev->resource[0].start, pdev->resource[0].end - pdev->resource[0].start + 1); - wait_for_completion(&done); - return 0; } -- 2.19.1