Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1996832imu; Fri, 14 Dec 2018 04:15:13 -0800 (PST) X-Google-Smtp-Source: AFSGD/Wydok0qRqV272YFJ6IvRsi0Ycs8EYf9HZgY4dK0ZuC4D6l4fxxNRlsRqzSfBla/Pa4fOSB X-Received: by 2002:a62:c101:: with SMTP id i1mr2625624pfg.80.1544789713002; Fri, 14 Dec 2018 04:15:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544789712; cv=none; d=google.com; s=arc-20160816; b=fXBgKjL7lnclt4k92kZ5r2GEGjCzYINCoR7t23LBOjRtxb60BJxhyBf9zKjKEYXjHl GKYKT7mJ4RXHoFoKYUGYidZn6KmCZ+kPaQiSt8QVneyYOc4BGXW6Eb3RzkGO5hoIeayX u0JjvTuNKm9pA75cK7U+PBT6sIHRVChWc6JFk0H184f5FKXDrP0y4sc2K73IVHmTE04F GRqToB7uijNsFFEOEnlaXxo3MT89lEuEzZs3RXpEbyAROUlE8Owd725UJOP9LOVVJiay D/BtxzraPklm8NOUm0Mtt8MHD7z1x/BhIcefba8Pvb7Z7jY+puUd7aEqM27EB6ss6BlJ NniA== 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=K+DuzVbgsMYpwQsVHFYXCrqbkJxnWnKtFk54w8JO7N8=; b=K3YdyzG3Gq2PB/irAh8f7X+oldmsgI/1Q/PBebbO+18J2UM5QVYGviKPNlvZqR3YqB P2Vsw0st0hRjIj7x46mXCVGC98wuwh/oLec7PSQzyvtcticPRd0Fdf9moiI1HZvOptqw Imx13u5+FDM5VXr9dcUQ6pLMzagbnGyL+WxeyyPgFtCLSTvyq1c/e2pIw4xKwKMamzWy jj1GnQGWY+8nokJGuEsxscqQTS0g2RrVewZ3x5lcIy2jID0EZxsO6jLjAyKWIpDL+nx/ EoGRUkKtalIrPB6eCerJTFL1iuzAMSwF7Iuz0kqzWXd3OPgtSRsKyb9bZ4ObxdD3RCyU ms3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Kn7qrTp5; 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 d23si4023156pgm.559.2018.12.14.04.14.58; Fri, 14 Dec 2018 04:15:12 -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=Kn7qrTp5; 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 S1732288AbeLNMOM (ORCPT + 99 others); Fri, 14 Dec 2018 07:14:12 -0500 Received: from mail.kernel.org ([198.145.29.99]:33724 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731196AbeLNMOJ (ORCPT ); Fri, 14 Dec 2018 07:14:09 -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 362A321508; Fri, 14 Dec 2018 12:14:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544789648; bh=n6CocBIX1mXX/LATcA7fAi0TArMs/tpF6AzpVARsu64=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Kn7qrTp5pctLXfqqIJIp1vPBUIXZUyOQFg4aYaexdoLGxrc9loykzwytlHmB9cK6l lkWVBCPIapFmo+6YfiaIZYl0865eCTb8Hl6XFyDb9dq6AXKWncS/ywtYw9GUK6s9+F wEYu4mTsHlaETtEFSJrsb4w0mhiPU8BVylkJTXfQ= 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.4 23/88] USB: omap_udc: fix crashes on probe error and module removal Date: Fri, 14 Dec 2018 12:59:57 +0100 Message-Id: <20181214115704.037531403@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181214115702.151309521@linuxfoundation.org> References: <20181214115702.151309521@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.4-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 b25eac2dcaf8..da1030f69145 100644 --- a/drivers/usb/gadget/udc/omap_udc.c +++ b/drivers/usb/gadget/udc/omap_udc.c @@ -2612,9 +2612,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 @@ -2919,12 +2932,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); @@ -2951,36 +2960,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