Skip to content

Commit fabb1c3

Browse files
committed
Merge tag 'phy-for-4.4-rc' of git://git.kernel.org/pub/scm/linux/kernel/git/kishon/linux-phy into usb-linus
Kishon writes: phy: for 4.4 -rc *) Add missing of_node_put in a bunch of PHY drivers *) Add get_device in devm_of_phy_get_by_index() *) Fix randconfig build error in sun9i usb driver
2 parents 9f9499a + 7087446 commit fabb1c3

File tree

9 files changed

+101
-43
lines changed

9 files changed

+101
-43
lines changed

drivers/phy/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ config PHY_SUN9I_USB
233233
tristate "Allwinner sun9i SoC USB PHY driver"
234234
depends on ARCH_SUNXI && HAS_IOMEM && OF
235235
depends on RESET_CONTROLLER
236+
depends on USB_COMMON
236237
select GENERIC_PHY
237238
help
238239
Enable this to support the transceiver that is part of Allwinner

drivers/phy/phy-bcm-cygnus-pcie.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ static int cygnus_pcie_phy_probe(struct platform_device *pdev)
128128
struct phy_provider *provider;
129129
struct resource *res;
130130
unsigned cnt = 0;
131+
int ret;
131132

132133
if (of_get_child_count(node) == 0) {
133134
dev_err(dev, "PHY no child node\n");
@@ -154,24 +155,28 @@ static int cygnus_pcie_phy_probe(struct platform_device *pdev)
154155
if (of_property_read_u32(child, "reg", &id)) {
155156
dev_err(dev, "missing reg property for %s\n",
156157
child->name);
157-
return -EINVAL;
158+
ret = -EINVAL;
159+
goto put_child;
158160
}
159161

160162
if (id >= MAX_NUM_PHYS) {
161163
dev_err(dev, "invalid PHY id: %u\n", id);
162-
return -EINVAL;
164+
ret = -EINVAL;
165+
goto put_child;
163166
}
164167

165168
if (core->phys[id].phy) {
166169
dev_err(dev, "duplicated PHY id: %u\n", id);
167-
return -EINVAL;
170+
ret = -EINVAL;
171+
goto put_child;
168172
}
169173

170174
p = &core->phys[id];
171175
p->phy = devm_phy_create(dev, child, &cygnus_pcie_phy_ops);
172176
if (IS_ERR(p->phy)) {
173177
dev_err(dev, "failed to create PHY\n");
174-
return PTR_ERR(p->phy);
178+
ret = PTR_ERR(p->phy);
179+
goto put_child;
175180
}
176181

177182
p->core = core;
@@ -191,6 +196,9 @@ static int cygnus_pcie_phy_probe(struct platform_device *pdev)
191196
dev_dbg(dev, "registered %u PCIe PHY(s)\n", cnt);
192197

193198
return 0;
199+
put_child:
200+
of_node_put(child);
201+
return ret;
194202
}
195203

196204
static const struct of_device_id cygnus_pcie_phy_match_table[] = {

drivers/phy/phy-berlin-sata.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ static int phy_berlin_sata_probe(struct platform_device *pdev)
195195
struct phy_provider *phy_provider;
196196
struct phy_berlin_priv *priv;
197197
struct resource *res;
198-
int i = 0;
198+
int ret, i = 0;
199199
u32 phy_id;
200200

201201
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
@@ -237,22 +237,27 @@ static int phy_berlin_sata_probe(struct platform_device *pdev)
237237
if (of_property_read_u32(child, "reg", &phy_id)) {
238238
dev_err(dev, "missing reg property in node %s\n",
239239
child->name);
240-
return -EINVAL;
240+
ret = -EINVAL;
241+
goto put_child;
241242
}
242243

243244
if (phy_id >= ARRAY_SIZE(phy_berlin_power_down_bits)) {
244245
dev_err(dev, "invalid reg in node %s\n", child->name);
245-
return -EINVAL;
246+
ret = -EINVAL;
247+
goto put_child;
246248
}
247249

248250
phy_desc = devm_kzalloc(dev, sizeof(*phy_desc), GFP_KERNEL);
249-
if (!phy_desc)
250-
return -ENOMEM;
251+
if (!phy_desc) {
252+
ret = -ENOMEM;
253+
goto put_child;
254+
}
251255

252256
phy = devm_phy_create(dev, NULL, &phy_berlin_sata_ops);
253257
if (IS_ERR(phy)) {
254258
dev_err(dev, "failed to create PHY %d\n", phy_id);
255-
return PTR_ERR(phy);
259+
ret = PTR_ERR(phy);
260+
goto put_child;
256261
}
257262

258263
phy_desc->phy = phy;
@@ -269,6 +274,9 @@ static int phy_berlin_sata_probe(struct platform_device *pdev)
269274
phy_provider =
270275
devm_of_phy_provider_register(dev, phy_berlin_sata_phy_xlate);
271276
return PTR_ERR_OR_ZERO(phy_provider);
277+
put_child:
278+
of_node_put(child);
279+
return ret;
272280
}
273281

274282
static const struct of_device_id phy_berlin_sata_of_match[] = {

drivers/phy/phy-brcmstb-sata.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static int brcm_sata_phy_probe(struct platform_device *pdev)
140140
struct brcm_sata_phy *priv;
141141
struct resource *res;
142142
struct phy_provider *provider;
143-
int count = 0;
143+
int ret, count = 0;
144144

145145
if (of_get_child_count(dn) == 0)
146146
return -ENODEV;
@@ -163,16 +163,19 @@ static int brcm_sata_phy_probe(struct platform_device *pdev)
163163
if (of_property_read_u32(child, "reg", &id)) {
164164
dev_err(dev, "missing reg property in node %s\n",
165165
child->name);
166-
return -EINVAL;
166+
ret = -EINVAL;
167+
goto put_child;
167168
}
168169

169170
if (id >= MAX_PORTS) {
170171
dev_err(dev, "invalid reg: %u\n", id);
171-
return -EINVAL;
172+
ret = -EINVAL;
173+
goto put_child;
172174
}
173175
if (priv->phys[id].phy) {
174176
dev_err(dev, "already registered port %u\n", id);
175-
return -EINVAL;
177+
ret = -EINVAL;
178+
goto put_child;
176179
}
177180

178181
port = &priv->phys[id];
@@ -182,7 +185,8 @@ static int brcm_sata_phy_probe(struct platform_device *pdev)
182185
port->ssc_en = of_property_read_bool(child, "brcm,enable-ssc");
183186
if (IS_ERR(port->phy)) {
184187
dev_err(dev, "failed to create PHY\n");
185-
return PTR_ERR(port->phy);
188+
ret = PTR_ERR(port->phy);
189+
goto put_child;
186190
}
187191

188192
phy_set_drvdata(port->phy, port);
@@ -198,6 +202,9 @@ static int brcm_sata_phy_probe(struct platform_device *pdev)
198202
dev_info(dev, "registered %d port(s)\n", count);
199203

200204
return 0;
205+
put_child:
206+
of_node_put(child);
207+
return ret;
201208
}
202209

203210
static struct platform_driver brcm_sata_phy_driver = {

drivers/phy/phy-core.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,9 @@ EXPORT_SYMBOL_GPL(devm_of_phy_get);
636636
* @np: node containing the phy
637637
* @index: index of the phy
638638
*
639-
* Gets the phy using _of_phy_get(), and associates a device with it using
640-
* devres. On driver detach, release function is invoked on the devres data,
639+
* Gets the phy using _of_phy_get(), then gets a refcount to it,
640+
* and associates a device with it using devres. On driver detach,
641+
* release function is invoked on the devres data,
641642
* then, devres data is freed.
642643
*
643644
*/
@@ -651,13 +652,21 @@ struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
651652
return ERR_PTR(-ENOMEM);
652653

653654
phy = _of_phy_get(np, index);
654-
if (!IS_ERR(phy)) {
655-
*ptr = phy;
656-
devres_add(dev, ptr);
657-
} else {
655+
if (IS_ERR(phy)) {
658656
devres_free(ptr);
657+
return phy;
659658
}
660659

660+
if (!try_module_get(phy->ops->owner)) {
661+
devres_free(ptr);
662+
return ERR_PTR(-EPROBE_DEFER);
663+
}
664+
665+
get_device(&phy->dev);
666+
667+
*ptr = phy;
668+
devres_add(dev, ptr);
669+
661670
return phy;
662671
}
663672
EXPORT_SYMBOL_GPL(devm_of_phy_get_by_index);

drivers/phy/phy-miphy28lp.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,27 +1226,30 @@ static int miphy28lp_probe(struct platform_device *pdev)
12261226

12271227
miphy_phy = devm_kzalloc(&pdev->dev, sizeof(*miphy_phy),
12281228
GFP_KERNEL);
1229-
if (!miphy_phy)
1230-
return -ENOMEM;
1229+
if (!miphy_phy) {
1230+
ret = -ENOMEM;
1231+
goto put_child;
1232+
}
12311233

12321234
miphy_dev->phys[port] = miphy_phy;
12331235

12341236
phy = devm_phy_create(&pdev->dev, child, &miphy28lp_ops);
12351237
if (IS_ERR(phy)) {
12361238
dev_err(&pdev->dev, "failed to create PHY\n");
1237-
return PTR_ERR(phy);
1239+
ret = PTR_ERR(phy);
1240+
goto put_child;
12381241
}
12391242

12401243
miphy_dev->phys[port]->phy = phy;
12411244
miphy_dev->phys[port]->phydev = miphy_dev;
12421245

12431246
ret = miphy28lp_of_probe(child, miphy_phy);
12441247
if (ret)
1245-
return ret;
1248+
goto put_child;
12461249

12471250
ret = miphy28lp_probe_resets(child, miphy_dev->phys[port]);
12481251
if (ret)
1249-
return ret;
1252+
goto put_child;
12501253

12511254
phy_set_drvdata(phy, miphy_dev->phys[port]);
12521255
port++;
@@ -1255,6 +1258,9 @@ static int miphy28lp_probe(struct platform_device *pdev)
12551258

12561259
provider = devm_of_phy_provider_register(&pdev->dev, miphy28lp_xlate);
12571260
return PTR_ERR_OR_ZERO(provider);
1261+
put_child:
1262+
of_node_put(child);
1263+
return ret;
12581264
}
12591265

12601266
static const struct of_device_id miphy28lp_of_match[] = {

drivers/phy/phy-miphy365x.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -566,22 +566,25 @@ static int miphy365x_probe(struct platform_device *pdev)
566566

567567
miphy_phy = devm_kzalloc(&pdev->dev, sizeof(*miphy_phy),
568568
GFP_KERNEL);
569-
if (!miphy_phy)
570-
return -ENOMEM;
569+
if (!miphy_phy) {
570+
ret = -ENOMEM;
571+
goto put_child;
572+
}
571573

572574
miphy_dev->phys[port] = miphy_phy;
573575

574576
phy = devm_phy_create(&pdev->dev, child, &miphy365x_ops);
575577
if (IS_ERR(phy)) {
576578
dev_err(&pdev->dev, "failed to create PHY\n");
577-
return PTR_ERR(phy);
579+
ret = PTR_ERR(phy);
580+
goto put_child;
578581
}
579582

580583
miphy_dev->phys[port]->phy = phy;
581584

582585
ret = miphy365x_of_probe(child, miphy_phy);
583586
if (ret)
584-
return ret;
587+
goto put_child;
585588

586589
phy_set_drvdata(phy, miphy_dev->phys[port]);
587590

@@ -591,12 +594,15 @@ static int miphy365x_probe(struct platform_device *pdev)
591594
&miphy_phy->ctrlreg);
592595
if (ret) {
593596
dev_err(&pdev->dev, "No sysconfig offset found\n");
594-
return ret;
597+
goto put_child;
595598
}
596599
}
597600

598601
provider = devm_of_phy_provider_register(&pdev->dev, miphy365x_xlate);
599602
return PTR_ERR_OR_ZERO(provider);
603+
put_child:
604+
of_node_put(child);
605+
return ret;
600606
}
601607

602608
static const struct of_device_id miphy365x_of_match[] = {

drivers/phy/phy-mt65xx-usb3.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ static int mt65xx_u3phy_probe(struct platform_device *pdev)
415415
struct resource *sif_res;
416416
struct mt65xx_u3phy *u3phy;
417417
struct resource res;
418-
int port;
418+
int port, retval;
419419

420420
u3phy = devm_kzalloc(dev, sizeof(*u3phy), GFP_KERNEL);
421421
if (!u3phy)
@@ -447,31 +447,34 @@ static int mt65xx_u3phy_probe(struct platform_device *pdev)
447447
for_each_child_of_node(np, child_np) {
448448
struct mt65xx_phy_instance *instance;
449449
struct phy *phy;
450-
int retval;
451450

452451
instance = devm_kzalloc(dev, sizeof(*instance), GFP_KERNEL);
453-
if (!instance)
454-
return -ENOMEM;
452+
if (!instance) {
453+
retval = -ENOMEM;
454+
goto put_child;
455+
}
455456

456457
u3phy->phys[port] = instance;
457458

458459
phy = devm_phy_create(dev, child_np, &mt65xx_u3phy_ops);
459460
if (IS_ERR(phy)) {
460461
dev_err(dev, "failed to create phy\n");
461-
return PTR_ERR(phy);
462+
retval = PTR_ERR(phy);
463+
goto put_child;
462464
}
463465

464466
retval = of_address_to_resource(child_np, 0, &res);
465467
if (retval) {
466468
dev_err(dev, "failed to get address resource(id-%d)\n",
467469
port);
468-
return retval;
470+
goto put_child;
469471
}
470472

471473
instance->port_base = devm_ioremap_resource(&phy->dev, &res);
472474
if (IS_ERR(instance->port_base)) {
473475
dev_err(dev, "failed to remap phy regs\n");
474-
return PTR_ERR(instance->port_base);
476+
retval = PTR_ERR(instance->port_base);
477+
goto put_child;
475478
}
476479

477480
instance->phy = phy;
@@ -483,6 +486,9 @@ static int mt65xx_u3phy_probe(struct platform_device *pdev)
483486
provider = devm_of_phy_provider_register(dev, mt65xx_phy_xlate);
484487

485488
return PTR_ERR_OR_ZERO(provider);
489+
put_child:
490+
of_node_put(child_np);
491+
return retval;
486492
}
487493

488494
static const struct of_device_id mt65xx_u3phy_id_table[] = {

drivers/phy/phy-rockchip-usb.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,16 @@ static int rockchip_usb_phy_probe(struct platform_device *pdev)
108108

109109
for_each_available_child_of_node(dev->of_node, child) {
110110
rk_phy = devm_kzalloc(dev, sizeof(*rk_phy), GFP_KERNEL);
111-
if (!rk_phy)
112-
return -ENOMEM;
111+
if (!rk_phy) {
112+
err = -ENOMEM;
113+
goto put_child;
114+
}
113115

114116
if (of_property_read_u32(child, "reg", &reg_offset)) {
115117
dev_err(dev, "missing reg property in node %s\n",
116118
child->name);
117-
return -EINVAL;
119+
err = -EINVAL;
120+
goto put_child;
118121
}
119122

120123
rk_phy->reg_offset = reg_offset;
@@ -127,18 +130,22 @@ static int rockchip_usb_phy_probe(struct platform_device *pdev)
127130
rk_phy->phy = devm_phy_create(dev, child, &ops);
128131
if (IS_ERR(rk_phy->phy)) {
129132
dev_err(dev, "failed to create PHY\n");
130-
return PTR_ERR(rk_phy->phy);
133+
err = PTR_ERR(rk_phy->phy);
134+
goto put_child;
131135
}
132136
phy_set_drvdata(rk_phy->phy, rk_phy);
133137

134138
/* only power up usb phy when it use, so disable it when init*/
135139
err = rockchip_usb_phy_power(rk_phy, 1);
136140
if (err)
137-
return err;
141+
goto put_child;
138142
}
139143

140144
phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
141145
return PTR_ERR_OR_ZERO(phy_provider);
146+
put_child:
147+
of_node_put(child);
148+
return err;
142149
}
143150

144151
static const struct of_device_id rockchip_usb_phy_dt_ids[] = {

0 commit comments

Comments
 (0)