netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Colin Foster <colin.foster@in-advantage.com>
To: Vladimir Oltean <vladimir.oltean@nxp.com>
Cc: netdev@vger.kernel.org, "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Claudiu Manoil <claudiu.manoil@nxp.com>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	UNGLinuxDriver@microchip.com, Andrew Lunn <andrew@lunn.ch>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Russell King <linux@armlinux.org.uk>
Subject: Re: [PATCH net-next 1/8] net: dsa: ocelot: use devres in ocelot_ext_probe()
Date: Thu, 30 May 2024 11:40:43 -0500	[thread overview]
Message-ID: <ZlisCyAh9LtfcYgv@colin-ia-desktop> (raw)
In-Reply-To: <20240530163333.2458884-2-vladimir.oltean@nxp.com>

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
> 

  reply	other threads:[~2024-05-30 16:40 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-30 16:33 [PATCH net-next 0/8] Probing cleanup for the Felix DSA driver Vladimir Oltean
2024-05-30 16:33 ` [PATCH net-next 1/8] net: dsa: ocelot: use devres in ocelot_ext_probe() Vladimir Oltean
2024-05-30 16:40   ` Colin Foster [this message]
2024-06-03  2:00   ` Colin Foster
2024-06-03 11:01     ` Vladimir Oltean
2024-05-30 16:33 ` [PATCH net-next 2/8] net: dsa: ocelot: use devres in seville_probe() Vladimir Oltean
2024-05-30 16:33 ` [PATCH net-next 3/8] net: dsa: ocelot: delete open coded status = "disabled" parsing Vladimir Oltean
2024-05-30 16:33 ` [PATCH net-next 4/8] net: dsa: ocelot: consistently use devres in felix_pci_probe() Vladimir Oltean
2024-05-30 16:33 ` [PATCH net-next 5/8] net: dsa: ocelot: move devm_request_threaded_irq() to felix_setup() Vladimir Oltean
2024-05-30 16:33 ` [PATCH net-next 6/8] net: dsa: ocelot: use ds->num_tx_queues = OCELOT_NUM_TC for all models Vladimir Oltean
2024-05-30 16:47   ` Colin Foster
2024-06-03  2:02   ` Colin Foster
2024-05-30 16:33 ` [PATCH net-next 7/8] net: dsa: ocelot: common probing code Vladimir Oltean
2024-06-03  2:04   ` Colin Foster
2024-05-30 16:33 ` [PATCH net-next 8/8] net: dsa: ocelot: unexport felix_phylink_mac_ops and felix_switch_ops Vladimir Oltean
2024-05-30 18:12   ` Sai Krishna Gajula
2024-05-31  3:08 ` [PATCH net-next 0/8] Probing cleanup for the Felix DSA driver Colin Foster
2024-05-31  7:47   ` Russell King (Oracle)
2024-06-03 12:10 ` patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZlisCyAh9LtfcYgv@colin-ia-desktop \
    --to=colin.foster@in-advantage.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=andrew@lunn.ch \
    --cc=claudiu.manoil@nxp.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=f.fainelli@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=vladimir.oltean@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).