From patchwork Tue Sep 26 11:39:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Liu X-Patchwork-Id: 9971789 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 01EA36037F for ; Tue, 26 Sep 2017 11:38:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ECABD28EB4 for ; Tue, 26 Sep 2017 11:38:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E0D3C28EB5; Tue, 26 Sep 2017 11:38:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6691228EB8 for ; Tue, 26 Sep 2017 11:38:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=aaT7YxkNZ4BKpY4ZzqAMq2giQbbFEQxSmFDgtC3iVB4=; b=CeR tGuj/mlq0hJMy/5x6Hjk3Fu6bFBAxaW2ZRz9rtSBn9tEzoxJrZ0QiDLF+KIszoYb33CKTHvK2hEJA L3l7c3zZWgbKBDnhqYl/z6hP+hpZA/l4z6CQPzfXM90DmZPX1G1PdktuM7pDrVZuj2f3geKMlh2XM 1Gag97BGtInLVhH0hiEKfxjiZN7sy0MOlh7u0BpjzvCjOgQMElrItRzzy4XvQYE9ZW8jKAAvpkpYy Yz1cBB9RxmTbyRfYJAbLJuYSHbHDf4w/5RWgzouoSaf/xet3X6Ia0Xte4/lycN9kA6Z0rfMzMoVIe KIYm+QVofCg8l+wsUYeLLvv6cvRhbZg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dwoBm-00013K-6Z; Tue, 26 Sep 2017 11:38:10 +0000 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dwoBi-0000vo-0l for linux-arm-kernel@lists.infradead.org; Tue, 26 Sep 2017 11:38:07 +0000 Received: by mail-pg0-x244.google.com with SMTP id u18so6623381pgo.1 for ; Tue, 26 Sep 2017 04:37:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=UahNrmFYggl45J83VTRjB8gG5eD2bIFOHSf1ZFj4zrM=; b=cxXC6O6hnHoU7vKPnnGSdcOq3hCUjM7dH5ZKmxUL26Yg4SvTBbXZJudCWGn7lY25I6 7yrNam52IioHN8ZQ+ifU9un6Y/So+Oirqec0xy2khJKRc99BZfXTHyX1PgKE+XibPwGX uJFg9sDlOIbbA01KravpKDljfECdMY08KAJVcmyjSMD/rR/2y+MUEa01Rq45ZpCPo2+x UEkzkePju9jzEBYlBlyutXOF5LuksCDnZgfNSm6ty+uMtQUb7dHQZLcg/O4uYu2BPvMD zrAjN31XyniMLeDS1/LPMsAKzXJsEauxaxrzSw1r8f3KqGKFC+TtOvAr4MmcBrIMKSiB 4A8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=UahNrmFYggl45J83VTRjB8gG5eD2bIFOHSf1ZFj4zrM=; b=G8tu/tnxjR3TuypoCGGdcQ9MCQ6ieULE+7Ug+3PcQmZYGhuiC1WrwyIQ6bFwmL0kzi pkMzbHNX0ht+viVTXp3A/+2X08lc31RaF7uoNignyOM2s56HBBBDOfGr1RPTutLjiP7H 9NwW4+vNYw+fTzPmYVvh8zvPF4JfWlx7lTl0bRGj023RLmmLoUx+MwJbZoCGDUGlTIRK iPmuqmI+4YWidoTWUezjc2m2ENnhnTa34ATX4EE4fUjiikGo2feAPC4gyfzOMWV1RcI/ DYHbg/oQZX4WV8W5cvnbQItfMWZMsVqH/xGGD4WIMhQoWeFLVOwCYesu6yWSs2nb4DYh hdcQ== X-Gm-Message-State: AHPjjUiE7szAGS+MqqBm1LwUcHUhjUbL9POAxtzbaNS4cabxECTKTgKT TWwD4XQIazBySQHRqHVdiho= X-Google-Smtp-Source: AOwi7QA/dyjCe5sVHWJkXoeSyucNc6wi9xc1GnVfVebEzTK4ioISLPA1lNzR2t9KUlGAJqhbDVW7vw== X-Received: by 10.99.61.143 with SMTP id k137mr10502847pga.389.1506425865052; Tue, 26 Sep 2017 04:37:45 -0700 (PDT) Received: from 60-242-179-244.static.tpgi.com.au (60-242-179-244.static.tpgi.com.au. [60.242.179.244]) by smtp.gmail.com with ESMTPSA id v2sm15315869pgo.38.2017.09.26.04.37.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Sep 2017 04:37:43 -0700 (PDT) From: Jonathan Liu To: Bin Liu , Greg Kroah-Hartman , Maxime Ripard , Chen-Yu Tsai Subject: [PATCH] usb: musb: sunxi: Explicitly release USB PHY on exit Date: Tue, 26 Sep 2017 21:39:23 +1000 Message-Id: <20170926113923.18181-1-net147@gmail.com> X-Mailer: git-send-email 2.13.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170926_043806_132953_DEADD094 X-CRM114-Status: GOOD ( 11.69 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-sunxi@googlegroups.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Jonathan Liu MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This fixes a kernel oops when unloading the driver due to usb_put_phy being called after usb_phy_generic_unregister when the device is detached. Calling usb_phy_generic_unregister causes x->dev->driver to be NULL in usb_put_phy and results in a NULL pointer dereference. As we are now explicitly managing the lifetime of usb_phy, devm_usb_get_phy is changed to usb_get_phy and we call usb_put_phy in the probe error path. Cc: stable@vger.kernel.org # v4.3+ Signed-off-by: Jonathan Liu --- drivers/usb/musb/sunxi.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/usb/musb/sunxi.c b/drivers/usb/musb/sunxi.c index c9a09b5bb6e5..8eed61042103 100644 --- a/drivers/usb/musb/sunxi.c +++ b/drivers/usb/musb/sunxi.c @@ -297,6 +297,8 @@ static int sunxi_musb_exit(struct musb *musb) if (test_bit(SUNXI_MUSB_FL_HAS_SRAM, &glue->flags)) sunxi_sram_release(musb->controller->parent); + usb_put_phy(glue->xceiv); + return 0; } @@ -781,7 +783,7 @@ static int sunxi_musb_probe(struct platform_device *pdev) return PTR_ERR(glue->usb_phy); } - glue->xceiv = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); + glue->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); if (IS_ERR(glue->xceiv)) { ret = PTR_ERR(glue->xceiv); dev_err(&pdev->dev, "Error getting usb-phy %d\n", ret); @@ -803,11 +805,13 @@ static int sunxi_musb_probe(struct platform_device *pdev) if (IS_ERR(glue->musb_pdev)) { ret = PTR_ERR(glue->musb_pdev); dev_err(&pdev->dev, "Error registering musb dev: %d\n", ret); - goto err_unregister_usb_phy; + goto err_put_usb_phy; } return 0; +err_put_usb_phy: + usb_put_phy(glue->xceiv); err_unregister_usb_phy: usb_phy_generic_unregister(glue->usb_phy); return ret;