Commit 454cfffe authored by Vladimir Oltean's avatar Vladimir Oltean Committed by David S. Miller

net: dsa: ocelot: use devres in ocelot_ext_probe()

Russell King suggested that felix_vsc9959, seville_vsc9953 and
ocelot_ext have a large portion of duplicated init and teardown code,
which could be made common [1]. The teardown code could even be
simplified away if we made use of devres, something which is used here
and there in the felix driver, just not very consistently.

[1] https://lore.kernel.org/all/Zh1GvcOTXqb7CpQt@shell.armlinux.org.uk/

Prepare the ground in the ocelot_ext driver, by allocating the data
structures using devres and deleting the kfree() calls. This also
deletes the "Failed to allocate ..." message, since memory allocation
errors are extremely loud anyway, and it's hard to miss them.
Suggested-by: default avatar"Russell King (Oracle)" <linux@armlinux.org.uk>
Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: default avatarColin Foster <colin.foster@in-advantage.com>
Tested-by: default avatarColin Foster <colin.foster@in-advantage.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 93e30878
...@@ -71,7 +71,7 @@ static int ocelot_ext_probe(struct platform_device *pdev) ...@@ -71,7 +71,7 @@ static int ocelot_ext_probe(struct platform_device *pdev)
struct felix *felix; struct felix *felix;
int err; int err;
felix = kzalloc(sizeof(*felix), GFP_KERNEL); felix = devm_kzalloc(dev, sizeof(*felix), GFP_KERNEL);
if (!felix) if (!felix)
return -ENOMEM; return -ENOMEM;
...@@ -84,12 +84,9 @@ static int ocelot_ext_probe(struct platform_device *pdev) ...@@ -84,12 +84,9 @@ static int ocelot_ext_probe(struct platform_device *pdev)
felix->info = &vsc7512_info; felix->info = &vsc7512_info;
ds = kzalloc(sizeof(*ds), GFP_KERNEL); ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
if (!ds) { if (!ds)
err = -ENOMEM; return -ENOMEM;
dev_err_probe(dev, err, "Failed to allocate DSA switch\n");
goto err_free_felix;
}
ds->dev = dev; ds->dev = dev;
ds->num_ports = felix->info->num_ports; ds->num_ports = felix->info->num_ports;
...@@ -102,17 +99,9 @@ static int ocelot_ext_probe(struct platform_device *pdev) ...@@ -102,17 +99,9 @@ static int ocelot_ext_probe(struct platform_device *pdev)
felix->tag_proto = DSA_TAG_PROTO_OCELOT; felix->tag_proto = DSA_TAG_PROTO_OCELOT;
err = dsa_register_switch(ds); err = dsa_register_switch(ds);
if (err) { if (err)
dev_err_probe(dev, err, "Failed to register DSA switch\n"); dev_err_probe(dev, err, "Failed to register DSA switch\n");
goto err_free_ds;
}
return 0;
err_free_ds:
kfree(ds);
err_free_felix:
kfree(felix);
return err; return err;
} }
...@@ -124,9 +113,6 @@ static void ocelot_ext_remove(struct platform_device *pdev) ...@@ -124,9 +113,6 @@ static void ocelot_ext_remove(struct platform_device *pdev)
return; return;
dsa_unregister_switch(felix->ds); dsa_unregister_switch(felix->ds);
kfree(felix->ds);
kfree(felix);
} }
static void ocelot_ext_shutdown(struct platform_device *pdev) static void ocelot_ext_shutdown(struct platform_device *pdev)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment