Skip to content

Commit bffc723

Browse files
Zhang Zekunkwilczynski
authored andcommitted
PCI: tegra: Use helper function for_each_child_of_node_scoped()
The for_each_available_child_of_node_scoped() helper provides a scope-based clean-up functionality to put the device_node automatically, and as such, there is no need to call of_node_put() directly. Thus, use this helper to simplify the code. Signed-off-by: Zhang Zekun <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Reviewed-by: Manivannan Sadhasivam <[email protected]> Link: https://lore.kernel.org/r/[email protected] [kwilczynski: commit log] Signed-off-by: Krzysztof Wilczyński <[email protected]>
1 parent f60b4e0 commit bffc723

File tree

1 file changed

+28
-52
lines changed

1 file changed

+28
-52
lines changed

drivers/pci/controller/pci-tegra.c

Lines changed: 28 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,47 +2106,39 @@ static int tegra_pcie_get_regulators(struct tegra_pcie *pcie, u32 lane_mask)
21062106
static int tegra_pcie_parse_dt(struct tegra_pcie *pcie)
21072107
{
21082108
struct device *dev = pcie->dev;
2109-
struct device_node *np = dev->of_node, *port;
2109+
struct device_node *np = dev->of_node;
21102110
const struct tegra_pcie_soc *soc = pcie->soc;
21112111
u32 lanes = 0, mask = 0;
21122112
unsigned int lane = 0;
21132113
int err;
21142114

21152115
/* parse root ports */
2116-
for_each_child_of_node(np, port) {
2116+
for_each_child_of_node_scoped(np, port) {
21172117
struct tegra_pcie_port *rp;
21182118
unsigned int index;
21192119
u32 value;
21202120
char *label;
21212121

21222122
err = of_pci_get_devfn(port);
2123-
if (err < 0) {
2124-
dev_err(dev, "failed to parse address: %d\n", err);
2125-
goto err_node_put;
2126-
}
2123+
if (err < 0)
2124+
return dev_err_probe(dev, err, "failed to parse address\n");
21272125

21282126
index = PCI_SLOT(err);
21292127

2130-
if (index < 1 || index > soc->num_ports) {
2131-
dev_err(dev, "invalid port number: %d\n", index);
2132-
err = -EINVAL;
2133-
goto err_node_put;
2134-
}
2128+
if (index < 1 || index > soc->num_ports)
2129+
return dev_err_probe(dev, -EINVAL,
2130+
"invalid port number: %d\n", index);
21352131

21362132
index--;
21372133

21382134
err = of_property_read_u32(port, "nvidia,num-lanes", &value);
2139-
if (err < 0) {
2140-
dev_err(dev, "failed to parse # of lanes: %d\n",
2141-
err);
2142-
goto err_node_put;
2143-
}
2135+
if (err < 0)
2136+
return dev_err_probe(dev, err,
2137+
"failed to parse # of lanes\n");
21442138

2145-
if (value > 16) {
2146-
dev_err(dev, "invalid # of lanes: %u\n", value);
2147-
err = -EINVAL;
2148-
goto err_node_put;
2149-
}
2139+
if (value > 16)
2140+
return dev_err_probe(dev, -EINVAL,
2141+
"invalid # of lanes: %u\n", value);
21502142

21512143
lanes |= value << (index << 3);
21522144

@@ -2159,16 +2151,12 @@ static int tegra_pcie_parse_dt(struct tegra_pcie *pcie)
21592151
lane += value;
21602152

21612153
rp = devm_kzalloc(dev, sizeof(*rp), GFP_KERNEL);
2162-
if (!rp) {
2163-
err = -ENOMEM;
2164-
goto err_node_put;
2165-
}
2154+
if (!rp)
2155+
return -ENOMEM;
21662156

21672157
err = of_address_to_resource(port, 0, &rp->regs);
2168-
if (err < 0) {
2169-
dev_err(dev, "failed to parse address: %d\n", err);
2170-
goto err_node_put;
2171-
}
2158+
if (err < 0)
2159+
return dev_err_probe(dev, err, "failed to parse address\n");
21722160

21732161
INIT_LIST_HEAD(&rp->list);
21742162
rp->index = index;
@@ -2177,16 +2165,12 @@ static int tegra_pcie_parse_dt(struct tegra_pcie *pcie)
21772165
rp->np = port;
21782166

21792167
rp->base = devm_pci_remap_cfg_resource(dev, &rp->regs);
2180-
if (IS_ERR(rp->base)) {
2181-
err = PTR_ERR(rp->base);
2182-
goto err_node_put;
2183-
}
2168+
if (IS_ERR(rp->base))
2169+
return PTR_ERR(rp->base);
21842170

21852171
label = devm_kasprintf(dev, GFP_KERNEL, "pex-reset-%u", index);
2186-
if (!label) {
2187-
err = -ENOMEM;
2188-
goto err_node_put;
2189-
}
2172+
if (!label)
2173+
return -ENOMEM;
21902174

21912175
/*
21922176
* Returns -ENOENT if reset-gpios property is not populated
@@ -2199,34 +2183,26 @@ static int tegra_pcie_parse_dt(struct tegra_pcie *pcie)
21992183
GPIOD_OUT_LOW,
22002184
label);
22012185
if (IS_ERR(rp->reset_gpio)) {
2202-
if (PTR_ERR(rp->reset_gpio) == -ENOENT) {
2186+
if (PTR_ERR(rp->reset_gpio) == -ENOENT)
22032187
rp->reset_gpio = NULL;
2204-
} else {
2205-
dev_err(dev, "failed to get reset GPIO: %ld\n",
2206-
PTR_ERR(rp->reset_gpio));
2207-
err = PTR_ERR(rp->reset_gpio);
2208-
goto err_node_put;
2209-
}
2188+
else
2189+
return dev_err_probe(dev, PTR_ERR(rp->reset_gpio),
2190+
"failed to get reset GPIO\n");
22102191
}
22112192

22122193
list_add_tail(&rp->list, &pcie->ports);
22132194
}
22142195

22152196
err = tegra_pcie_get_xbar_config(pcie, lanes, &pcie->xbar_config);
2216-
if (err < 0) {
2217-
dev_err(dev, "invalid lane configuration\n");
2218-
return err;
2219-
}
2197+
if (err < 0)
2198+
return dev_err_probe(dev, err,
2199+
"invalid lane configuration\n");
22202200

22212201
err = tegra_pcie_get_regulators(pcie, mask);
22222202
if (err < 0)
22232203
return err;
22242204

22252205
return 0;
2226-
2227-
err_node_put:
2228-
of_node_put(port);
2229-
return err;
22302206
}
22312207

22322208
/*

0 commit comments

Comments
 (0)