Skip to content

Commit 7e99e34

Browse files
vivienJakub Kicinski
authored andcommitted
net: dsa: remove dsa_switch_alloc helper
Now that ports are dynamically listed in the fabric, there is no need to provide a special helper to allocate the dsa_switch structure. This will give more flexibility to drivers to embed this structure as they wish in their private structure. Signed-off-by: Vivien Didelot <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 05f294a commit 7e99e34

File tree

14 files changed

+49
-28
lines changed

14 files changed

+49
-28
lines changed

drivers/net/dsa/b53/b53_common.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2341,10 +2341,13 @@ struct b53_device *b53_switch_alloc(struct device *base,
23412341
struct dsa_switch *ds;
23422342
struct b53_device *dev;
23432343

2344-
ds = dsa_switch_alloc(base, DSA_MAX_PORTS);
2344+
ds = devm_kzalloc(base, sizeof(*ds), GFP_KERNEL);
23452345
if (!ds)
23462346
return NULL;
23472347

2348+
ds->dev = base;
2349+
ds->num_ports = DSA_MAX_PORTS;
2350+
23482351
dev = devm_kzalloc(base, sizeof(*dev), GFP_KERNEL);
23492352
if (!dev)
23502353
return NULL;

drivers/net/dsa/dsa_loop.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,13 @@ static int dsa_loop_drv_probe(struct mdio_device *mdiodev)
286286
dev_info(&mdiodev->dev, "%s: 0x%0x\n",
287287
pdata->name, pdata->enabled_ports);
288288

289-
ds = dsa_switch_alloc(&mdiodev->dev, DSA_MAX_PORTS);
289+
ds = devm_kzalloc(&mdiodev->dev, sizeof(*ds), GFP_KERNEL);
290290
if (!ds)
291291
return -ENOMEM;
292292

293+
ds->dev = &mdiodev->dev;
294+
ds->num_ports = DSA_MAX_PORTS;
295+
293296
ps = devm_kzalloc(&mdiodev->dev, sizeof(*ps), GFP_KERNEL);
294297
if (!ps)
295298
return -ENOMEM;

drivers/net/dsa/lan9303-core.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1283,10 +1283,12 @@ static int lan9303_register_switch(struct lan9303 *chip)
12831283
{
12841284
int base;
12851285

1286-
chip->ds = dsa_switch_alloc(chip->dev, LAN9303_NUM_PORTS);
1286+
chip->ds = devm_kzalloc(chip->dev, sizeof(*chip->ds), GFP_KERNEL);
12871287
if (!chip->ds)
12881288
return -ENOMEM;
12891289

1290+
chip->ds->dev = chip->dev;
1291+
chip->ds->num_ports = LAN9303_NUM_PORTS;
12901292
chip->ds->priv = chip;
12911293
chip->ds->ops = &lan9303_switch_ops;
12921294
base = chip->phy_addr_base;

drivers/net/dsa/lantiq_gswip.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1854,10 +1854,12 @@ static int gswip_probe(struct platform_device *pdev)
18541854
if (!priv->hw_info)
18551855
return -EINVAL;
18561856

1857-
priv->ds = dsa_switch_alloc(dev, priv->hw_info->max_ports);
1857+
priv->ds = devm_kzalloc(dev, sizeof(*priv->ds), GFP_KERNEL);
18581858
if (!priv->ds)
18591859
return -ENOMEM;
18601860

1861+
priv->ds->dev = dev;
1862+
priv->ds->num_ports = priv->hw_info->max_ports;
18611863
priv->ds->priv = priv;
18621864
priv->ds->ops = &gswip_switch_ops;
18631865
priv->dev = dev;

drivers/net/dsa/microchip/ksz_common.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,13 @@ struct ksz_device *ksz_switch_alloc(struct device *base, void *priv)
398398
struct dsa_switch *ds;
399399
struct ksz_device *swdev;
400400

401-
ds = dsa_switch_alloc(base, DSA_MAX_PORTS);
401+
ds = devm_kzalloc(base, sizeof(*ds), GFP_KERNEL);
402402
if (!ds)
403403
return NULL;
404404

405+
ds->dev = base;
406+
ds->num_ports = DSA_MAX_PORTS;
407+
405408
swdev = devm_kzalloc(base, sizeof(*swdev), GFP_KERNEL);
406409
if (!swdev)
407410
return NULL;

drivers/net/dsa/mt7530.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1632,10 +1632,13 @@ mt7530_probe(struct mdio_device *mdiodev)
16321632
if (!priv)
16331633
return -ENOMEM;
16341634

1635-
priv->ds = dsa_switch_alloc(&mdiodev->dev, DSA_MAX_PORTS);
1635+
priv->ds = devm_kzalloc(&mdiodev->dev, sizeof(*priv->ds), GFP_KERNEL);
16361636
if (!priv->ds)
16371637
return -ENOMEM;
16381638

1639+
priv->ds->dev = &mdiodev->dev;
1640+
priv->ds->num_ports = DSA_MAX_PORTS;
1641+
16391642
/* Use medatek,mcm property to distinguish hardware type that would
16401643
* casues a little bit differences on power-on sequence.
16411644
*/

drivers/net/dsa/mv88e6060.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,12 @@ static int mv88e6060_probe(struct mdio_device *mdiodev)
270270

271271
dev_info(dev, "switch %s detected\n", name);
272272

273-
ds = dsa_switch_alloc(dev, MV88E6060_PORTS);
273+
ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
274274
if (!ds)
275275
return -ENOMEM;
276276

277+
ds->dev = dev;
278+
ds->num_ports = MV88E6060_PORTS;
277279
ds->priv = priv;
278280
ds->dev = dev;
279281
ds->ops = &mv88e6060_switch_ops;

drivers/net/dsa/mv88e6xxx/chip.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4978,10 +4978,12 @@ static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
49784978
struct device *dev = chip->dev;
49794979
struct dsa_switch *ds;
49804980

4981-
ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
4981+
ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
49824982
if (!ds)
49834983
return -ENOMEM;
49844984

4985+
ds->dev = dev;
4986+
ds->num_ports = mv88e6xxx_num_ports(chip);
49854987
ds->priv = chip;
49864988
ds->dev = dev;
49874989
ds->ops = &mv88e6xxx_switch_ops;

drivers/net/dsa/qca8k.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,10 +1077,13 @@ qca8k_sw_probe(struct mdio_device *mdiodev)
10771077
if (id != QCA8K_ID_QCA8337)
10781078
return -ENODEV;
10791079

1080-
priv->ds = dsa_switch_alloc(&mdiodev->dev, QCA8K_NUM_PORTS);
1080+
priv->ds = devm_kzalloc(&mdiodev->dev, sizeof(*priv->ds),
1081+
QCA8K_NUM_PORTS);
10811082
if (!priv->ds)
10821083
return -ENOMEM;
10831084

1085+
priv->ds->dev = &mdiodev->dev;
1086+
priv->ds->num_ports = DSA_MAX_PORTS;
10841087
priv->ds->priv = priv;
10851088
priv->ops = qca8k_switch_ops;
10861089
priv->ds->ops = &priv->ops;

drivers/net/dsa/realtek-smi-core.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,12 @@ static int realtek_smi_probe(struct platform_device *pdev)
444444
return ret;
445445
}
446446

447-
smi->ds = dsa_switch_alloc(dev, smi->num_ports);
447+
smi->ds = devm_kzalloc(dev, sizeof(*smi->ds), GFP_KERNEL);
448448
if (!smi->ds)
449449
return -ENOMEM;
450+
451+
smi->ds->dev = dev;
452+
smi->ds->num_ports = smi->num_ports;
450453
smi->ds->priv = smi;
451454

452455
smi->ds->ops = var->ds_ops;

drivers/net/dsa/sja1105/sja1105_main.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2047,10 +2047,12 @@ static int sja1105_probe(struct spi_device *spi)
20472047

20482048
dev_info(dev, "Probed switch chip: %s\n", priv->info->name);
20492049

2050-
ds = dsa_switch_alloc(dev, SJA1105_NUM_PORTS);
2050+
ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
20512051
if (!ds)
20522052
return -ENOMEM;
20532053

2054+
ds->dev = dev;
2055+
ds->num_ports = SJA1105_NUM_PORTS;
20542056
ds->ops = &sja1105_switch_ops;
20552057
ds->priv = priv;
20562058
priv->ds = ds;

drivers/net/dsa/vitesse-vsc73xx-core.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1178,9 +1178,12 @@ int vsc73xx_probe(struct vsc73xx *vsc)
11781178
* We allocate 8 ports and avoid access to the nonexistant
11791179
* ports.
11801180
*/
1181-
vsc->ds = dsa_switch_alloc(dev, 8);
1181+
vsc->ds = devm_kzalloc(dev, sizeof(*vsc->ds), GFP_KERNEL);
11821182
if (!vsc->ds)
11831183
return -ENOMEM;
1184+
1185+
vsc->ds->dev = dev;
1186+
vsc->ds->num_ports = 8;
11841187
vsc->ds->priv = vsc;
11851188

11861189
vsc->ds->ops = &vsc73xx_ds_ops;

include/net/dsa.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,6 @@ static inline bool dsa_can_decode(const struct sk_buff *skb,
577577
return false;
578578
}
579579

580-
struct dsa_switch *dsa_switch_alloc(struct device *dev, size_t n);
581580
void dsa_unregister_switch(struct dsa_switch *ds);
582581
int dsa_register_switch(struct dsa_switch *ds);
583582
#ifdef CONFIG_PM_SLEEP

net/dsa/dsa2.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,12 @@ static int dsa_switch_probe(struct dsa_switch *ds)
846846
struct device_node *np = ds->dev->of_node;
847847
int err;
848848

849+
if (!ds->dev)
850+
return -ENODEV;
851+
852+
if (!ds->num_ports)
853+
return -EINVAL;
854+
849855
if (np)
850856
err = dsa_switch_parse_of(ds, np);
851857
else if (pdata)
@@ -859,21 +865,6 @@ static int dsa_switch_probe(struct dsa_switch *ds)
859865
return dsa_switch_add(ds);
860866
}
861867

862-
struct dsa_switch *dsa_switch_alloc(struct device *dev, size_t n)
863-
{
864-
struct dsa_switch *ds;
865-
866-
ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
867-
if (!ds)
868-
return NULL;
869-
870-
ds->dev = dev;
871-
ds->num_ports = n;
872-
873-
return ds;
874-
}
875-
EXPORT_SYMBOL_GPL(dsa_switch_alloc);
876-
877868
int dsa_register_switch(struct dsa_switch *ds)
878869
{
879870
int err;

0 commit comments

Comments
 (0)