Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp4356994rwr; Sun, 30 Apr 2023 05:55:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7MAv8nESqZ793RAy49bU6RXhRq6sIFdfwaBVGF6IP2Iu3c6k30rbDCDP6irBU2BFru/dx1 X-Received: by 2002:a05:6a21:32a2:b0:eb:7d41:a70b with SMTP id yt34-20020a056a2132a200b000eb7d41a70bmr14353037pzb.1.1682859341945; Sun, 30 Apr 2023 05:55:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682859341; cv=none; d=google.com; s=arc-20160816; b=U4TJzQn6d4w8eiqHVH0h1WU5etQd4xUsJ0V1s2b5w8B2eaCUmQT5ftP4cZJ+ZyM53L hsQXtfvBVHtTkTSMJZo0g0+k2TGIIEOXObi/Tet0na9+eVw3R7zb9yL3AM/KG4gTrazW 0y2b12H+9K6YJZ/rsvths7dZpjikTpqgHC5GCRUEezfDPwiVsT27GX51u326PZmsMtYz N9gd8vNwHIW2GsvOOk6NU0DNJcpHG462lQUyVm6vYJUa4XvlgEKTI5SHJl7supyn07iC VSs4T6clqgYAQ4r/vdh/VQUVDVOYrj9jcc1Dmrum7X/I2orxGdshE8V6D7E4g2E/CoAS ZTSA== 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 :message-id:date:subject:cc:to:from; bh=7A9KAxQKpdnXfULQGSPAtFvAgiLTMsmhTs9bNa+jPVk=; b=FZWUc6eyL16pLYsIhd+COhqSdoTbtZA7ZKkm/ZvpdMF4KtQmhAcW/Xp2g9hcoREO/W 775hebyIvxz1Y6lA904LWqzBcox2WGcBYNeYDPkY4sS0VRG/rVcJpCWGr/LRaZOrOcS9 Jtpz49GmeDkbYkWXcold6noaIZ4EfjKkodeKuZDAceaPNMOicQksd0D855orFD4cBSAS o94XutKUJLhhpGfO/y6EY8JK7XkVFLNxxM3cP7ghmNRCFVxoXNUg2v/zugHQPbErurAY 3UKBnVmpk6bcVN5XNDOHG/ABrne/6dXimQS+phQaaJ5i8ai1suINDE9B8Pt6jZVPSunS ZoBg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c24-20020a630d18000000b0051b5c9dd1ffsi26533125pgl.66.2023.04.30.05.55.31; Sun, 30 Apr 2023 05:55:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230294AbjD3MyI (ORCPT + 99 others); Sun, 30 Apr 2023 08:54:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230287AbjD3MyF (ORCPT ); Sun, 30 Apr 2023 08:54:05 -0400 Received: from hust.edu.cn (mail.hust.edu.cn [202.114.0.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 993D1271C; Sun, 30 Apr 2023 05:54:02 -0700 (PDT) Received: from ubuntu.localdomain ([10.12.172.67]) (user=saraday@hust.edu.cn mech=LOGIN bits=0) by mx1.hust.edu.cn with ESMTP id 33UCr6nY027403-33UCr6nZ027403 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Sun, 30 Apr 2023 20:53:11 +0800 From: Ziliang Liao To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Linus Walleij Cc: hust-os-kernel-patches@googlegroups.com, Ziliang Liao , Dongliang Mu , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] bus: qcom-ebi2: use prefix devm for clock resource allocation functions Date: Sun, 30 Apr 2023 20:51:53 +0800 Message-Id: <20230430125154.126863-1-saraday@hust.edu.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-FEAS-AUTH-USER: saraday@hust.edu.cn X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Smatch reports: drivers/bus/qcom-ebi2.c:387 qcom_ebi2_probe() warn: 'ebi2clk' from clk_prepare_enable() not released on lines: 358. drivers/bus/qcom-ebi2.c:387 qcom_ebi2_probe() warn: 'ebi2xclk' from clk_prepare_enabled() not released on lines: 358. The clk_disable_unprepare() is only used to explicitly release resources when the qcom_ebi2_probe() fails, and when executed correctly, it may cause resource leakage due to unknown release time. Replace devm_clk_get() and clk_prepare_enable() with devm_clk_get_enabled() to automatically manage the allocated resources. Fixes: 335a12754808 ("bus: qcom: add EBI2 driver") Signed-off-by: Ziliang Liao Reviewed-by: Dongliang Mu --- The issue is found by static analyzer. The patched code has passed Smatch checker, but remains untested on real device. drivers/bus/qcom-ebi2.c | 35 ++++++++--------------------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/drivers/bus/qcom-ebi2.c b/drivers/bus/qcom-ebi2.c index c1fef1b4bd89..3999e969e1cf 100644 --- a/drivers/bus/qcom-ebi2.c +++ b/drivers/bus/qcom-ebi2.c @@ -303,40 +303,28 @@ static int qcom_ebi2_probe(struct platform_device *pdev) u32 val; int ret; - ebi2xclk = devm_clk_get(dev, "ebi2x"); - if (IS_ERR(ebi2xclk)) + ebi2xclk = devm_clk_get_enabled(dev, "ebi2x"); + if (IS_ERR(ebi2xclk)) { + dev_err(dev, "could not enable EBI2X clk"); return PTR_ERR(ebi2xclk); - - ret = clk_prepare_enable(ebi2xclk); - if (ret) { - dev_err(dev, "could not enable EBI2X clk (%d)\n", ret); - return ret; } - ebi2clk = devm_clk_get(dev, "ebi2"); + ebi2clk = devm_clk_get_enabled(dev, "ebi2"); if (IS_ERR(ebi2clk)) { - ret = PTR_ERR(ebi2clk); - goto err_disable_2x_clk; - } - - ret = clk_prepare_enable(ebi2clk); - if (ret) { - dev_err(dev, "could not enable EBI2 clk\n"); - goto err_disable_2x_clk; + dev_err(dev, "could not enable EBI2 clk"); + return PTR_ERR(ebi2clk); } res = platform_get_resource(pdev, IORESOURCE_MEM, 0); ebi2_base = devm_ioremap_resource(dev, res); if (IS_ERR(ebi2_base)) { - ret = PTR_ERR(ebi2_base); - goto err_disable_clk; + return PTR_ERR(ebi2_base); } res = platform_get_resource(pdev, IORESOURCE_MEM, 1); ebi2_xmem = devm_ioremap_resource(dev, res); if (IS_ERR(ebi2_xmem)) { - ret = PTR_ERR(ebi2_xmem); - goto err_disable_clk; + return PTR_ERR(ebi2_xmem); } /* Allegedly this turns the power save mode off */ @@ -378,13 +366,6 @@ static int qcom_ebi2_probe(struct platform_device *pdev) if (have_children) return of_platform_default_populate(np, NULL, dev); return 0; - -err_disable_clk: - clk_disable_unprepare(ebi2clk); -err_disable_2x_clk: - clk_disable_unprepare(ebi2xclk); - - return ret; } static const struct of_device_id qcom_ebi2_of_match[] = { -- 2.25.1