Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp221009pxb; Mon, 13 Sep 2021 17:31:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxOhQEPB8IMWXWqeOeyGakTUi33EpmfxfIStFFfMxGjd6XBDlVCWcxAZKzrbnlGkrGQOM8L X-Received: by 2002:aa7:d459:: with SMTP id q25mr16153739edr.62.1631579488712; Mon, 13 Sep 2021 17:31:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631579488; cv=none; d=google.com; s=arc-20160816; b=dxmj25rjvlISYhQgJqXUnrHM2a8q7tnmH1icWqA8A/rJ3cgC7x0cFohLehE2B2Fe6R yNI0HAy3MsXx5KUWxSdQqD2JsvGm318rD82Bp76zRCMZNba8sLweZ3W5szM8Yl7CtETu Doh6qUGl/J7iMeqn8nc79yN2qfDpKhwdcQH7c8agJNQ8pqxkL7JqT54T4sEi6Tx+JsKZ uh0OmA5S3A0IiCixi2RcxasVuGhvXy9Bq64dDmHisAMNsgsA003eWILsTufm/6Lg2VRL s2fLTil3nsQY4t5AbdnTYgdRDzzc/VK+65WuzAi3YoYalI5HeSLE+q5P189r8JZpt+RV pkAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6bhFkcYdxyc6X6SyWMRyQIAK9ZuLJlssYrvyu+9vcJk=; b=AaCmphpnooRkj5pCnEuk3CE+JchoVbcW6yC2ch/6o7F92IYBVL31LoeuIy8j8KXQu9 k4PCfC3x8Qbwdy0H6XRrixV5LtrtpiR/2PIPe8p5VJke23DMWNsgBksCQSzCsGuYvoqk 35EeGyZuvXC8O2PBVEiXsv83N4oX/h56F1b74Hd3T+67CzdYvrpbp0c3Jl7B+qF1TGya 1W5Lw1F0TpQHfVomOtJoi9IuurzpqO839I3WwxeiNmPkUYVtm4lLddaeYS63usGEqMfv rhajLTq4jVUdqL/a8KTpOtZP1vXVgeYbJBQaXusO37xIH4qV9gKPuBG5bX7A6pVPZMxq CluA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1MSJaY24; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i10si10945829ejd.745.2021.09.13.17.31.05; Mon, 13 Sep 2021 17:31:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1MSJaY24; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244562AbhIMOTA (ORCPT + 99 others); Mon, 13 Sep 2021 10:19:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:34312 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344876AbhIMOOo (ORCPT ); Mon, 13 Sep 2021 10:14:44 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 69356610E6; Mon, 13 Sep 2021 13:43:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631540625; bh=g5bvzzsZ30AzMLtzWBmROfQKl3rddEjPsLLezYEkHdw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1MSJaY244PuEXWdGlo5GTE31yR/9MWeZBDrlCIGwtGlChDPGc/KLcw9CSMQKaDy9p wBH6bxyqEr7yK2+DjaV1HoXZUT2wVFttj1OfjpnWEgdblCXRTKwlfe9kqKl6kCRRrA 3I5hIOjMKTx2B0dbShnai7NLZZzzNNVt3Upcr2CA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Florian Fainelli , Christophe JAILLET , Sasha Levin Subject: [PATCH 5.13 236/300] usb: bdc: Fix a resource leak in the error handling path of bdc_probe() Date: Mon, 13 Sep 2021 15:14:57 +0200 Message-Id: <20210913131117.328610897@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131109.253835823@linuxfoundation.org> References: <20210913131109.253835823@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christophe JAILLET [ Upstream commit 6f15a2a09cecb7a2faba4a75bbd101f6f962294b ] If an error occurs after a successful 'clk_prepare_enable()' call, it must be undone by a corresponding 'clk_disable_unprepare()' call. This call is already present in the remove function. Add this call in the error handling path and reorder the code so that the 'clk_prepare_enable()' call happens later in the function. The goal is to have as much managed resources functions as possible before the 'clk_prepare_enable()' call in order to keep the error handling path simple. While at it, remove the now unneeded 'clk' variable. Fixes: c87dca047849 ("usb: bdc: Add clock enable for new chips with a separate BDC clock") Acked-by: Florian Fainelli Signed-off-by: Christophe JAILLET Link: https://lore.kernel.org/r/f8a4a6897deb0c8cb2e576580790303550f15fcd.1629314734.git.christophe.jaillet@wanadoo.fr Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/gadget/udc/bdc/bdc_core.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/drivers/usb/gadget/udc/bdc/bdc_core.c b/drivers/usb/gadget/udc/bdc/bdc_core.c index 251db57e51fa..fa1a3908ec3b 100644 --- a/drivers/usb/gadget/udc/bdc/bdc_core.c +++ b/drivers/usb/gadget/udc/bdc/bdc_core.c @@ -488,27 +488,14 @@ static int bdc_probe(struct platform_device *pdev) int irq; u32 temp; struct device *dev = &pdev->dev; - struct clk *clk; int phy_num; dev_dbg(dev, "%s()\n", __func__); - clk = devm_clk_get_optional(dev, "sw_usbd"); - if (IS_ERR(clk)) - return PTR_ERR(clk); - - ret = clk_prepare_enable(clk); - if (ret) { - dev_err(dev, "could not enable clock\n"); - return ret; - } - bdc = devm_kzalloc(dev, sizeof(*bdc), GFP_KERNEL); if (!bdc) return -ENOMEM; - bdc->clk = clk; - bdc->regs = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(bdc->regs)) return PTR_ERR(bdc->regs); @@ -545,10 +532,20 @@ static int bdc_probe(struct platform_device *pdev) } } + bdc->clk = devm_clk_get_optional(dev, "sw_usbd"); + if (IS_ERR(bdc->clk)) + return PTR_ERR(bdc->clk); + + ret = clk_prepare_enable(bdc->clk); + if (ret) { + dev_err(dev, "could not enable clock\n"); + return ret; + } + ret = bdc_phy_init(bdc); if (ret) { dev_err(bdc->dev, "BDC phy init failure:%d\n", ret); - return ret; + goto disable_clk; } temp = bdc_readl(bdc->regs, BDC_BDCCAP1); @@ -581,6 +578,8 @@ cleanup: bdc_hw_exit(bdc); phycleanup: bdc_phy_exit(bdc); +disable_clk: + clk_disable_unprepare(bdc->clk); return ret; } -- 2.30.2