Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp91951pxb; Mon, 13 Sep 2021 13:51:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+ZpHCRphaGWZeq/S/1IYkG+NQV3rEEjZ/bT17dlN6UJbobK2p0l8Ms+F7H8xqXadvZR0f X-Received: by 2002:a17:906:38ce:: with SMTP id r14mr14762589ejd.268.1631566285251; Mon, 13 Sep 2021 13:51:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631566285; cv=none; d=google.com; s=arc-20160816; b=OZdzUGGlXhKiL6lVZ6/M/lDptuWsmGID0HFABFFbgIXm/HON+YaKqUlaLe0yrf6mkP G1XOv2vRZ6l8RiUHoWk5w6z28yW4epGvV6sEAK9lZLyKppM7eOp8+YT4nWoCFwMrOWti dNOUukYrQwub6G50cpS1tgQr8DytGWn91J9e2XGVxMH48hQlYNQSBEABLxpNYIp2rq45 cN6gmkx9Iv8WP8AV/ctLIbwNsci+bXBpgAXJaiQDdSoZ+ITUT6GksC8U4ZI4rnW2NoI9 1nveKJ0A1hmSeRzEZuACHKP9cM+IgEnTAyJpEVu30euqdsBBENPBTtu4pklk93Qf5rRW S+lA== 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=zHxdYP/GRnBOAmGAZM/v5fCNabgj6nJK8rDce8ZHtui0BJ/usvvyIaZ5LIOReKLqT6 tQHemO/OYVW4YXWOFnUEh3lNOk4CRAeEZR80kVZCElJPyrF+S+OhQt8W43+HO8H6GkU8 2byg5j8qZt9iwffjeulBaSIWD8zUrmAvS2kPzaJh+Pk0Ijued1xBs7wlVAvGslmEAbpM lRQpRttMa4boUSS1tumg7J0ELhmhbb97YVMpn47V0VmDzDNapQrrp1sZHiz2E+xwKrRq 24Q+S2SuqTRYN8BpinWryWCJZ3PtvBby9hI0Q52vZRJ5WcA+vVP9plSIgyIbVttBHeRR 4n0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KZ4fsa89; 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 s6si5099555edd.0.2021.09.13.13.50.44; Mon, 13 Sep 2021 13:51:25 -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=KZ4fsa89; 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 S244379AbhIMNtW (ORCPT + 99 others); Mon, 13 Sep 2021 09:49:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:51782 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243677AbhIMNov (ORCPT ); Mon, 13 Sep 2021 09:44:51 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2FD5E61440; Mon, 13 Sep 2021 13:31:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631539874; bh=g5bvzzsZ30AzMLtzWBmROfQKl3rddEjPsLLezYEkHdw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KZ4fsa89q9RMdBjnl97PdjD/WcyayN1vxk1AAhLFj7DSvGRXmtS1yevWJT/2Sqdw1 fbqh0SEpdUyo33dyKk52jw1mRgSCu1vHjkzWrNFLlT1d0XHNXvb277akYKb8fT4Ofn iG2EKxMNPFaVYgnTVYGTGh5w7ryeXapy2b5mb784= 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.10 195/236] usb: bdc: Fix a resource leak in the error handling path of bdc_probe() Date: Mon, 13 Sep 2021 15:15:00 +0200 Message-Id: <20210913131107.010324831@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131100.316353015@linuxfoundation.org> References: <20210913131100.316353015@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