From: Kousik Sanagavarapu <five231003@gmail.com>
To: Nishanth Menon <nm@ti.com>,
Jonathan Cameron <Jonathan.Cameron@Huawei.com>,
Santosh Shilimkar <ssantosh@kernel.org>,
Nathan Chancellor <nathan@kernel.org>,
Julia Lawall <julia.lawall@inria.fr>
Cc: Shuah Khan <skhan@linuxfoundation.org>,
Javier Carrasco <javier.carrasco.cruz@gmail.com>,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
Kousik Sanagavarapu <five231003@gmail.com>
Subject: [PATCH v3 2/4] soc: ti: pruss: do device_node auto cleanup
Date: Sun, 7 Jul 2024 10:44:17 +0530 [thread overview]
Message-ID: <20240707055341.3656-3-five231003@gmail.com> (raw)
In-Reply-To: <20240707055341.3656-1-five231003@gmail.com>
Use scope based cleanup instead of manual of_node_put() calls, hence
simplifying the handling of error paths at various places.
While at it, use dev_err_probe() instead of dev_err() in all the code
paths touched.
Suggested-by: Julia Lawall <julia.lawall@inria.fr>
Signed-off-by: Kousik Sanagavarapu <five231003@gmail.com>
---
drivers/soc/ti/pruss.c | 91 +++++++++++++++---------------------------
1 file changed, 33 insertions(+), 58 deletions(-)
diff --git a/drivers/soc/ti/pruss.c b/drivers/soc/ti/pruss.c
index a3c55a291b0b..a01eabb0ca26 100644
--- a/drivers/soc/ti/pruss.c
+++ b/drivers/soc/ti/pruss.c
@@ -380,50 +380,42 @@ static int pruss_clk_mux_setup(struct pruss *pruss, struct clk *clk_mux,
static int pruss_clk_init(struct pruss *pruss, struct device_node *cfg_node)
{
- const struct pruss_private_data *data;
- struct device_node *clks_np;
struct device *dev = pruss->dev;
- int ret = 0;
-
- data = of_device_get_match_data(dev);
+ struct device_node *clks_np __free(device_node) =
+ of_get_child_by_name(cfg_node, "clocks");
+ const struct pruss_private_data *data = of_device_get_match_data(dev);
+ int ret;
- clks_np = of_get_child_by_name(cfg_node, "clocks");
- if (!clks_np) {
- dev_err(dev, "%pOF is missing its 'clocks' node\n", cfg_node);
- return -ENODEV;
- }
+ if (!clks_np)
+ return dev_err_probe(dev, -ENODEV,
+ "%pOF is missing its 'clocks' node\n",
+ cfg_node);
if (data && data->has_core_mux_clock) {
ret = pruss_clk_mux_setup(pruss, pruss->core_clk_mux,
"coreclk-mux", clks_np);
- if (ret) {
- dev_err(dev, "failed to setup coreclk-mux\n");
- goto put_clks_node;
- }
+ if (ret)
+ return dev_err_probe(dev, ret,
+ "failed to setup coreclk-mux\n");
}
ret = pruss_clk_mux_setup(pruss, pruss->iep_clk_mux, "iepclk-mux",
clks_np);
- if (ret) {
- dev_err(dev, "failed to setup iepclk-mux\n");
- goto put_clks_node;
- }
-
-put_clks_node:
- of_node_put(clks_np);
+ if (ret)
+ return dev_err_probe(dev, ret, "failed to setup iepclk-mux\n");
- return ret;
+ return 0;
}
static int pruss_of_setup_memories(struct device *dev, struct pruss *pruss)
{
struct device_node *np = dev_of_node(dev);
- struct device_node *child;
+ struct device_node *child __free(device_node) =
+ of_get_child_by_name(np, "memories");
const struct pruss_private_data *data = of_device_get_match_data(dev);
const char *mem_names[PRUSS_MEM_MAX] = { "dram0", "dram1", "shrdram2" };
int i;
- child = of_get_child_by_name(np, "memories");
if (!child)
return dev_err_probe(dev, -ENODEV,
"%pOF is missing its 'memories' node\n",
@@ -442,24 +434,18 @@ static int pruss_of_setup_memories(struct device *dev, struct pruss *pruss)
index = of_property_match_string(child, "reg-names",
mem_names[i]);
- if (index < 0) {
- of_node_put(child);
+ if (index < 0)
return index;
- }
- if (of_address_to_resource(child, index, &res)) {
- of_node_put(child);
+ if (of_address_to_resource(child, index, &res))
return -EINVAL;
- }
pruss->mem_regions[i].va = devm_ioremap(dev, res.start,
resource_size(&res));
- if (!pruss->mem_regions[i].va) {
- of_node_put(child);
+ if (!pruss->mem_regions[i].va)
return dev_err_probe(dev, -ENOMEM,
"failed to parse and map memory resource %d %s\n",
i, mem_names[i]);
- }
pruss->mem_regions[i].pa = res.start;
pruss->mem_regions[i].size = resource_size(&res);
@@ -467,7 +453,6 @@ static int pruss_of_setup_memories(struct device *dev, struct pruss *pruss)
mem_names[i], &pruss->mem_regions[i].pa,
pruss->mem_regions[i].size, pruss->mem_regions[i].va);
}
- of_node_put(child);
return 0;
}
@@ -481,26 +466,21 @@ static struct regmap_config regmap_conf = {
static int pruss_cfg_of_init(struct device *dev, struct pruss *pruss)
{
struct device_node *np = dev_of_node(dev);
- struct device_node *child;
+ struct device_node *child __free(device_node) =
+ of_get_child_by_name(np, "cfg");
struct resource res;
int ret;
- child = of_get_child_by_name(np, "cfg");
- if (!child) {
- dev_err(dev, "%pOF is missing its 'cfg' node\n", child);
- return -ENODEV;
- }
+ if (!child)
+ return dev_err_probe(dev, -ENODEV,
+ "%pOF is missing its 'cfg' node\n", child);
- if (of_address_to_resource(child, 0, &res)) {
- ret = -ENOMEM;
- goto node_put;
- }
+ if (of_address_to_resource(child, 0, &res))
+ return -ENOMEM;
pruss->cfg_base = devm_ioremap(dev, res.start, resource_size(&res));
- if (!pruss->cfg_base) {
- ret = -ENOMEM;
- goto node_put;
- }
+ if (!pruss->cfg_base)
+ return -ENOMEM;
regmap_conf.name = kasprintf(GFP_KERNEL, "%pOFn@%llx", child,
(u64)res.start);
@@ -509,20 +489,15 @@ static int pruss_cfg_of_init(struct device *dev, struct pruss *pruss)
pruss->cfg_regmap = devm_regmap_init_mmio(dev, pruss->cfg_base,
®map_conf);
kfree(regmap_conf.name);
- if (IS_ERR(pruss->cfg_regmap)) {
- dev_err(dev, "regmap_init_mmio failed for cfg, ret = %ld\n",
- PTR_ERR(pruss->cfg_regmap));
- ret = PTR_ERR(pruss->cfg_regmap);
- goto node_put;
- }
+ if (IS_ERR(pruss->cfg_regmap))
+ return dev_err_probe(dev, PTR_ERR(pruss->cfg_regmap),
+ "regmap_init_mmio failed for cfg\n");
ret = pruss_clk_init(pruss, child);
if (ret)
- dev_err(dev, "pruss_clk_init failed, ret = %d\n", ret);
+ return dev_err_probe(dev, ret, "pruss_clk_init failed\n");
-node_put:
- of_node_put(child);
- return ret;
+ return 0;
}
static int pruss_probe(struct platform_device *pdev)
--
2.45.2.561.g66ac6e4bcd
next prev parent reply other threads:[~2024-07-07 5:54 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-07 5:14 [PATCH v3 0/4] Do device node auto cleanup in drivers/soc/ti/ Kousik Sanagavarapu
2024-07-07 5:14 ` [PATCH v3 1/4] soc: ti: pruss: factor out memories setup Kousik Sanagavarapu
2024-08-24 18:49 ` Nishanth Menon
2024-08-25 6:38 ` Kousik Sanagavarapu
2024-07-07 5:14 ` Kousik Sanagavarapu [this message]
2024-07-07 5:14 ` [PATCH v3 3/4] soc: ti: knav_qmss_queue: do device_node auto cleanup Kousik Sanagavarapu
2024-07-07 5:14 ` [PATCH v3 4/4] soc: ti: pm33xx: " Kousik Sanagavarapu
2024-07-17 21:34 ` [PATCH v3 0/4] Do device node auto cleanup in drivers/soc/ti/ Kousik Sanagavarapu
2024-07-18 11:21 ` Nishanth Menon
2024-07-18 14:12 ` Kousik Sanagavarapu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240707055341.3656-3-five231003@gmail.com \
--to=five231003@gmail.com \
--cc=Jonathan.Cameron@Huawei.com \
--cc=javier.carrasco.cruz@gmail.com \
--cc=julia.lawall@inria.fr \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nathan@kernel.org \
--cc=nm@ti.com \
--cc=skhan@linuxfoundation.org \
--cc=ssantosh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.