From patchwork Wed Aug 28 07:38:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "zhangzekun (A)" X-Patchwork-Id: 13780849 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B9CD158A04 for ; Wed, 28 Aug 2024 07:51:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724831511; cv=none; b=V5ta7pm9OwH2pFMhYyRHe4uifOlBVKoe7dowubIhuRZV+dG9n3zsH2udQa/oHMHRcjD9OvqbjoOBVeKBUoBIEiVWgxHuPSwZvt6fXrpZPqnY9U/bHWuA3Jm9R8KFw/6vHc6sxeGb7i1Cea9Nh7rk5i8vfHTTl2KHtj6aIQ9gqmw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724831511; c=relaxed/simple; bh=kgj8GVDnZlWVRCPTBuTw0brAryjVz+5O8NGArmuU4Uw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qAhVOdkphjJsO04p/JyuykHTbTfchWXsJ9ojFH2wIz+CYoBUrMngPPG0hsnhOf+EmCQQE7GEvyAK3Wy2V+DOj/awdqNQuzoFJyF2CrOXJaUMuWSA0lBwJBHxY3OFhdluZVmHWZLBadOU1I8dTuvw3Zzp5umvuzWfMoy8CZFGStc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4WtxS41lJ2zyR4Y; Wed, 28 Aug 2024 15:51:16 +0800 (CST) Received: from kwepemf500003.china.huawei.com (unknown [7.202.181.241]) by mail.maildlp.com (Postfix) with ESMTPS id 6D30918007C; Wed, 28 Aug 2024 15:51:46 +0800 (CST) Received: from huawei.com (10.175.112.208) by kwepemf500003.china.huawei.com (7.202.181.241) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 28 Aug 2024 15:51:45 +0800 From: Zhang Zekun To: , , , , , , , , , , , , , , , CC: Subject: [PATCH 1/5] PCI: kirin: Use helper function for_each_available_child_of_node_scoped() Date: Wed, 28 Aug 2024 15:38:21 +0800 Message-ID: <20240828073825.43072-2-zhangzekun11@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240828073825.43072-1-zhangzekun11@huawei.com> References: <20240828073825.43072-1-zhangzekun11@huawei.com> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemf500003.china.huawei.com (7.202.181.241) for_each_available_child_of_node_scoped() provides a scope-based cleanup functinality to put the device_node automatically, and we don't need to call of_node_put() directly. Let's simplify the code a bit with the use of these functions. Signed-off-by: Zhang Zekun Reviewed-by: Jonathan Cameron --- drivers/pci/controller/dwc/pcie-kirin.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/pci/controller/dwc/pcie-kirin.c b/drivers/pci/controller/dwc/pcie-kirin.c index 0a29136491b8..e9bda1746ca5 100644 --- a/drivers/pci/controller/dwc/pcie-kirin.c +++ b/drivers/pci/controller/dwc/pcie-kirin.c @@ -452,7 +452,7 @@ static long kirin_pcie_get_resource(struct kirin_pcie *kirin_pcie, struct platform_device *pdev) { struct device *dev = &pdev->dev; - struct device_node *child, *node = dev->of_node; + struct device_node *node = dev->of_node; void __iomem *apb_base; int ret; @@ -477,17 +477,13 @@ static long kirin_pcie_get_resource(struct kirin_pcie *kirin_pcie, return ret; /* Parse OF children */ - for_each_available_child_of_node(node, child) { + for_each_available_child_of_node_scoped(node, child) { ret = kirin_pcie_parse_port(kirin_pcie, pdev, child); if (ret) - goto put_node; + return ret; } return 0; - -put_node: - of_node_put(child); - return ret; } static void kirin_pcie_sideband_dbi_w_mode(struct kirin_pcie *kirin_pcie, From patchwork Wed Aug 28 07:38:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "zhangzekun (A)" X-Patchwork-Id: 13780850 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1E2271552EB for ; Wed, 28 Aug 2024 07:51:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724831512; cv=none; b=LeroYcYKungpN899FtJ+MwzfCtrAJz1ZAQgXjW2HAU+Zuh0ul0TEHpNyZqYAue/BaoQk24XCnptxIc5P8F5LrYYdZQBRgGcNcTY9nhBGeS0YyHxyGO7oNqU+S/f5D82AYOWz/3Fp7uPtTAPLXYumVuoTg1KuJtP+x+xKV/dKh9A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724831512; c=relaxed/simple; bh=Nftnqekf4BKkmnvCsFvjvPT5ViVvEdvBKoMh7tkLcrg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kcF2p+O9dTpyYc8SHVE5EtEDgTnmHXtSLil6g4AagtFwqfhowmJtV6UQHirkYVRv88V6rq67ds6w0EW+tp6+qZxmJRE3e3n9by2de3MrBU7/g87KOtAQbu83k7sEo8h+kC56Gg7VYViRHyNtRwyTZqZZMe74K7L1UTeKmQ6BaCs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4WtxQj5jS7zpTtB; Wed, 28 Aug 2024 15:50:05 +0800 (CST) Received: from kwepemf500003.china.huawei.com (unknown [7.202.181.241]) by mail.maildlp.com (Postfix) with ESMTPS id 9AE67180AE6; Wed, 28 Aug 2024 15:51:47 +0800 (CST) Received: from huawei.com (10.175.112.208) by kwepemf500003.china.huawei.com (7.202.181.241) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 28 Aug 2024 15:51:46 +0800 From: Zhang Zekun To: , , , , , , , , , , , , , , , CC: Subject: [PATCH 2/5] PCI: mediatek: Use helper function for_each_available_child_of_node_scoped() Date: Wed, 28 Aug 2024 15:38:22 +0800 Message-ID: <20240828073825.43072-3-zhangzekun11@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240828073825.43072-1-zhangzekun11@huawei.com> References: <20240828073825.43072-1-zhangzekun11@huawei.com> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemf500003.china.huawei.com (7.202.181.241) for_each_available_child_of_node_scoped() provides a scope-based cleanup functinality to put the device_node automatically, and we don't need to call of_node_put() directly. Let's simplify the code a bit with the use of these functions. Signed-off-by: Zhang Zekun Reviewed-by: Jonathan Cameron --- drivers/pci/controller/pcie-mediatek.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c index 9be3cebd862e..d14e8d151c08 100644 --- a/drivers/pci/controller/pcie-mediatek.c +++ b/drivers/pci/controller/pcie-mediatek.c @@ -1042,24 +1042,24 @@ static int mtk_pcie_subsys_powerup(struct mtk_pcie *pcie) static int mtk_pcie_setup(struct mtk_pcie *pcie) { struct device *dev = pcie->dev; - struct device_node *node = dev->of_node, *child; + struct device_node *node = dev->of_node; struct mtk_pcie_port *port, *tmp; int err, slot; slot = of_get_pci_domain_nr(dev->of_node); if (slot < 0) { - for_each_available_child_of_node(node, child) { + for_each_available_child_of_node_scoped(node, child) { err = of_pci_get_devfn(child); if (err < 0) { dev_err(dev, "failed to get devfn: %d\n", err); - goto error_put_node; + return err; } slot = PCI_SLOT(err); err = mtk_pcie_parse_port(pcie, child, slot); if (err) - goto error_put_node; + return err; } } else { err = mtk_pcie_parse_port(pcie, node, slot); @@ -1080,9 +1080,6 @@ static int mtk_pcie_setup(struct mtk_pcie *pcie) mtk_pcie_subsys_powerdown(pcie); return 0; -error_put_node: - of_node_put(child); - return err; } static int mtk_pcie_probe(struct platform_device *pdev) From patchwork Wed Aug 28 07:38:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "zhangzekun (A)" X-Patchwork-Id: 13780851 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E9A581487FE for ; Wed, 28 Aug 2024 07:51:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724831513; cv=none; b=fU/L4ZYNbo+Vh9qsdVXS+MJBvxL/pBE3lPljrR4o2J5M93p+pQYJOJpZuAV6T4QWAce/5ILEqwI6OF+2HmGc46DdQDIriv8iA5OJq8fXSEBAF5dxEbUix176Ac13iprChcykRZPlzJmcptBhbm0r2iRyvrGuALQnyqyGTnCMUGg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724831513; c=relaxed/simple; bh=C0fB222TDeyt/HXLq2P2O13kaWs4e2K2QKPbb51Beck=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Mqwh8ywWg4mDkJ9haWj7AVMjyUco2JE8ysYyjhOOeXSVNxTcm0+i5co9XqVPnjop9d5eoINBmu6fQ8CVtuH5PMSFOHq0CBLZ365AXBkIWUrrAiV7hWfzuspyohBeQyU7EyTT9EFXBvvKy7ChktINCxGitLPBAHd0v1mSsX0Lw70= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4WtxM713d2zQqy6; Wed, 28 Aug 2024 15:46:59 +0800 (CST) Received: from kwepemf500003.china.huawei.com (unknown [7.202.181.241]) by mail.maildlp.com (Postfix) with ESMTPS id C4CF214035E; Wed, 28 Aug 2024 15:51:48 +0800 (CST) Received: from huawei.com (10.175.112.208) by kwepemf500003.china.huawei.com (7.202.181.241) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 28 Aug 2024 15:51:47 +0800 From: Zhang Zekun To: , , , , , , , , , , , , , , , CC: Subject: [PATCH 3/5] PCI: mt7621: Use helper function for_each_available_child_of_node_scoped() Date: Wed, 28 Aug 2024 15:38:23 +0800 Message-ID: <20240828073825.43072-4-zhangzekun11@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240828073825.43072-1-zhangzekun11@huawei.com> References: <20240828073825.43072-1-zhangzekun11@huawei.com> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemf500003.china.huawei.com (7.202.181.241) for_each_available_child_of_node_scoped() provides a scope-based cleanup functinality to put the device_node automatically, and we don't need to call of_node_put() directly. Let's simplify the code a bit with the use of these functions. Signed-off-by: Zhang Zekun Reviewed-by: Sergio Paracuellos Reviewed-by: Jonathan Cameron --- drivers/pci/controller/pcie-mt7621.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/pci/controller/pcie-mt7621.c b/drivers/pci/controller/pcie-mt7621.c index 9b4754a45515..16c3df1c49a1 100644 --- a/drivers/pci/controller/pcie-mt7621.c +++ b/drivers/pci/controller/pcie-mt7621.c @@ -258,19 +258,18 @@ static int mt7621_pcie_parse_dt(struct mt7621_pcie *pcie) { struct device *dev = pcie->dev; struct platform_device *pdev = to_platform_device(dev); - struct device_node *node = dev->of_node, *child; + struct device_node *node = dev->of_node; int err; pcie->base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(pcie->base)) return PTR_ERR(pcie->base); - for_each_available_child_of_node(node, child) { + for_each_available_child_of_node_scoped(node, child) { int slot; err = of_pci_get_devfn(child); if (err < 0) { - of_node_put(child); dev_err(dev, "failed to parse devfn: %d\n", err); return err; } @@ -278,10 +277,8 @@ static int mt7621_pcie_parse_dt(struct mt7621_pcie *pcie) slot = PCI_SLOT(err); err = mt7621_pcie_parse_port(pcie, child, slot); - if (err) { - of_node_put(child); + if (err) return err; - } } return 0; From patchwork Wed Aug 28 07:38:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "zhangzekun (A)" X-Patchwork-Id: 13780852 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 16C8A158A04 for ; Wed, 28 Aug 2024 07:51:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724831513; cv=none; b=Cpk1Y6je+zPN5UEiOAqQ8Hcm1Gqv8ktV1j2a3smipAol5Acl4M1HgaOjA5qDpuWHxCF57ccXjRwAl4sx58em8AQVO/m3HqIJWOgAgLPbmH/4hr3c2ehJTMpc2/uie6JR4nh0mAX6W9rCIsiIJn9cbQppqwKtXRvxZ8AzsSWMApw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724831513; c=relaxed/simple; bh=s/RZ5Op0SHFsFAHxNX9PzxkEk5CdJXWmJoLNQUC8iYo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UDhw3fMK4tvmhJOjoNh0adFMoyu7agH3gqvi6Xje1siUQXV+UH17/4dVEVEhaskI84E5dUM3DLlInk1PLKJ1U3Yys1NUNYIeE5POvxpCcrYagAwJcpNNYazvQqlCcP0uUbzoylwNVG0OtitRw/fZhWoKAUuwwDorz+2W75yOxb0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4WtxM82bMWzQqyv; Wed, 28 Aug 2024 15:47:00 +0800 (CST) Received: from kwepemf500003.china.huawei.com (unknown [7.202.181.241]) by mail.maildlp.com (Postfix) with ESMTPS id 06A4A14035E; Wed, 28 Aug 2024 15:51:50 +0800 (CST) Received: from huawei.com (10.175.112.208) by kwepemf500003.china.huawei.com (7.202.181.241) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 28 Aug 2024 15:51:48 +0800 From: Zhang Zekun To: , , , , , , , , , , , , , , , CC: Subject: [PATCH 4/5] PCI: apple: Use helper function for_each_child_of_node_scoped() Date: Wed, 28 Aug 2024 15:38:24 +0800 Message-ID: <20240828073825.43072-5-zhangzekun11@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240828073825.43072-1-zhangzekun11@huawei.com> References: <20240828073825.43072-1-zhangzekun11@huawei.com> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemf500003.china.huawei.com (7.202.181.241) for_each_child_of_node_scoped() provides a scope-based cleanup functinality to put the device_node automatically, and we don't need to call of_node_put() directly. Let's simplify the code a bit with the use of these functions. Signed-off-by: Zhang Zekun Reviewed-by: Jonathan Cameron --- drivers/pci/controller/pcie-apple.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c index fefab2758a06..f1bd20a64b67 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -764,7 +764,6 @@ static int apple_pcie_init(struct pci_config_window *cfg) { struct device *dev = cfg->parent; struct platform_device *platform = to_platform_device(dev); - struct device_node *of_port; struct apple_pcie *pcie; int ret; @@ -787,11 +786,10 @@ static int apple_pcie_init(struct pci_config_window *cfg) if (ret) return ret; - for_each_child_of_node(dev->of_node, of_port) { + for_each_child_of_node_scoped(dev->of_node, of_port) { ret = apple_pcie_setup_port(pcie, of_port); if (ret) { dev_err(pcie->dev, "Port %pOF setup fail: %d\n", of_port, ret); - of_node_put(of_port); return ret; } } From patchwork Wed Aug 28 07:38:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "zhangzekun (A)" X-Patchwork-Id: 13780853 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A9E9B1487FE for ; Wed, 28 Aug 2024 07:51:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.255 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724831516; cv=none; b=DknzShx4EDL9V31U5oTj752gMwpBoiCfalw7LfVWuZNqGeYew8eqs4Y5RFoIGX8gTDO4LvE1MSa/k+aE0CEw61/kxwA4fa74KaWyZiZZs53WB9DHfpOW9q2hHIrnjUQQ8tozW2XQqIB63F8DrRKpCsfnv+2bE+MZ6Ln0L6Jv+sw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724831516; c=relaxed/simple; bh=QDNIpKluA/Hn6IwbVvn3bv6YH1aHA8guIHFxWtIplno=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qmBIAmCTy4U69NMT5MUO/9K0LIo0fmPHPaOVfm6n9EQlNDLvpbAgQwOiGF+Oz2VPiTS+o6KcBXr812TJ3NOgwD5KUsn4a8uZsy+0efA4JONjYVzFXJq9e4NDxbp8v3vOIVxWFSP2TyEXRGpUvPQzOjlAVz5FqcRewr6vkGOFw6g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.255 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4WtxRq1JRyz16PbW; Wed, 28 Aug 2024 15:51:03 +0800 (CST) Received: from kwepemf500003.china.huawei.com (unknown [7.202.181.241]) by mail.maildlp.com (Postfix) with ESMTPS id 2FC75180105; Wed, 28 Aug 2024 15:51:51 +0800 (CST) Received: from huawei.com (10.175.112.208) by kwepemf500003.china.huawei.com (7.202.181.241) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 28 Aug 2024 15:51:49 +0800 From: Zhang Zekun To: , , , , , , , , , , , , , , , CC: Subject: [PATCH 5/5] PCI: tegra: Use helper function for_each_child_of_node_scoped() Date: Wed, 28 Aug 2024 15:38:25 +0800 Message-ID: <20240828073825.43072-6-zhangzekun11@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240828073825.43072-1-zhangzekun11@huawei.com> References: <20240828073825.43072-1-zhangzekun11@huawei.com> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemf500003.china.huawei.com (7.202.181.241) for_each_child_of_node_scoped() provides a scope-based cleanup functinality to put the device_node automatically, and we don't need to call of_node_put() directly. Let's simplify the code a bit with the use of these functions. Signed-off-by: Zhang Zekun --- drivers/pci/controller/pci-tegra.c | 41 ++++++++++-------------------- 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/drivers/pci/controller/pci-tegra.c b/drivers/pci/controller/pci-tegra.c index d7517c3976e7..f1214b3374da 100644 --- a/drivers/pci/controller/pci-tegra.c +++ b/drivers/pci/controller/pci-tegra.c @@ -2106,14 +2106,14 @@ static int tegra_pcie_get_regulators(struct tegra_pcie *pcie, u32 lane_mask) static int tegra_pcie_parse_dt(struct tegra_pcie *pcie) { struct device *dev = pcie->dev; - struct device_node *np = dev->of_node, *port; + struct device_node *np = dev->of_node; const struct tegra_pcie_soc *soc = pcie->soc; u32 lanes = 0, mask = 0; unsigned int lane = 0; int err; /* parse root ports */ - for_each_child_of_node(np, port) { + for_each_child_of_node_scoped(np, port) { struct tegra_pcie_port *rp; unsigned int index; u32 value; @@ -2122,15 +2122,14 @@ static int tegra_pcie_parse_dt(struct tegra_pcie *pcie) err = of_pci_get_devfn(port); if (err < 0) { dev_err(dev, "failed to parse address: %d\n", err); - goto err_node_put; + return err; } index = PCI_SLOT(err); if (index < 1 || index > soc->num_ports) { dev_err(dev, "invalid port number: %d\n", index); - err = -EINVAL; - goto err_node_put; + return -EINVAL; } index--; @@ -2139,13 +2138,12 @@ static int tegra_pcie_parse_dt(struct tegra_pcie *pcie) if (err < 0) { dev_err(dev, "failed to parse # of lanes: %d\n", err); - goto err_node_put; + return err; } if (value > 16) { dev_err(dev, "invalid # of lanes: %u\n", value); - err = -EINVAL; - goto err_node_put; + return -EINVAL; } lanes |= value << (index << 3); @@ -2159,15 +2157,13 @@ static int tegra_pcie_parse_dt(struct tegra_pcie *pcie) lane += value; rp = devm_kzalloc(dev, sizeof(*rp), GFP_KERNEL); - if (!rp) { - err = -ENOMEM; - goto err_node_put; - } + if (!rp) + return -ENOMEM; err = of_address_to_resource(port, 0, &rp->regs); if (err < 0) { dev_err(dev, "failed to parse address: %d\n", err); - goto err_node_put; + return err; } INIT_LIST_HEAD(&rp->list); @@ -2177,16 +2173,12 @@ static int tegra_pcie_parse_dt(struct tegra_pcie *pcie) rp->np = port; rp->base = devm_pci_remap_cfg_resource(dev, &rp->regs); - if (IS_ERR(rp->base)) { - err = PTR_ERR(rp->base); - goto err_node_put; - } + if (IS_ERR(rp->base)) + return PTR_ERR(rp->base); label = devm_kasprintf(dev, GFP_KERNEL, "pex-reset-%u", index); - if (!label) { - err = -ENOMEM; - goto err_node_put; - } + if (!label) + return -ENOMEM; /* * Returns -ENOENT if reset-gpios property is not populated @@ -2204,8 +2196,7 @@ static int tegra_pcie_parse_dt(struct tegra_pcie *pcie) } else { dev_err(dev, "failed to get reset GPIO: %ld\n", PTR_ERR(rp->reset_gpio)); - err = PTR_ERR(rp->reset_gpio); - goto err_node_put; + return PTR_ERR(rp->reset_gpio); } } @@ -2223,10 +2214,6 @@ static int tegra_pcie_parse_dt(struct tegra_pcie *pcie) return err; return 0; - -err_node_put: - of_node_put(port); - return err; } /*