Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp3955414rwr; Mon, 8 May 2023 00:04:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4bk7KnCH8Vw0UZLmI9Ipv2p6j3S9RhX61p7fvjOJgS8elKpDNE37rT7FdfCeThOlnjkuXR X-Received: by 2002:a17:90a:7801:b0:24e:16aa:48 with SMTP id w1-20020a17090a780100b0024e16aa0048mr9585871pjk.15.1683529494268; Mon, 08 May 2023 00:04:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683529494; cv=none; d=google.com; s=arc-20160816; b=dEkXAax61sfKCVrc1O3JhM2nxcqdt11KHB7h+dcJhwPUBkmHva2vwm1IJgoP8TBLPg q+rKWqP/UZeMxYJ/FswVLmcB9SBxINfYVUdlPVQ3Z6hyMLYLiYsYL6DMrGxjRgqeVLHG VWqwt24Kve/tDBxLkqHN5aGqzQPTbduoqQpWTVITxIgp/kg0znYXNFFomOGeClyaF6nd ICPaVvkvWAf7Bu8bMpx/O8JoGet0nIrbHq/fXkwPfM5A9vQUSzuLM0A0fD5vmh8qr4Im IiE3kGkh6ZPtvfHRdhTrOed/V0CF/SHHjdbs3AeJJwTDjKd286mTQWT0xdG4pETCOZWb 02fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=Ryhq4eaEWmWDYOdIXBNmYtLvCNROHD7rXvSdIVxOm0c=; b=x2O+O/qxDBQ9JDzMwg94clF8RTptr8dUfRjcepPs+08a24Qpz4FM5W5W+CPYzAZIhI 0IDZ6DAo5r//sUSfcgNmJTHsv0/g5n3P9SRsTnNDLshs0e8EYKnNT687IgkyW8ZKWueE xr6dSOWObFPRWQIxeAsgvlCqN+1LHbQQtXEbTPIt8qpeVKQRwSF2o11tDBVOCZPdviQs MQrZ44ltXzJsk8Ovkl4ZYeru6hEuUgCL2Rd0qh7x281ZyboK0n5WI5AlljUoeY8198wb SAs8zIrGAEmkbKOksD5VrWA8MtAI2m/mwGLXrmWaPJFZX+kcQrWlGQ4p/wOJhpkU6ese TADQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=h86uiNgo; 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 x36-20020a17090a6c2700b00233e301c780si12412714pjj.31.2023.05.08.00.04.41; Mon, 08 May 2023 00:04:54 -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; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=h86uiNgo; 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 S231814AbjEHG7t (ORCPT + 99 others); Mon, 8 May 2023 02:59:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233255AbjEHG7g (ORCPT ); Mon, 8 May 2023 02:59:36 -0400 Received: from smtp.smtpout.orange.fr (smtp-13.smtpout.orange.fr [80.12.242.13]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1ACF319D71 for ; Sun, 7 May 2023 23:59:24 -0700 (PDT) Received: from [192.168.1.18] ([86.243.2.178]) by smtp.orange.fr with ESMTPA id vuq3pLWu0unMHvuq3pBwg2; Mon, 08 May 2023 08:59:21 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1683529161; bh=Ryhq4eaEWmWDYOdIXBNmYtLvCNROHD7rXvSdIVxOm0c=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=h86uiNgobj8OHnUlZm8V2grAj3q3ci8iC0qVk46uo5eN377DtEykldpJIuRyDuokr yhrzdNzi2PUnQNxexCNSZFyWLPjMBmZ4Cgn7f48hkrWcnm0CslcYwBOubM2H/jwmMo b8Qait6jaUPATs5S5DicF28oXnVoT3O4mQb1o5YB78gBogK34hzFgYUY5SWXZHEOeq TfkcLwDzYEugRZokteWYZGVkdkv3hNroXMqdwBnAQR/Txg/TgU+cVsKmAKeUoMv+lx BYvGWsp7GzM3KBwCsKdHXpwwyk9AfYsMDZLV3r/e/CqFsjL4cCyGZiO+U75EMCr/OS nIHyjGooJiyTA== X-ME-Helo: [192.168.1.18] X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Mon, 08 May 2023 08:59:21 +0200 X-ME-IP: 86.243.2.178 Message-ID: <430d0357-d10e-db3d-bc82-722b022b519b@wanadoo.fr> Date: Mon, 8 May 2023 08:59:15 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH v3] pci: controller: pci-ftpci100: Release the clock resources Content-Language: fr, en-US To: Junyan Ye , Lorenzo Pieralisi , =?UTF-8?Q?Krzysztof_Wilczy=c5=84ski?= , Rob Herring , Bjorn Helgaas , Wei Yongjun , Linus Walleij , Andrew Murray Cc: hust-os-kernel-patches@googlegroups.com, Dongliang Mu , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org References: <20230508043641.23807-1-yejunyan@hust.edu.cn> From: Christophe JAILLET In-Reply-To: <20230508043641.23807-1-yejunyan@hust.edu.cn> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,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 Le 08/05/2023 à 06:36, Junyan Ye a écrit : > Smatch reported: > 1. drivers/pci/controller/pci-ftpci100.c:526 faraday_pci_probe() warn: > 'clk' from clk_prepare_enable() not released on lines: 442,451,462,478,512,517. > 2. drivers/pci/controller/pci-ftpci100.c:526 faraday_pci_probe() warn: > 'p->bus_clk' from clk_prepare_enable() not released on lines: 451,462,478,512,517. > > The clock resource is obtained by devm_clk_get(), and then > clk_prepare_enable() makes the clock resource ready for use. After that, > clk_disable_unprepare() should be called to release the clock resource > when it is no longer needed. However, while doing some error handling > in faraday_pci_probe(), clk_disable_unprepare() is not called to release > clk and p->bus_clk before returning. These return lines are exactly 442, > 451, 462, 478, 512, 517. > > Fix this warning by replacing devm_clk_get() with devm_clk_get_enabled(), > which is equivalent to devm_clk_get() + clk_prepare_enable(). And with > devm_clk_get_enabled(), the clock will automatically be disabled, > unprepared and freed when the device is unbound from the bus. > > Fixes: b3c433efb8a3 ("PCI: faraday: Fix wrong pointer passed to PTR_ERR()") > Fixes: 2eeb02b28579 ("PCI: faraday: Add clock handling") > Fixes: 783a862563f7 ("PCI: faraday: Use pci_parse_request_of_pci_ranges()") > Fixes: d3c68e0a7e34 ("PCI: faraday: Add Faraday Technology FTPCI100 PCI Host Bridge driver") > Fixes: f1e8bd21e39e ("PCI: faraday: Convert IRQ masking to raw PCI config accessors") > Reviewed-by: Dongliang Mu > Signed-off-by: Junyan Ye > --- > v2 -> v3: Rebase to v6.4-rc1 and modify commit message. > v1 -> v2: Switch from clk_disable_unprepare() to devm_clk_get_enabled() to release the clock. > This issue is found by static analyzer. > > drivers/pci/controller/pci-ftpci100.c | 14 ++------------ > 1 file changed, 2 insertions(+), 12 deletions(-) > > diff --git a/drivers/pci/controller/pci-ftpci100.c b/drivers/pci/controller/pci-ftpci100.c > index ecd3009df586..6e7981d2ed5e 100644 > --- a/drivers/pci/controller/pci-ftpci100.c > +++ b/drivers/pci/controller/pci-ftpci100.c > @@ -429,22 +429,12 @@ static int faraday_pci_probe(struct platform_device *pdev) > p->dev = dev; > > /* Retrieve and enable optional clocks */ Hi, completely unrelated to your patch, but this comments state "optional". The code below seems to make both clocks mandatory. Moreover, a few lines later, we have: if (!IS_ERR(p->bus_clk)) { which seems to say that bus_clk is optional. This was introduced by 2eeb02b28579. Just a guess, but either the comment should be updated, or the code modified. Just my 2c, CJ > - clk = devm_clk_get(dev, "PCLK"); > + clk = devm_clk_get_enabled(dev, "PCLK"); > if (IS_ERR(clk)) > return PTR_ERR(clk); > - ret = clk_prepare_enable(clk); > - if (ret) { > - dev_err(dev, "could not prepare PCLK\n"); > - return ret; > - } > - p->bus_clk = devm_clk_get(dev, "PCICLK"); > + p->bus_clk = devm_clk_get_enabled(dev, "PCICLK"); > if (IS_ERR(p->bus_clk)) > return PTR_ERR(p->bus_clk); > - ret = clk_prepare_enable(p->bus_clk); > - if (ret) { > - dev_err(dev, "could not prepare PCICLK\n"); > - return ret; > - } > > p->base = devm_platform_ioremap_resource(pdev, 0); > if (IS_ERR(p->base))