Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp491687pxb; Wed, 3 Nov 2021 07:33:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyS63PuZW7Vlu1tPr5KPGfrRBTGLX3u5vlYXagqdxywAa09Gaml2cP9uCYehb4Zn4ltAe+B X-Received: by 2002:a17:907:3d88:: with SMTP id he8mr22786897ejc.565.1635950019006; Wed, 03 Nov 2021 07:33:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635950019; cv=none; d=google.com; s=arc-20160816; b=Tm2h9qk4/OomMil2qrCu2cFrdIp4pZPahKHrbFpbTZjCB0gtpUSQOz+Ne8ZKo3kSBi ZHCqMQuphNyOLy6fcX8I0Cr8iSkx50ZihSccQek/R+sEnRCFukA3qO0p6zUWtmYVQFjv GDSe2OmVClVDX8ePFYlhoRRpVlMNaECXxt/kYducBHikt+w7NGu/Igx5Aak6Jxss7IbV Xg6tXBV8+RO7Kxa/igdgu03ykHJuHhgqqZA/FtGQM79ATexF5fncp4ioLdFMGe4ic6jN mOyQdaGTrHiVnJoqbM3plxaWw417S+HiT3dsDKlMI/XKsijvid4j4MXC/IQMTKbj/iPo CPKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=OHVuV2Y/NrdsDeYCdXdUOdLc9LCXFsaPcQM/UDWK8PI=; b=o1YQoc7cqrs6vg9LZeYWS7geTXfp0x8FUV2Cm4Clm5WQphNi0Aw5uiGnLMYa3Zbj+0 JjS59zhv5eLXkGosLlwpFzU8u9X3hFT/IpXeqdKroJYmcXY4wrwGyg9Kg2Im3Zmqh1Uy f4ZEL+XjYICGY291QQQNHkjxeefFdewecJD1/h9eoeSc4BlgOU6FiUK6R9NQImmOqqba iH2oOdnwQmG5KJ+q5ZGfKWWAqptjlRK0afh4HdK6v1//FTG1uu8cuFOAeND5CkWxbtuL dDsJ+CdYxAQci2mCDxzYk81Kr76HzuCetjIQvgF5Pi2UvHAbsvCDHjijzHBN0DF/zFbC xPGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NWZC7exJ; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a23si3515511edy.170.2021.11.03.07.33.14; Wed, 03 Nov 2021 07:33:38 -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=@kernel.org header.s=k20201202 header.b=NWZC7exJ; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231712AbhKCOdi (ORCPT + 99 others); Wed, 3 Nov 2021 10:33:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:42922 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231572AbhKCOdi (ORCPT ); Wed, 3 Nov 2021 10:33:38 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 31E4A61050; Wed, 3 Nov 2021 14:31:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1635949861; bh=N5Mg6vArlWNEiIMvZeF4xSwCRRgbnJ1JR10vTfGkNm0=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=NWZC7exJ3FFlKoQiJ0mpdkryWf6aR/jLrNXkgToN7yyhMmPWDVTYIyH+3zQwxNrUI XxkFWIs1hvS6ciYKWeVYq570sHZFZT0uOwkZWO2fhlxb5oizs8BykhvQ6IKHJ9Le/t LHc7o/OLryb1S9LRR2Sa/8d53J5elP1M0hzjbFYDz1oFnvJmKFEPXk3FEMyw3vpnsF NdN1nwgxk4FhiOS0wuOYEje8t5GTUWkS4bNuqSJSthXftYNJuXFbhZKsKJCRwfCgfM YjuhygGyk3We7uyzYHeRZsRWwNF5soLNqeLLVkg2qcpn7cNZFoZdEUgPiQAFIyl4OQ ucYeeQPB2pSPw== Date: Wed, 3 Nov 2021 09:30:59 -0500 From: Bjorn Helgaas To: Wan Jiabing , Mauro Carvalho Chehab , Rob Herring Cc: Xiaowei Song , Binghui Wang , Lorenzo Pieralisi , Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , Bjorn Helgaas , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, jiabing.wan@qq.com Subject: Re: [PATCH] PCI: kirin: Fix of_node_put() issue in pcie-kirin Message-ID: <20211103143059.GA683503@bhelgaas> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211103062518.25695-1-wanjiabing@vivo.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [+to Mauro, author of code being changed, Rob for "of_pci_get_devfn()" naming question] On Wed, Nov 03, 2021 at 02:25:18AM -0400, Wan Jiabing wrote: > Fix following coccicheck warning: > ./drivers/pci/controller/dwc/pcie-kirin.c:414:2-34: WARNING: Function > for_each_available_child_of_node should have of_node_put() before return. > > Early exits from for_each_available_child_of_node should decrement the > node reference counter. Replace return by goto here. > > Signed-off-by: Wan Jiabing > --- > drivers/pci/controller/dwc/pcie-kirin.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/pci/controller/dwc/pcie-kirin.c b/drivers/pci/controller/dwc/pcie-kirin.c > index 06017e826832..23a2c076ce53 100644 > --- a/drivers/pci/controller/dwc/pcie-kirin.c > +++ b/drivers/pci/controller/dwc/pcie-kirin.c > @@ -422,7 +422,8 @@ static int kirin_pcie_parse_port(struct kirin_pcie *pcie, > pcie->num_slots++; > if (pcie->num_slots > MAX_PCI_SLOTS) { > dev_err(dev, "Too many PCI slots!\n"); > - return -EINVAL; > + ret = -EINVAL; > + goto put_node; > } > > ret = of_pci_get_devfn(child); This is a change to the code added here: https://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git/commit/?id=31bd24f0cfe0 This fix looks right to me; all the other early exits from the inner loop drop the "child" reference. But this is a nested loop and the *outer* loop also increments refcounts, and I don't see that outer loop reference on "parent" being dropped at all: for_each_available_child_of_node(node, parent) { for_each_available_child_of_node(parent, child) { ... if (error) goto put_node; } } put_node: of_node_put(child); The "of_pci_get_devfn()" immediately after is unrelated, but possibly a confusing name. "Get" often suggests a reference count being increased, but that's not the case with of_pci_get_devfn(). I want to fix this before sending a pull request to Linus, and I can easily squash it into a local branch, but I need an ack from Mauro that this patch is correct and also a fix or explanation for the outer loop reference situation. Bjorn