diff mbox series

[net-next,4/6] net: gianfar: use devm for register_netdev

Message ID 20241001212204.308758-5-rosenp@gmail.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series gianfar cleanups | 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: 9 this patch: 9
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 9 this patch: 9
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 fail Errors and warnings before: 12 this patch: 12
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 16 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

Commit Message

Rosen Penev Oct. 1, 2024, 9:22 p.m. UTC
Avoids manual unregister netdev.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/net/ethernet/freescale/gianfar.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Comments

Maxime Chevallier Oct. 2, 2024, 7:29 a.m. UTC | #1
Hi,

On Tue,  1 Oct 2024 14:22:02 -0700
Rosen Penev <rosenp@gmail.com> wrote:

> Avoids manual unregister netdev.
> 
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
>  drivers/net/ethernet/freescale/gianfar.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/net/ethernet/freescale/gianfar.c b/drivers/net/ethernet/freescale/gianfar.c
> index 66818d63cced..07936dccc389 100644
> --- a/drivers/net/ethernet/freescale/gianfar.c
> +++ b/drivers/net/ethernet/freescale/gianfar.c
> @@ -3272,7 +3272,7 @@ static int gfar_probe(struct platform_device *ofdev)
>  	/* Carrier starts down, phylib will bring it up */
>  	netif_carrier_off(dev);
>  
> -	err = register_netdev(dev);
> +	err = devm_register_netdev(&ofdev->dev, dev);

I wonder if this is not a good opportunity to also move the
registration at the end of this function. Here, the netdev is
registered but some configuration is still being done afterwards, such
as WoL init and internal filter configuration.

There's the ever so slightly chance that traffic can start flowing
before these filters are configured, which could lead to unexpected
side effects. We usually register the netdev as a very last step, once
all initial configuration is done and the device is ready to be used.

As you're doing some cleanup on the registration code itself, it seems
like a good opportunity to change that.

Thanks,

Maxime
Rosen Penev Oct. 2, 2024, 7:40 p.m. UTC | #2
On Wed, Oct 2, 2024 at 12:29 AM Maxime Chevallier
<maxime.chevallier@bootlin.com> wrote:
>
> Hi,
>
> On Tue,  1 Oct 2024 14:22:02 -0700
> Rosen Penev <rosenp@gmail.com> wrote:
>
> > Avoids manual unregister netdev.
> >
> > Signed-off-by: Rosen Penev <rosenp@gmail.com>
> > ---
> >  drivers/net/ethernet/freescale/gianfar.c | 4 +---
> >  1 file changed, 1 insertion(+), 3 deletions(-)
> >
> > diff --git a/drivers/net/ethernet/freescale/gianfar.c b/drivers/net/ethernet/freescale/gianfar.c
> > index 66818d63cced..07936dccc389 100644
> > --- a/drivers/net/ethernet/freescale/gianfar.c
> > +++ b/drivers/net/ethernet/freescale/gianfar.c
> > @@ -3272,7 +3272,7 @@ static int gfar_probe(struct platform_device *ofdev)
> >       /* Carrier starts down, phylib will bring it up */
> >       netif_carrier_off(dev);
> >
> > -     err = register_netdev(dev);
> > +     err = devm_register_netdev(&ofdev->dev, dev);
>
> I wonder if this is not a good opportunity to also move the
> registration at the end of this function. Here, the netdev is
> registered but some configuration is still being done afterwards, such
> as WoL init and internal filter configuration.
>
> There's the ever so slightly chance that traffic can start flowing
> before these filters are configured, which could lead to unexpected
> side effects. We usually register the netdev as a very last step, once
> all initial configuration is done and the device is ready to be used.
>
> As you're doing some cleanup on the registration code itself, it seems
> like a good opportunity to change that.
There seem to be a bunch of netdev_info calls. I assume those need a
registered netdev.

Additionally, the irqs are allocated in _open instead of _probe. I
assume those would need to be moved.
>
> Thanks,
>
> Maxime
>
>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/freescale/gianfar.c b/drivers/net/ethernet/freescale/gianfar.c
index 66818d63cced..07936dccc389 100644
--- a/drivers/net/ethernet/freescale/gianfar.c
+++ b/drivers/net/ethernet/freescale/gianfar.c
@@ -3272,7 +3272,7 @@  static int gfar_probe(struct platform_device *ofdev)
 	/* Carrier starts down, phylib will bring it up */
 	netif_carrier_off(dev);
 
-	err = register_netdev(dev);
+	err = devm_register_netdev(&ofdev->dev, dev);
 
 	if (err) {
 		pr_err("%s: Cannot register net device, aborting\n", dev->name);
@@ -3338,8 +3338,6 @@  static void gfar_remove(struct platform_device *ofdev)
 	of_node_put(priv->phy_node);
 	of_node_put(priv->tbi_node);
 
-	unregister_netdev(priv->ndev);
-
 	if (of_phy_is_fixed_link(np))
 		of_phy_deregister_fixed_link(np);