soc: ti: pruss: do device_node auto cleanup
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> Link: https://lore.kernel.org/r/20240825085714.10736-3-five231003@gmail.com Signed-off-by: Nishanth Menon <nm@ti.com>
This commit is contained in:
parent
952ceb0378
commit
df70c0b482
@ -380,50 +380,42 @@ put_clk_mux_np:
|
|||||||
|
|
||||||
static int pruss_clk_init(struct pruss *pruss, struct device_node *cfg_node)
|
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;
|
struct device *dev = pruss->dev;
|
||||||
int ret = 0;
|
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;
|
||||||
|
|
||||||
data = of_device_get_match_data(dev);
|
if (!clks_np)
|
||||||
|
return dev_err_probe(dev, -ENODEV,
|
||||||
clks_np = of_get_child_by_name(cfg_node, "clocks");
|
"%pOF is missing its 'clocks' node\n",
|
||||||
if (!clks_np) {
|
cfg_node);
|
||||||
dev_err(dev, "%pOF is missing its 'clocks' node\n", cfg_node);
|
|
||||||
return -ENODEV;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data && data->has_core_mux_clock) {
|
if (data && data->has_core_mux_clock) {
|
||||||
ret = pruss_clk_mux_setup(pruss, pruss->core_clk_mux,
|
ret = pruss_clk_mux_setup(pruss, pruss->core_clk_mux,
|
||||||
"coreclk-mux", clks_np);
|
"coreclk-mux", clks_np);
|
||||||
if (ret) {
|
if (ret)
|
||||||
dev_err(dev, "failed to setup coreclk-mux\n");
|
return dev_err_probe(dev, ret,
|
||||||
goto put_clks_node;
|
"failed to setup coreclk-mux\n");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = pruss_clk_mux_setup(pruss, pruss->iep_clk_mux, "iepclk-mux",
|
ret = pruss_clk_mux_setup(pruss, pruss->iep_clk_mux, "iepclk-mux",
|
||||||
clks_np);
|
clks_np);
|
||||||
if (ret) {
|
if (ret)
|
||||||
dev_err(dev, "failed to setup iepclk-mux\n");
|
return dev_err_probe(dev, ret, "failed to setup iepclk-mux\n");
|
||||||
goto put_clks_node;
|
|
||||||
}
|
|
||||||
|
|
||||||
put_clks_node:
|
return 0;
|
||||||
of_node_put(clks_np);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int pruss_of_setup_memories(struct device *dev, struct pruss *pruss)
|
static int pruss_of_setup_memories(struct device *dev, struct pruss *pruss)
|
||||||
{
|
{
|
||||||
struct device_node *np = dev_of_node(dev);
|
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 struct pruss_private_data *data = of_device_get_match_data(dev);
|
||||||
const char *mem_names[PRUSS_MEM_MAX] = { "dram0", "dram1", "shrdram2" };
|
const char *mem_names[PRUSS_MEM_MAX] = { "dram0", "dram1", "shrdram2" };
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
child = of_get_child_by_name(np, "memories");
|
|
||||||
if (!child)
|
if (!child)
|
||||||
return dev_err_probe(dev, -ENODEV,
|
return dev_err_probe(dev, -ENODEV,
|
||||||
"%pOF is missing its 'memories' node\n",
|
"%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",
|
index = of_property_match_string(child, "reg-names",
|
||||||
mem_names[i]);
|
mem_names[i]);
|
||||||
if (index < 0) {
|
if (index < 0)
|
||||||
of_node_put(child);
|
|
||||||
return index;
|
return index;
|
||||||
}
|
|
||||||
|
|
||||||
if (of_address_to_resource(child, index, &res)) {
|
if (of_address_to_resource(child, index, &res))
|
||||||
of_node_put(child);
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
|
||||||
|
|
||||||
pruss->mem_regions[i].va = devm_ioremap(dev, res.start,
|
pruss->mem_regions[i].va = devm_ioremap(dev, res.start,
|
||||||
resource_size(&res));
|
resource_size(&res));
|
||||||
if (!pruss->mem_regions[i].va) {
|
if (!pruss->mem_regions[i].va)
|
||||||
of_node_put(child);
|
|
||||||
return dev_err_probe(dev, -ENOMEM,
|
return dev_err_probe(dev, -ENOMEM,
|
||||||
"failed to parse and map memory resource %d %s\n",
|
"failed to parse and map memory resource %d %s\n",
|
||||||
i, mem_names[i]);
|
i, mem_names[i]);
|
||||||
}
|
|
||||||
pruss->mem_regions[i].pa = res.start;
|
pruss->mem_regions[i].pa = res.start;
|
||||||
pruss->mem_regions[i].size = resource_size(&res);
|
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,
|
mem_names[i], &pruss->mem_regions[i].pa,
|
||||||
pruss->mem_regions[i].size, pruss->mem_regions[i].va);
|
pruss->mem_regions[i].size, pruss->mem_regions[i].va);
|
||||||
}
|
}
|
||||||
of_node_put(child);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -481,26 +466,21 @@ static struct regmap_config regmap_conf = {
|
|||||||
static int pruss_cfg_of_init(struct device *dev, struct pruss *pruss)
|
static int pruss_cfg_of_init(struct device *dev, struct pruss *pruss)
|
||||||
{
|
{
|
||||||
struct device_node *np = dev_of_node(dev);
|
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;
|
struct resource res;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
child = of_get_child_by_name(np, "cfg");
|
if (!child)
|
||||||
if (!child) {
|
return dev_err_probe(dev, -ENODEV,
|
||||||
dev_err(dev, "%pOF is missing its 'cfg' node\n", child);
|
"%pOF is missing its 'cfg' node\n", child);
|
||||||
return -ENODEV;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (of_address_to_resource(child, 0, &res)) {
|
if (of_address_to_resource(child, 0, &res))
|
||||||
ret = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto node_put;
|
|
||||||
}
|
|
||||||
|
|
||||||
pruss->cfg_base = devm_ioremap(dev, res.start, resource_size(&res));
|
pruss->cfg_base = devm_ioremap(dev, res.start, resource_size(&res));
|
||||||
if (!pruss->cfg_base) {
|
if (!pruss->cfg_base)
|
||||||
ret = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto node_put;
|
|
||||||
}
|
|
||||||
|
|
||||||
regmap_conf.name = kasprintf(GFP_KERNEL, "%pOFn@%llx", child,
|
regmap_conf.name = kasprintf(GFP_KERNEL, "%pOFn@%llx", child,
|
||||||
(u64)res.start);
|
(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,
|
pruss->cfg_regmap = devm_regmap_init_mmio(dev, pruss->cfg_base,
|
||||||
®map_conf);
|
®map_conf);
|
||||||
kfree(regmap_conf.name);
|
kfree(regmap_conf.name);
|
||||||
if (IS_ERR(pruss->cfg_regmap)) {
|
if (IS_ERR(pruss->cfg_regmap))
|
||||||
dev_err(dev, "regmap_init_mmio failed for cfg, ret = %ld\n",
|
return dev_err_probe(dev, PTR_ERR(pruss->cfg_regmap),
|
||||||
PTR_ERR(pruss->cfg_regmap));
|
"regmap_init_mmio failed for cfg\n");
|
||||||
ret = PTR_ERR(pruss->cfg_regmap);
|
|
||||||
goto node_put;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = pruss_clk_init(pruss, child);
|
ret = pruss_clk_init(pruss, child);
|
||||||
if (ret)
|
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:
|
return 0;
|
||||||
of_node_put(child);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int pruss_probe(struct platform_device *pdev)
|
static int pruss_probe(struct platform_device *pdev)
|
||||||
|
Loading…
Reference in New Issue
Block a user