Skip to content

Commit 8085db1

Browse files
committed
Merge branch 'pci/scoped-cleanup'
- Use for_each_available_child_of_node_scoped() to simplify apple, kirin, mediatek, mt7621, tegra drivers (Zhang Zekun) * pci/scoped-cleanup: PCI: tegra: Use helper function for_each_child_of_node_scoped() PCI: apple: Use helper function for_each_child_of_node_scoped() PCI: mt7621: Use helper function for_each_available_child_of_node_scoped() PCI: mediatek: Use helper function for_each_available_child_of_node_scoped() PCI: kirin: Tidy up _probe() related function with dev_err_probe() PCI: kirin: Use helper function for_each_available_child_of_node_scoped()
2 parents f775c8a + bffc723 commit 8085db1

File tree

5 files changed

+57
-107
lines changed

5 files changed

+57
-107
lines changed

drivers/pci/controller/dwc/pcie-kirin.c

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,9 @@ static int hi3660_pcie_phy_start(struct hi3660_pcie_phy *phy)
216216

217217
usleep_range(PIPE_CLK_WAIT_MIN, PIPE_CLK_WAIT_MAX);
218218
reg_val = kirin_apb_phy_readl(phy, PCIE_APB_PHY_STATUS0);
219-
if (reg_val & PIPE_CLK_STABLE) {
220-
dev_err(dev, "PIPE clk is not stable\n");
221-
return -EINVAL;
222-
}
219+
if (reg_val & PIPE_CLK_STABLE)
220+
return dev_err_probe(dev, -ETIMEDOUT,
221+
"PIPE clk is not stable\n");
223222

224223
return 0;
225224
}
@@ -371,10 +370,9 @@ static int kirin_pcie_get_gpio_enable(struct kirin_pcie *pcie,
371370
if (ret < 0)
372371
return 0;
373372

374-
if (ret > MAX_PCI_SLOTS) {
375-
dev_err(dev, "Too many GPIO clock requests!\n");
376-
return -EINVAL;
377-
}
373+
if (ret > MAX_PCI_SLOTS)
374+
return dev_err_probe(dev, -EINVAL,
375+
"Too many GPIO clock requests!\n");
378376

379377
pcie->n_gpio_clkreq = ret;
380378

@@ -420,17 +418,16 @@ static int kirin_pcie_parse_port(struct kirin_pcie *pcie,
420418
"unable to get a valid reset gpio\n");
421419
}
422420

423-
if (pcie->num_slots + 1 >= MAX_PCI_SLOTS) {
424-
dev_err(dev, "Too many PCI slots!\n");
425-
return -EINVAL;
426-
}
421+
if (pcie->num_slots + 1 >= MAX_PCI_SLOTS)
422+
return dev_err_probe(dev, -EINVAL,
423+
"Too many PCI slots!\n");
424+
427425
pcie->num_slots++;
428426

429427
ret = of_pci_get_devfn(child);
430-
if (ret < 0) {
431-
dev_err(dev, "failed to parse devfn: %d\n", ret);
432-
return ret;
433-
}
428+
if (ret < 0)
429+
return dev_err_probe(dev, ret,
430+
"failed to parse devfn\n");
434431

435432
slot = PCI_SLOT(ret);
436433

@@ -452,7 +449,7 @@ static long kirin_pcie_get_resource(struct kirin_pcie *kirin_pcie,
452449
struct platform_device *pdev)
453450
{
454451
struct device *dev = &pdev->dev;
455-
struct device_node *child, *node = dev->of_node;
452+
struct device_node *node = dev->of_node;
456453
void __iomem *apb_base;
457454
int ret;
458455

@@ -477,17 +474,13 @@ static long kirin_pcie_get_resource(struct kirin_pcie *kirin_pcie,
477474
return ret;
478475

479476
/* Parse OF children */
480-
for_each_available_child_of_node(node, child) {
477+
for_each_available_child_of_node_scoped(node, child) {
481478
ret = kirin_pcie_parse_port(kirin_pcie, pdev, child);
482479
if (ret)
483-
goto put_node;
480+
return ret;
484481
}
485482

486483
return 0;
487-
488-
put_node:
489-
of_node_put(child);
490-
return ret;
491484
}
492485

493486
static void kirin_pcie_sideband_dbi_w_mode(struct kirin_pcie *kirin_pcie,
@@ -729,16 +722,9 @@ static int kirin_pcie_probe(struct platform_device *pdev)
729722
struct dw_pcie *pci;
730723
int ret;
731724

732-
if (!dev->of_node) {
733-
dev_err(dev, "NULL node\n");
734-
return -EINVAL;
735-
}
736-
737725
data = of_device_get_match_data(dev);
738-
if (!data) {
739-
dev_err(dev, "OF data missing\n");
740-
return -EINVAL;
741-
}
726+
if (!data)
727+
return dev_err_probe(dev, -EINVAL, "OF data missing\n");
742728

743729
kirin_pcie = devm_kzalloc(dev, sizeof(struct kirin_pcie), GFP_KERNEL);
744730
if (!kirin_pcie)

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
/*

drivers/pci/controller/pcie-apple.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,6 @@ static int apple_pcie_init(struct pci_config_window *cfg)
732732
{
733733
struct device *dev = cfg->parent;
734734
struct platform_device *platform = to_platform_device(dev);
735-
struct device_node *of_port;
736735
struct apple_pcie *pcie;
737736
int ret;
738737

@@ -755,11 +754,10 @@ static int apple_pcie_init(struct pci_config_window *cfg)
755754
if (ret)
756755
return ret;
757756

758-
for_each_child_of_node(dev->of_node, of_port) {
757+
for_each_child_of_node_scoped(dev->of_node, of_port) {
759758
ret = apple_pcie_setup_port(pcie, of_port);
760759
if (ret) {
761760
dev_err(pcie->dev, "Port %pOF setup fail: %d\n", of_port, ret);
762-
of_node_put(of_port);
763761
return ret;
764762
}
765763
}

drivers/pci/controller/pcie-mediatek.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,24 +1041,22 @@ static int mtk_pcie_subsys_powerup(struct mtk_pcie *pcie)
10411041
static int mtk_pcie_setup(struct mtk_pcie *pcie)
10421042
{
10431043
struct device *dev = pcie->dev;
1044-
struct device_node *node = dev->of_node, *child;
1044+
struct device_node *node = dev->of_node;
10451045
struct mtk_pcie_port *port, *tmp;
10461046
int err, slot;
10471047

10481048
slot = of_get_pci_domain_nr(dev->of_node);
10491049
if (slot < 0) {
1050-
for_each_available_child_of_node(node, child) {
1050+
for_each_available_child_of_node_scoped(node, child) {
10511051
err = of_pci_get_devfn(child);
1052-
if (err < 0) {
1053-
dev_err(dev, "failed to get devfn: %d\n", err);
1054-
goto error_put_node;
1055-
}
1052+
if (err < 0)
1053+
return dev_err_probe(dev, err, "failed to get devfn\n");
10561054

10571055
slot = PCI_SLOT(err);
10581056

10591057
err = mtk_pcie_parse_port(pcie, child, slot);
10601058
if (err)
1061-
goto error_put_node;
1059+
return err;
10621060
}
10631061
} else {
10641062
err = mtk_pcie_parse_port(pcie, node, slot);
@@ -1079,9 +1077,6 @@ static int mtk_pcie_setup(struct mtk_pcie *pcie)
10791077
mtk_pcie_subsys_powerdown(pcie);
10801078

10811079
return 0;
1082-
error_put_node:
1083-
of_node_put(child);
1084-
return err;
10851080
}
10861081

10871082
static int mtk_pcie_probe(struct platform_device *pdev)

drivers/pci/controller/pcie-mt7621.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -258,30 +258,25 @@ static int mt7621_pcie_parse_dt(struct mt7621_pcie *pcie)
258258
{
259259
struct device *dev = pcie->dev;
260260
struct platform_device *pdev = to_platform_device(dev);
261-
struct device_node *node = dev->of_node, *child;
261+
struct device_node *node = dev->of_node;
262262
int err;
263263

264264
pcie->base = devm_platform_ioremap_resource(pdev, 0);
265265
if (IS_ERR(pcie->base))
266266
return PTR_ERR(pcie->base);
267267

268-
for_each_available_child_of_node(node, child) {
268+
for_each_available_child_of_node_scoped(node, child) {
269269
int slot;
270270

271271
err = of_pci_get_devfn(child);
272-
if (err < 0) {
273-
of_node_put(child);
274-
dev_err(dev, "failed to parse devfn: %d\n", err);
275-
return err;
276-
}
272+
if (err < 0)
273+
return dev_err_probe(dev, err, "failed to parse devfn\n");
277274

278275
slot = PCI_SLOT(err);
279276

280277
err = mt7621_pcie_parse_port(pcie, child, slot);
281-
if (err) {
282-
of_node_put(child);
278+
if (err)
283279
return err;
284-
}
285280
}
286281

287282
return 0;

0 commit comments

Comments
 (0)