Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1695923pxb; Thu, 4 Nov 2021 06:58:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+OkUhnkEYDh+D+boTPHAoAD63411nh/rZpl9tOqduySkmQtKGzOqmdWo/RvWt98hpqY3O X-Received: by 2002:a92:c248:: with SMTP id k8mr14846394ilo.192.1636034309753; Thu, 04 Nov 2021 06:58:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1636034309; cv=none; d=google.com; s=arc-20160816; b=yzWAyG3GlsdMKeBsoocDZA1WbchfXbvMLDCbD++Jewm+ngXSb7YSSzWbELbddXQlQF Sw4STL+o7iD83fWoZtzD3GOox8nXhHinVGktkLK28l/OgJrLVA1HKaJZgUu4lHwk/ooO DVCRRH6QIhrv3o+sy/UQO3/+qDdsCjbwXW/BISosXN9SzCFaggr0u6pzbimK09cpnVSV vyj6XcGdpfal0QXwDtHAbFL1BD84Rq1jC+D5jRAE80x6j2MqmkKs7DykdZZb1JpfTv+O Wv0rPjO+oa8NhYKtxI2CjgzZcXr/xUya7FORQs5owsO46jq2Nhil/ms48TDSeHnmR6b2 V7oA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=ki5K/GnHDQQs0Tc+Gvg1TXEXQ9gRGhRc/zLqm6mx3nE=; b=fdpsY48dAwRiO2ATERDtPTbW/8ND0Cs8kRMC1QpwjbM4woinqo0xJNI4/GE5unWjna n9MtFTIFIAcnmubFssD6xHzmaEwID3M91QWyObGwqmcTKy/0RnVHW2uf++E06Rp5XC77 HNF0DVmEm6rx5wHytJkILk6Kzbwn32l6fgQ8zZm0eNqo1hlagP7aGhoy1zlOdptxOft7 6i3vVhgyuHbIb7s31TpOOCCyOUZqxG9IznpktSyZP88SMGAD6eAiV9oloqaE1QH4+ww2 awuBmFj3dlI4bXyrdNI1lriIQhZ/GWSukS3QAL3Zohe6dYOkF7NC6M3bJks7Vl3EM8gU d8RA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=I5QDAAVg; 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 f14si7718723ila.81.2021.11.04.06.58.14; Thu, 04 Nov 2021 06:58:29 -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=I5QDAAVg; 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 S231182AbhKDN7m (ORCPT + 99 others); Thu, 4 Nov 2021 09:59:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:42164 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229505AbhKDN7m (ORCPT ); Thu, 4 Nov 2021 09:59:42 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0C8E060EBD; Thu, 4 Nov 2021 13:57:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636034224; bh=LmRim0t3JU43qMKfrhS3HrTRGgWYpquyItL1o78EZ7Y=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=I5QDAAVg/RBM1psXeBWNaVB41292EQwLnaZJjzwdUp4K4EU02+2rSfZUyFH0CCnqb 0rAG77sB/pLXdYZCtFZAX8KfqdCJLVVXJfkfpZ3Ojooqv8fxADGldBFpT3QAmwdFHN I2sddnAts5Zw1x0Lc8iyDFgpgYZqH6mKc4IIdJn2cU8+pk3ZqJWrCSivX3bQr1j6DI dZr3/sckDrhExp1S/daJPneBZFLhPHlqNTge162qnVkP51KOrh5F9YujznYKYs7KWo rtVWexHgELkd1sTEIELiimOA09V4iTfWicofrAvMIW4G9ZdxTwrVnw15DywC6ivKjv s8fvCxLDC/73g== Received: by mail-ed1-f53.google.com with SMTP id c8so5029356ede.13; Thu, 04 Nov 2021 06:57:03 -0700 (PDT) X-Gm-Message-State: AOAM530cEYniUZwGNBCugt4j/GYrNpvr0qHVXehcDFx8JSCOvpu0l376 8WmtILZ9jGquM+U5Cwyr7uRiP+163NdDVvJ/Tg== X-Received: by 2002:aa7:dc13:: with SMTP id b19mr54689320edu.145.1636034220156; Thu, 04 Nov 2021 06:57:00 -0700 (PDT) MIME-Version: 1.0 References: <20211103062518.25695-1-wanjiabing@vivo.com> <20211103143059.GA683503@bhelgaas> In-Reply-To: <20211103143059.GA683503@bhelgaas> From: Rob Herring Date: Thu, 4 Nov 2021 08:56:48 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] PCI: kirin: Fix of_node_put() issue in pcie-kirin To: Bjorn Helgaas Cc: Wan Jiabing , Mauro Carvalho Chehab , Xiaowei Song , Binghui Wang , Lorenzo Pieralisi , =?UTF-8?Q?Krzysztof_Wilczy=C5=84ski?= , Bjorn Helgaas , PCI , "linux-kernel@vger.kernel.org" , jiabing.wan@qq.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 3, 2021 at 9:31 AM Bjorn Helgaas wrote: > > [+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); Indeed. There should be a put on the parent. This whole function is less than ideal as it assumes the board has 2 levels of PCI nodes. This might be another (like brcmstb thread) place to use .add_bus(). But that's a problem for another day. > 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 guess you have to know that only nodes are refcounted and property functions never are. There's also of_pci_get_max_link_speed() and of_get_pci_domain_nr(). Rob