diff mbox series

[net-next,1/8] net: dsa: ocelot: use devres in ocelot_ext_probe()

Message ID 20240530163333.2458884-2-vladimir.oltean@nxp.com (mailing list archive)
State Accepted
Commit 454cfffe8dc112f1ed3966923f5dccdafa3bebf2
Delegated to: Netdev Maintainers
Headers show
Series Probing cleanup for the Felix DSA driver | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 902 this patch: 902
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 11 of 11 maintainers
netdev/build_clang success Errors and warnings before: 906 this patch: 906
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 906 this patch: 906
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 50 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-05-31--03-00 (tests: 1040)

Commit Message

Vladimir Oltean May 30, 2024, 4:33 p.m. UTC
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: "Russell King (Oracle)" <linux@armlinux.org.uk>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 drivers/net/dsa/ocelot/ocelot_ext.c | 24 +++++-------------------
 1 file changed, 5 insertions(+), 19 deletions(-)

Comments

Colin Foster May 30, 2024, 4:40 p.m. UTC | #1
Reviewed-by: Colin Foster <colin.foster@in-advantage.com>

On Thu, May 30, 2024 at 07:33:26PM +0300, Vladimir Oltean wrote:
> 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: "Russell King (Oracle)" <linux@armlinux.org.uk>
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
> ---
>  drivers/net/dsa/ocelot/ocelot_ext.c | 24 +++++-------------------
>  1 file changed, 5 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/net/dsa/ocelot/ocelot_ext.c b/drivers/net/dsa/ocelot/ocelot_ext.c
> index a8927dc7aca4..c893f3ee238b 100644
> --- a/drivers/net/dsa/ocelot/ocelot_ext.c
> +++ b/drivers/net/dsa/ocelot/ocelot_ext.c
> @@ -71,7 +71,7 @@ static int ocelot_ext_probe(struct platform_device *pdev)
>  	struct felix *felix;
>  	int err;
>  
> -	felix = kzalloc(sizeof(*felix), GFP_KERNEL);
> +	felix = devm_kzalloc(dev, sizeof(*felix), GFP_KERNEL);
>  	if (!felix)
>  		return -ENOMEM;
>  
> @@ -84,12 +84,9 @@ static int ocelot_ext_probe(struct platform_device *pdev)
>  
>  	felix->info = &vsc7512_info;
>  
> -	ds = kzalloc(sizeof(*ds), GFP_KERNEL);
> -	if (!ds) {
> -		err = -ENOMEM;
> -		dev_err_probe(dev, err, "Failed to allocate DSA switch\n");
> -		goto err_free_felix;
> -	}
> +	ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
> +	if (!ds)
> +		return -ENOMEM;
>  
>  	ds->dev = dev;
>  	ds->num_ports = felix->info->num_ports;
> @@ -102,17 +99,9 @@ static int ocelot_ext_probe(struct platform_device *pdev)
>  	felix->tag_proto = DSA_TAG_PROTO_OCELOT;
>  
>  	err = dsa_register_switch(ds);
> -	if (err) {
> +	if (err)
>  		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;
>  }
>  
> @@ -124,9 +113,6 @@ static void ocelot_ext_remove(struct platform_device *pdev)
>  		return;
>  
>  	dsa_unregister_switch(felix->ds);
> -
> -	kfree(felix->ds);
> -	kfree(felix);
>  }
>  
>  static void ocelot_ext_shutdown(struct platform_device *pdev)
> -- 
> 2.34.1
>
Colin Foster June 3, 2024, 2 a.m. UTC | #2
On Thu, May 30, 2024 at 07:33:26PM +0300, Vladimir Oltean wrote:
> 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: "Russell King (Oracle)" <linux@armlinux.org.uk>
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
> ---
>  drivers/net/dsa/ocelot/ocelot_ext.c | 24 +++++-------------------
> 1 file changed, 5 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/net/dsa/ocelot/ocelot_ext.c b/drivers/net/dsa/ocelot/ocelot_ext.c
> index a8927dc7aca4..c893f3ee238b 100644
> --- a/drivers/net/dsa/ocelot/ocelot_ext.c
> +++ b/drivers/net/dsa/ocelot/ocelot_ext.c

I found my issue and was able to test the series.

Tested-by: Colin Foster <colin.foster@in-advantage.com>
Vladimir Oltean June 3, 2024, 11:01 a.m. UTC | #3
On Sun, Jun 02, 2024 at 09:00:01PM -0500, Colin Foster wrote:
> On Thu, May 30, 2024 at 07:33:26PM +0300, Vladimir Oltean wrote:
> > 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: "Russell King (Oracle)" <linux@armlinux.org.uk>
> > Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
> > ---
> >  drivers/net/dsa/ocelot/ocelot_ext.c | 24 +++++-------------------
> > 1 file changed, 5 insertions(+), 19 deletions(-)
> > 
> > diff --git a/drivers/net/dsa/ocelot/ocelot_ext.c b/drivers/net/dsa/ocelot/ocelot_ext.c
> > index a8927dc7aca4..c893f3ee238b 100644
> > --- a/drivers/net/dsa/ocelot/ocelot_ext.c
> > +++ b/drivers/net/dsa/ocelot/ocelot_ext.c
> 
> I found my issue and was able to test the series.
> 
> Tested-by: Colin Foster <colin.foster@in-advantage.com>

Thanks for testing, Colin.
diff mbox series

Patch

diff --git a/drivers/net/dsa/ocelot/ocelot_ext.c b/drivers/net/dsa/ocelot/ocelot_ext.c
index a8927dc7aca4..c893f3ee238b 100644
--- a/drivers/net/dsa/ocelot/ocelot_ext.c
+++ b/drivers/net/dsa/ocelot/ocelot_ext.c
@@ -71,7 +71,7 @@  static int ocelot_ext_probe(struct platform_device *pdev)
 	struct felix *felix;
 	int err;
 
-	felix = kzalloc(sizeof(*felix), GFP_KERNEL);
+	felix = devm_kzalloc(dev, sizeof(*felix), GFP_KERNEL);
 	if (!felix)
 		return -ENOMEM;
 
@@ -84,12 +84,9 @@  static int ocelot_ext_probe(struct platform_device *pdev)
 
 	felix->info = &vsc7512_info;
 
-	ds = kzalloc(sizeof(*ds), GFP_KERNEL);
-	if (!ds) {
-		err = -ENOMEM;
-		dev_err_probe(dev, err, "Failed to allocate DSA switch\n");
-		goto err_free_felix;
-	}
+	ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
+	if (!ds)
+		return -ENOMEM;
 
 	ds->dev = dev;
 	ds->num_ports = felix->info->num_ports;
@@ -102,17 +99,9 @@  static int ocelot_ext_probe(struct platform_device *pdev)
 	felix->tag_proto = DSA_TAG_PROTO_OCELOT;
 
 	err = dsa_register_switch(ds);
-	if (err) {
+	if (err)
 		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;
 }
 
@@ -124,9 +113,6 @@  static void ocelot_ext_remove(struct platform_device *pdev)
 		return;
 
 	dsa_unregister_switch(felix->ds);
-
-	kfree(felix->ds);
-	kfree(felix);
 }
 
 static void ocelot_ext_shutdown(struct platform_device *pdev)