gianfar cleanups
v2 cover gianfar cleanups
Mostly devm adjustments and bugfixes along the way.
This was tested on a WatchGuard T10.
Rosen Penev (6):
v2: remove request_irq change. Fix NULL pointer deref with ofdev.
net: gianfar: use devm_alloc_etherdev_mqs
net: gianfar: use devm for register_netdev
net: gianfar: assign ofdev to priv struct
net: gianfar: remove free_gfar_dev
net: gianfar: alloc queues with devm
net: gianfar: iomap with devm
drivers/net/ethernet/freescale/gianfar.c | 93 +++++------------------- 1 file changed, 19 insertions(+), 74 deletions(-)
Signature · 1 line
2.47.0
PATCH v2 1/6 net: gianfar: use devm_alloc_etherdev_mqs
There seems to be a mistake here. There's a num_rx_qs variable that is not being passed to the allocation function. The mq variant just calls mqs with the last parameter of the former duplicated to the last parameter of the latter. That's fine if they match. Not sure they do.
Also avoids manual free_netdev
--- drivers/net/ethernet/freescale/gianfar.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/ethernet/freescale/gianfar.c +2 -3
@@ -475,8 +475,6 @@ static void free_gfar_dev(struct gfar_private *priv)kfree (priv->gfargrp[i].irqinfo[j]); priv->gfargrp[i].irqinfo[j] =NULL ; } - -free_netdev (priv->ndev); }static void disable_napi (struct gfar_private *priv)
@@ -681,7 +679,8 @@ static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev)return -EINVAL ; } - *pdev =alloc_etherdev_mq (sizeof (*priv), num_tx_qs); + *pdev =devm_alloc_etherdev_mqs (&ofdev->dev,sizeof (*priv), num_tx_qs, + num_rx_qs); dev = *pdev;if (NULL == dev)return -ENOMEM ;
Signature · 1 line
2.47.0
PATCH v2 2/6 net: gianfar: use devm for register_netdev
In reply to Rosen PenevAvoid manual unregister of netdev.
--- drivers/net/ethernet/freescale/gianfar.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/ethernet/freescale/gianfar.c +1 -3
@@ -3305,7 +3305,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);
@@ -3374,8 +3374,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);
Signature · 1 line
2.47.0
PATCH v2 3/6 net: gianfar: assign ofdev to priv struct
In reply to Rosen PenevThis is done in probe but not of_init. This will be used for further devm conversions.
--- drivers/net/ethernet/freescale/gianfar.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ethernet/freescale/gianfar.c +2 -0
@@ -687,6 +687,8 @@ static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev) priv =netdev_priv (dev); priv->ndev = dev; + priv->ofdev = ofdev; + priv->dev = &ofdev->dev; priv->mode = mode;
Signature · 1 line
2.47.0
PATCH v2 4/6 net: gianfar: remove free_gfar_dev
In reply to Rosen PenevUse devm for kzalloc. Allows to remove free_gfar_dev as devm handles freeing it now.
--- drivers/net/ethernet/freescale/gianfar.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-)
drivers/net/ethernet/freescale/gianfar.c +2 -16
@@ -466,17 +466,6 @@ static void unmap_group_regs(struct gfar_private *priv)iounmap (priv->gfargrp[i].regs); } -static void free_gfar_dev (struct gfar_private *priv) -{ -int i, j; - -for (i =0 ; i < priv->num_grps; i++) -for (j =0 ; j <GFAR_NUM_IRQS ; j++) { -kfree (priv->gfargrp[i].irqinfo[j]); - priv->gfargrp[i].irqinfo[j] =NULL ; - } -} -static void disable_napi (struct gfar_private *priv) {int i;
@@ -504,8 +493,8 @@ static int gfar_parse_group(struct device_node *np,int i;for (i =0 ; i <GFAR_NUM_IRQS ; i++) { - grp->irqinfo[i] =kzalloc (sizeof (struct gfar_irqinfo ), -GFP_KERNEL ); + grp->irqinfo[i] =devm_kzalloc ( + priv->dev,sizeof (struct gfar_irqinfo ),GFP_KERNEL );if (!grp->irqinfo[i])return -ENOMEM ; }
@@ -820,7 +809,6 @@ static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev)gfar_free_rx_queues (priv); tx_alloc_failed:gfar_free_tx_queues (priv); -free_gfar_dev (priv);return err; }
@@ -3364,7 +3352,6 @@ static int gfar_probe(struct platform_device *ofdev)gfar_free_tx_queues (priv);of_node_put (priv->phy_node);of_node_put (priv->tbi_node); -free_gfar_dev (priv);return err; }
@@ -3382,7 +3369,6 @@ static void gfar_remove(struct platform_device *ofdev)unmap_group_regs (priv);gfar_free_rx_queues (priv);gfar_free_tx_queues (priv); -free_gfar_dev (priv); }#ifdef CONFIG_PM
Signature · 1 line
2.47.0
PATCH v2 5/6 net: gianfar: alloc queues with devm
In reply to Rosen PenevRemove the freeing functions as they no longer serve a purpose. devm handles this automatically.
There seems to be a mistake here where free_tx_queue is called on failure. Just let devm deal with it.
--- drivers/net/ethernet/freescale/gianfar.c | 38 +++++------------------- 1 file changed, 7 insertions(+), 31 deletions(-)
drivers/net/ethernet/freescale/gianfar.c +7 -31
@@ -412,8 +412,8 @@ static int gfar_alloc_tx_queues(struct gfar_private *priv)int i;for (i =0 ; i < priv->num_tx_queues; i++) { - priv->tx_queue[i] =kzalloc (sizeof (struct gfar_priv_tx_q ), -GFP_KERNEL ); + priv->tx_queue[i] =devm_kzalloc ( + priv->dev,sizeof (struct gfar_priv_tx_q ),GFP_KERNEL );if (!priv->tx_queue[i])return -ENOMEM ;
@@ -430,8 +430,8 @@ static int gfar_alloc_rx_queues(struct gfar_private *priv)int i;for (i =0 ; i < priv->num_rx_queues; i++) { - priv->rx_queue[i] =kzalloc (sizeof (struct gfar_priv_rx_q ), -GFP_KERNEL ); + priv->rx_queue[i] =devm_kzalloc ( + priv->dev,sizeof (struct gfar_priv_rx_q ),GFP_KERNEL );if (!priv->rx_queue[i])return -ENOMEM ;
@@ -441,22 +441,6 @@ static int gfar_alloc_rx_queues(struct gfar_private *priv)return 0 ; } -static void gfar_free_tx_queues (struct gfar_private *priv) -{ -int i; - -for (i =0 ; i < priv->num_tx_queues; i++) -kfree (priv->tx_queue[i]); -} - -static void gfar_free_rx_queues (struct gfar_private *priv) -{ -int i; - -for (i =0 ; i < priv->num_rx_queues; i++) -kfree (priv->rx_queue[i]); -} -static void unmap_group_regs (struct gfar_private *priv) {int i;
@@ -687,16 +671,16 @@ static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev) err =gfar_alloc_tx_queues (priv);if (err) - goto tx_alloc_failed; +return err; err =gfar_alloc_rx_queues (priv);if (err) - goto rx_alloc_failed; +return err; err =of_property_read_string (np,"model" , &model);if (err) {pr_err ("Device model property missing, aborting\n" ); - goto rx_alloc_failed; +return err; }/* Init Rx queue filer rule set linked list */
@@ -805,10 +789,6 @@ static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev) err_grp_init:unmap_group_regs (priv); -rx_alloc_failed: -gfar_free_rx_queues (priv); -tx_alloc_failed: -gfar_free_tx_queues (priv);return err; }
@@ -3348,8 +3328,6 @@ static int gfar_probe(struct platform_device *ofdev)if (of_phy_is_fixed_link (np))of_phy_deregister_fixed_link (np);unmap_group_regs (priv); -gfar_free_rx_queues (priv); -gfar_free_tx_queues (priv);of_node_put (priv->phy_node);of_node_put (priv->tbi_node);return err;
@@ -3367,8 +3345,6 @@ static void gfar_remove(struct platform_device *ofdev)of_phy_deregister_fixed_link (np);unmap_group_regs (priv); -gfar_free_rx_queues (priv); -gfar_free_tx_queues (priv); }#ifdef CONFIG_PM
Signature · 1 line
2.47.0
PATCH v2 6/6 net: gianfar: iomap with devm
In reply to Rosen PenevRemove unmap_group_regs as it no longer served a purpose. devm can handle this automatically.
Remove gotos as they are no longer needed.
--- drivers/net/ethernet/freescale/gianfar.c | 26 +++++------------------- 1 file changed, 5 insertions(+), 21 deletions(-)
drivers/net/ethernet/freescale/gianfar.c +5 -21
@@ -441,15 +441,6 @@ static int gfar_alloc_rx_queues(struct gfar_private *priv)return 0 ; } -static void unmap_group_regs (struct gfar_private *priv) -{ -int i; - -for (i =0 ; i <MAXGROUPS ; i++) -if (priv->gfargrp[i].regs) -iounmap (priv->gfargrp[i].regs); -} -static void disable_napi (struct gfar_private *priv) {int i;
@@ -483,7 +474,7 @@ static int gfar_parse_group(struct device_node *np,return -ENOMEM ; } - grp->regs =of_iomap (np,0 ); + grp->regs =devm_of_iomap (priv->dev, np,0 ,NULL );if (!grp->regs)return -ENOMEM ;
@@ -700,13 +691,13 @@ static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev) err =gfar_parse_group (child, priv, model);if (err) {of_node_put (child); - goto err_grp_init; +return err; } } }else {/* SQ_SG_MODE */ err =gfar_parse_group (np, priv, model);if (err) - goto err_grp_init; +return err; }if (of_property_read_bool (np,"bd-stash" )) {
@@ -729,7 +720,7 @@ static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev) err =of_get_ethdev_address (np, dev);if (err == -EPROBE_DEFER ) - goto err_grp_init; +return err;if (err) {eth_hw_addr_random (dev);dev_info (&ofdev->dev,"Using random MAC address: %pM\n" , dev->dev_addr);
@@ -777,7 +768,7 @@ static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev)if (!priv->phy_node &&of_phy_is_fixed_link (np)) { err =of_phy_register_fixed_link (np);if (err) - goto err_grp_init; +return err; priv->phy_node =of_node_get (np); }
@@ -786,10 +777,6 @@ static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev) priv->tbi_node =of_parse_phandle (np,"tbi-handle" ,0 );return 0 ; - -err_grp_init: -unmap_group_regs (priv); -return err; } static u32 cluster_entry_per_class(struct gfar_private *priv, u32 rqfar,
@@ -3327,7 +3314,6 @@ static int gfar_probe(struct platform_device *ofdev) register_fail:if (of_phy_is_fixed_link (np))of_phy_deregister_fixed_link (np); -unmap_group_regs (priv);of_node_put (priv->phy_node);of_node_put (priv->tbi_node);return err;
@@ -3343,8 +3329,6 @@ static void gfar_remove(struct platform_device *ofdev)if (of_phy_is_fixed_link (np))of_phy_deregister_fixed_link (np); - -unmap_group_regs (priv); }#ifdef CONFIG_PM
Signature · 1 line
2.47.0
Quoted 3 lines · Rosen Penev
Mostly devm adjustments and bugfixes along the way.
This was tested on a WatchGuard T10.
FYI net-next is closed
https://lore.kernel.org/netdev/[email protected]/
So this series can be submit as an RFC or re-submit in a couple weeks.
Quoted 4 lines · Joe Damato
Quoted 2 lines · Rosen Penev
Mostly devm adjustments and bugfixes along the way.
Quoted 8 lines
Quoted 1 line
This was tested on a WatchGuard T10.
FYI net-next is closed
https://lore.kernel.org/netdev/[email protected]/
So this series can be submit as an RFC or re-submit in a couple weeks.
Ah missed. it. Will resend eventually.