Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <vivien.didelot@gmail.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>

authored by

Vivien Didelot and committed by
Jakub Kicinski
7e99e347 05f294a8

+49 -28
+4 -1
drivers/net/dsa/b53/b53_common.c
··· 2341 2341 struct dsa_switch *ds; 2342 2342 struct b53_device *dev; 2343 2343 2344 - ds = dsa_switch_alloc(base, DSA_MAX_PORTS); 2344 + ds = devm_kzalloc(base, sizeof(*ds), GFP_KERNEL); 2345 2345 if (!ds) 2346 2346 return NULL; 2347 + 2348 + ds->dev = base; 2349 + ds->num_ports = DSA_MAX_PORTS; 2347 2350 2348 2351 dev = devm_kzalloc(base, sizeof(*dev), GFP_KERNEL); 2349 2352 if (!dev)
+4 -1
drivers/net/dsa/dsa_loop.c
··· 286 286 dev_info(&mdiodev->dev, "%s: 0x%0x\n", 287 287 pdata->name, pdata->enabled_ports); 288 288 289 - ds = dsa_switch_alloc(&mdiodev->dev, DSA_MAX_PORTS); 289 + ds = devm_kzalloc(&mdiodev->dev, sizeof(*ds), GFP_KERNEL); 290 290 if (!ds) 291 291 return -ENOMEM; 292 + 293 + ds->dev = &mdiodev->dev; 294 + ds->num_ports = DSA_MAX_PORTS; 292 295 293 296 ps = devm_kzalloc(&mdiodev->dev, sizeof(*ps), GFP_KERNEL); 294 297 if (!ps)
+3 -1
drivers/net/dsa/lan9303-core.c
··· 1283 1283 { 1284 1284 int base; 1285 1285 1286 - chip->ds = dsa_switch_alloc(chip->dev, LAN9303_NUM_PORTS); 1286 + chip->ds = devm_kzalloc(chip->dev, sizeof(*chip->ds), GFP_KERNEL); 1287 1287 if (!chip->ds) 1288 1288 return -ENOMEM; 1289 1289 1290 + chip->ds->dev = chip->dev; 1291 + chip->ds->num_ports = LAN9303_NUM_PORTS; 1290 1292 chip->ds->priv = chip; 1291 1293 chip->ds->ops = &lan9303_switch_ops; 1292 1294 base = chip->phy_addr_base;
+3 -1
drivers/net/dsa/lantiq_gswip.c
··· 1854 1854 if (!priv->hw_info) 1855 1855 return -EINVAL; 1856 1856 1857 - priv->ds = dsa_switch_alloc(dev, priv->hw_info->max_ports); 1857 + priv->ds = devm_kzalloc(dev, sizeof(*priv->ds), GFP_KERNEL); 1858 1858 if (!priv->ds) 1859 1859 return -ENOMEM; 1860 1860 1861 + priv->ds->dev = dev; 1862 + priv->ds->num_ports = priv->hw_info->max_ports; 1861 1863 priv->ds->priv = priv; 1862 1864 priv->ds->ops = &gswip_switch_ops; 1863 1865 priv->dev = dev;
+4 -1
drivers/net/dsa/microchip/ksz_common.c
··· 398 398 struct dsa_switch *ds; 399 399 struct ksz_device *swdev; 400 400 401 - ds = dsa_switch_alloc(base, DSA_MAX_PORTS); 401 + ds = devm_kzalloc(base, sizeof(*ds), GFP_KERNEL); 402 402 if (!ds) 403 403 return NULL; 404 + 405 + ds->dev = base; 406 + ds->num_ports = DSA_MAX_PORTS; 404 407 405 408 swdev = devm_kzalloc(base, sizeof(*swdev), GFP_KERNEL); 406 409 if (!swdev)
+4 -1
drivers/net/dsa/mt7530.c
··· 1632 1632 if (!priv) 1633 1633 return -ENOMEM; 1634 1634 1635 - priv->ds = dsa_switch_alloc(&mdiodev->dev, DSA_MAX_PORTS); 1635 + priv->ds = devm_kzalloc(&mdiodev->dev, sizeof(*priv->ds), GFP_KERNEL); 1636 1636 if (!priv->ds) 1637 1637 return -ENOMEM; 1638 + 1639 + priv->ds->dev = &mdiodev->dev; 1640 + priv->ds->num_ports = DSA_MAX_PORTS; 1638 1641 1639 1642 /* Use medatek,mcm property to distinguish hardware type that would 1640 1643 * casues a little bit differences on power-on sequence.
+3 -1
drivers/net/dsa/mv88e6060.c
··· 270 270 271 271 dev_info(dev, "switch %s detected\n", name); 272 272 273 - ds = dsa_switch_alloc(dev, MV88E6060_PORTS); 273 + ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL); 274 274 if (!ds) 275 275 return -ENOMEM; 276 276 277 + ds->dev = dev; 278 + ds->num_ports = MV88E6060_PORTS; 277 279 ds->priv = priv; 278 280 ds->dev = dev; 279 281 ds->ops = &mv88e6060_switch_ops;
+3 -1
drivers/net/dsa/mv88e6xxx/chip.c
··· 4978 4978 struct device *dev = chip->dev; 4979 4979 struct dsa_switch *ds; 4980 4980 4981 - ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip)); 4981 + ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL); 4982 4982 if (!ds) 4983 4983 return -ENOMEM; 4984 4984 4985 + ds->dev = dev; 4986 + ds->num_ports = mv88e6xxx_num_ports(chip); 4985 4987 ds->priv = chip; 4986 4988 ds->dev = dev; 4987 4989 ds->ops = &mv88e6xxx_switch_ops;
+4 -1
drivers/net/dsa/qca8k.c
··· 1077 1077 if (id != QCA8K_ID_QCA8337) 1078 1078 return -ENODEV; 1079 1079 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); 1081 1082 if (!priv->ds) 1082 1083 return -ENOMEM; 1083 1084 1085 + priv->ds->dev = &mdiodev->dev; 1086 + priv->ds->num_ports = DSA_MAX_PORTS; 1084 1087 priv->ds->priv = priv; 1085 1088 priv->ops = qca8k_switch_ops; 1086 1089 priv->ds->ops = &priv->ops;
+4 -1
drivers/net/dsa/realtek-smi-core.c
··· 444 444 return ret; 445 445 } 446 446 447 - smi->ds = dsa_switch_alloc(dev, smi->num_ports); 447 + smi->ds = devm_kzalloc(dev, sizeof(*smi->ds), GFP_KERNEL); 448 448 if (!smi->ds) 449 449 return -ENOMEM; 450 + 451 + smi->ds->dev = dev; 452 + smi->ds->num_ports = smi->num_ports; 450 453 smi->ds->priv = smi; 451 454 452 455 smi->ds->ops = var->ds_ops;
+3 -1
drivers/net/dsa/sja1105/sja1105_main.c
··· 2047 2047 2048 2048 dev_info(dev, "Probed switch chip: %s\n", priv->info->name); 2049 2049 2050 - ds = dsa_switch_alloc(dev, SJA1105_NUM_PORTS); 2050 + ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL); 2051 2051 if (!ds) 2052 2052 return -ENOMEM; 2053 2053 2054 + ds->dev = dev; 2055 + ds->num_ports = SJA1105_NUM_PORTS; 2054 2056 ds->ops = &sja1105_switch_ops; 2055 2057 ds->priv = priv; 2056 2058 priv->ds = ds;
+4 -1
drivers/net/dsa/vitesse-vsc73xx-core.c
··· 1178 1178 * We allocate 8 ports and avoid access to the nonexistant 1179 1179 * ports. 1180 1180 */ 1181 - vsc->ds = dsa_switch_alloc(dev, 8); 1181 + vsc->ds = devm_kzalloc(dev, sizeof(*vsc->ds), GFP_KERNEL); 1182 1182 if (!vsc->ds) 1183 1183 return -ENOMEM; 1184 + 1185 + vsc->ds->dev = dev; 1186 + vsc->ds->num_ports = 8; 1184 1187 vsc->ds->priv = vsc; 1185 1188 1186 1189 vsc->ds->ops = &vsc73xx_ds_ops;
-1
include/net/dsa.h
··· 577 577 return false; 578 578 } 579 579 580 - struct dsa_switch *dsa_switch_alloc(struct device *dev, size_t n); 581 580 void dsa_unregister_switch(struct dsa_switch *ds); 582 581 int dsa_register_switch(struct dsa_switch *ds); 583 582 #ifdef CONFIG_PM_SLEEP
+6 -15
net/dsa/dsa2.c
··· 846 846 struct device_node *np = ds->dev->of_node; 847 847 int err; 848 848 849 + if (!ds->dev) 850 + return -ENODEV; 851 + 852 + if (!ds->num_ports) 853 + return -EINVAL; 854 + 849 855 if (np) 850 856 err = dsa_switch_parse_of(ds, np); 851 857 else if (pdata) ··· 864 858 865 859 return dsa_switch_add(ds); 866 860 } 867 - 868 - struct dsa_switch *dsa_switch_alloc(struct device *dev, size_t n) 869 - { 870 - struct dsa_switch *ds; 871 - 872 - ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL); 873 - if (!ds) 874 - return NULL; 875 - 876 - ds->dev = dev; 877 - ds->num_ports = n; 878 - 879 - return ds; 880 - } 881 - EXPORT_SYMBOL_GPL(dsa_switch_alloc); 882 861 883 862 int dsa_register_switch(struct dsa_switch *ds) 884 863 {