[PATCH 0/6] soc: qcom: use scoped device node handling to simplify error paths
Use cleanup.h/scope on device nodes to get rid of of_node_put(). Code is a bit simpler.
Best regards, Krzysztof
--- Krzysztof Kozlowski (6): soc: qcom: apr: simplify with scoped for each OF child loop soc: qcom: aoss: simplify with scoped for each OF child loop soc: qcom: ice: use scoped device node handling to simplify error paths soc: qcom: ocmem: use scoped device node handling to simplify error paths soc: qcom: pbs: use scoped device node handling to simplify error paths soc: qcom: smp2p: use scoped device node handling to simplify error paths
drivers/soc/qcom/apr.c | 5 +---- drivers/soc/qcom/ice.c | 14 +++++--------- drivers/soc/qcom/ocmem.c | 7 ++----- drivers/soc/qcom/qcom-pbs.c | 16 ++++++---------- drivers/soc/qcom/qcom_aoss.c | 8 +++----- drivers/soc/qcom/smp2p.c | 16 ++++------------ 6 files changed, 21 insertions(+), 45 deletions(-) --- base-commit: d54f33dafd9e93367ffaf95318ed371138a6c8c0 change-id: 20240813-b4-cleanup-h-of-node-put-other-7e9c7128abe4
Best regards,
Use scoped for_each_child_of_node_scoped() when iterating over device nodes to make code a bit simpler.
Signed-off-by: Krzysztof Kozlowski krzysztof.kozlowski@linaro.org --- drivers/soc/qcom/apr.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/drivers/soc/qcom/apr.c b/drivers/soc/qcom/apr.c index 4fbff3a890e2..a956c407ce03 100644 --- a/drivers/soc/qcom/apr.c +++ b/drivers/soc/qcom/apr.c @@ -485,11 +485,10 @@ static int of_apr_add_pd_lookups(struct device *dev) { const char *service_name, *service_path; struct packet_router *apr = dev_get_drvdata(dev); - struct device_node *node; struct pdr_service *pds; int ret;
- for_each_child_of_node(dev->of_node, node) { + for_each_child_of_node_scoped(dev->of_node, node) { ret = of_property_read_string_index(node, "qcom,protection-domain", 0, &service_name); if (ret < 0) @@ -499,14 +498,12 @@ static int of_apr_add_pd_lookups(struct device *dev) 1, &service_path); if (ret < 0) { dev_err(dev, "pdr service path missing: %d\n", ret); - of_node_put(node); return ret; }
pds = pdr_add_lookup(apr->pdr, service_name, service_path); if (IS_ERR(pds) && PTR_ERR(pds) != -EALREADY) { dev_err(dev, "pdr add lookup failed: %ld\n", PTR_ERR(pds)); - of_node_put(node); return PTR_ERR(pds); } }
Use scoped for_each_available_child_of_node_scoped() when iterating over device nodes to make code a bit simpler.
Signed-off-by: Krzysztof Kozlowski krzysztof.kozlowski@linaro.org --- drivers/soc/qcom/qcom_aoss.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/soc/qcom/qcom_aoss.c b/drivers/soc/qcom/qcom_aoss.c index ca2f6b7629ce..60af26667bce 100644 --- a/drivers/soc/qcom/qcom_aoss.c +++ b/drivers/soc/qcom/qcom_aoss.c @@ -394,7 +394,7 @@ static int qmp_cooling_device_add(struct qmp *qmp,
static int qmp_cooling_devices_register(struct qmp *qmp) { - struct device_node *np, *child; + struct device_node *np; int count = 0; int ret;
@@ -407,15 +407,13 @@ static int qmp_cooling_devices_register(struct qmp *qmp) if (!qmp->cooling_devs) return -ENOMEM;
- for_each_available_child_of_node(np, child) { + for_each_available_child_of_node_scoped(np, child) { if (!of_property_present(child, "#cooling-cells")) continue; ret = qmp_cooling_device_add(qmp, &qmp->cooling_devs[count++], child); - if (ret) { - of_node_put(child); + if (ret) goto unroll; - } }
if (!count)
Obtain the device node reference with scoped/cleanup.h to reduce error handling and make the code a bit simpler.
Signed-off-by: Krzysztof Kozlowski krzysztof.kozlowski@linaro.org --- drivers/soc/qcom/ice.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/drivers/soc/qcom/ice.c b/drivers/soc/qcom/ice.c index fbab7fe5c652..50be7a9274a1 100644 --- a/drivers/soc/qcom/ice.c +++ b/drivers/soc/qcom/ice.c @@ -8,6 +8,7 @@ */
#include <linux/bitfield.h> +#include <linux/cleanup.h> #include <linux/clk.h> #include <linux/delay.h> #include <linux/iopoll.h> @@ -265,7 +266,6 @@ struct qcom_ice *of_qcom_ice_get(struct device *dev) { struct platform_device *pdev = to_platform_device(dev); struct qcom_ice *ice; - struct device_node *node; struct resource *res; void __iomem *base;
@@ -292,15 +292,15 @@ struct qcom_ice *of_qcom_ice_get(struct device *dev) * (legacy DT binding), then it must at least provide a phandle * to the ICE devicetree node, otherwise ICE is not supported. */ - node = of_parse_phandle(dev->of_node, "qcom,ice", 0); + struct device_node *node __free(device_node) = of_parse_phandle(dev->of_node, + "qcom,ice", 0); if (!node) return NULL;
pdev = of_find_device_by_node(node); if (!pdev) { dev_err(dev, "Cannot find device node %s\n", node->name); - ice = ERR_PTR(-EPROBE_DEFER); - goto out; + return ERR_PTR(-EPROBE_DEFER); }
ice = platform_get_drvdata(pdev); @@ -308,8 +308,7 @@ struct qcom_ice *of_qcom_ice_get(struct device *dev) dev_err(dev, "Cannot get ice instance from %s\n", dev_name(&pdev->dev)); platform_device_put(pdev); - ice = ERR_PTR(-EPROBE_DEFER); - goto out; + return ERR_PTR(-EPROBE_DEFER); }
ice->link = device_link_add(dev, &pdev->dev, DL_FLAG_AUTOREMOVE_SUPPLIER); @@ -321,9 +320,6 @@ struct qcom_ice *of_qcom_ice_get(struct device *dev) ice = ERR_PTR(-EINVAL); }
-out: - of_node_put(node); - return ice; } EXPORT_SYMBOL_GPL(of_qcom_ice_get);
Obtain the device node reference with scoped/cleanup.h to reduce error handling and make the code a bit simpler.
Signed-off-by: Krzysztof Kozlowski krzysztof.kozlowski@linaro.org --- drivers/soc/qcom/ocmem.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/drivers/soc/qcom/ocmem.c b/drivers/soc/qcom/ocmem.c index 6b6dd80cbc0f..ff8df7d75d6b 100644 --- a/drivers/soc/qcom/ocmem.c +++ b/drivers/soc/qcom/ocmem.c @@ -186,23 +186,20 @@ static void update_range(struct ocmem *ocmem, struct ocmem_buf *buf, struct ocmem *of_get_ocmem(struct device *dev) { struct platform_device *pdev; - struct device_node *devnode; struct ocmem *ocmem;
- devnode = of_parse_phandle(dev->of_node, "sram", 0); + struct device_node *devnode __free(device_node) = of_parse_phandle(dev->of_node, + "sram", 0); if (!devnode || !devnode->parent) { dev_err(dev, "Cannot look up sram phandle\n"); - of_node_put(devnode); return ERR_PTR(-ENODEV); }
pdev = of_find_device_by_node(devnode->parent); if (!pdev) { dev_err(dev, "Cannot find device node %s\n", devnode->name); - of_node_put(devnode); return ERR_PTR(-EPROBE_DEFER); } - of_node_put(devnode);
ocmem = platform_get_drvdata(pdev); if (!ocmem) {
Obtain the device node reference with scoped/cleanup.h to reduce error handling and make the code a bit simpler.
Signed-off-by: Krzysztof Kozlowski krzysztof.kozlowski@linaro.org --- drivers/soc/qcom/qcom-pbs.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/drivers/soc/qcom/qcom-pbs.c b/drivers/soc/qcom/qcom-pbs.c index 6af49b5060e5..77a70d3d0d0b 100644 --- a/drivers/soc/qcom/qcom-pbs.c +++ b/drivers/soc/qcom/qcom-pbs.c @@ -3,6 +3,7 @@ * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved. */
+#include <linux/cleanup.h> #include <linux/delay.h> #include <linux/err.h> #include <linux/module.h> @@ -148,11 +149,11 @@ EXPORT_SYMBOL_GPL(qcom_pbs_trigger_event); */ struct pbs_dev *get_pbs_client_device(struct device *dev) { - struct device_node *pbs_dev_node; struct platform_device *pdev; struct pbs_dev *pbs;
- pbs_dev_node = of_parse_phandle(dev->of_node, "qcom,pbs", 0); + struct device_node *pbs_dev_node __free(device_node) = of_parse_phandle(dev->of_node, + "qcom,pbs", 0); if (!pbs_dev_node) { dev_err(dev, "Missing qcom,pbs property\n"); return ERR_PTR(-ENODEV); @@ -161,28 +162,23 @@ struct pbs_dev *get_pbs_client_device(struct device *dev) pdev = of_find_device_by_node(pbs_dev_node); if (!pdev) { dev_err(dev, "Unable to find PBS dev_node\n"); - pbs = ERR_PTR(-EPROBE_DEFER); - goto out; + return ERR_PTR(-EPROBE_DEFER); }
pbs = platform_get_drvdata(pdev); if (!pbs) { dev_err(dev, "Cannot get pbs instance from %s\n", dev_name(&pdev->dev)); platform_device_put(pdev); - pbs = ERR_PTR(-EPROBE_DEFER); - goto out; + return ERR_PTR(-EPROBE_DEFER); }
pbs->link = device_link_add(dev, &pdev->dev, DL_FLAG_AUTOREMOVE_SUPPLIER); if (!pbs->link) { dev_err(&pdev->dev, "Failed to create device link to consumer %s\n", dev_name(dev)); platform_device_put(pdev); - pbs = ERR_PTR(-EINVAL); - goto out; + return ERR_PTR(-EINVAL); }
-out: - of_node_put(pbs_dev_node); return pbs; } EXPORT_SYMBOL_GPL(get_pbs_client_device);
Obtain the device node reference with scoped/cleanup.h to reduce error handling and make the code a bit simpler.
Signed-off-by: Krzysztof Kozlowski krzysztof.kozlowski@linaro.org --- drivers/soc/qcom/smp2p.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
diff --git a/drivers/soc/qcom/smp2p.c b/drivers/soc/qcom/smp2p.c index 4aa61b0f11ad..cefcbd61c628 100644 --- a/drivers/soc/qcom/smp2p.c +++ b/drivers/soc/qcom/smp2p.c @@ -539,7 +539,6 @@ static int smp2p_parse_ipc(struct qcom_smp2p *smp2p) static int qcom_smp2p_probe(struct platform_device *pdev) { struct smp2p_entry *entry; - struct device_node *node; struct qcom_smp2p *smp2p; const char *key; int irq; @@ -593,11 +592,10 @@ static int qcom_smp2p_probe(struct platform_device *pdev) if (ret < 0) goto release_mbox;
- for_each_available_child_of_node(pdev->dev.of_node, node) { + for_each_available_child_of_node_scoped(pdev->dev.of_node, node) { entry = devm_kzalloc(&pdev->dev, sizeof(*entry), GFP_KERNEL); if (!entry) { ret = -ENOMEM; - of_node_put(node); goto unwind_interfaces; }
@@ -605,25 +603,19 @@ static int qcom_smp2p_probe(struct platform_device *pdev) spin_lock_init(&entry->lock);
ret = of_property_read_string(node, "qcom,entry-name", &entry->name); - if (ret < 0) { - of_node_put(node); + if (ret < 0) goto unwind_interfaces; - }
if (of_property_read_bool(node, "interrupt-controller")) { ret = qcom_smp2p_inbound_entry(smp2p, entry, node); - if (ret < 0) { - of_node_put(node); + if (ret < 0) goto unwind_interfaces; - }
list_add(&entry->node, &smp2p->inbound); } else { ret = qcom_smp2p_outbound_entry(smp2p, entry, node); - if (ret < 0) { - of_node_put(node); + if (ret < 0) goto unwind_interfaces; - }
list_add(&entry->node, &smp2p->outbound); }
On Tue, 13 Aug 2024 15:09:46 +0200, Krzysztof Kozlowski wrote:
Use cleanup.h/scope on device nodes to get rid of of_node_put(). Code is a bit simpler.
Best regards, Krzysztof
Applied, thanks!
[1/6] soc: qcom: apr: simplify with scoped for each OF child loop commit: 6c26d9c764c62343722d6ea6c9e4c7e65989f634 [2/6] soc: qcom: aoss: simplify with scoped for each OF child loop commit: c50203cbba1573546f115330530d24382fc53f09 [3/6] soc: qcom: ice: use scoped device node handling to simplify error paths commit: 877840f13bcc96e05aca2e1e6cc0f957afb788a4 [4/6] soc: qcom: ocmem: use scoped device node handling to simplify error paths commit: f4c1c19f5c0e5cf2870df91dedc6b40400fd9c8a [5/6] soc: qcom: pbs: use scoped device node handling to simplify error paths commit: a29e97bdc160aaa27187c7be3bcd052af66c027a [6/6] soc: qcom: smp2p: use scoped device node handling to simplify error paths commit: f728778272242c84d36682c0aabbb845195e745d
Best regards,
participants (2)
-
Bjorn Andersson
-
Krzysztof Kozlowski