diff mbox series

ixp4xx_eth: Fix an error handling path in ixp4xx_eth_probe()

Message ID 3ab37c3934c99066a124f99e73c0fc077fcb69b4.1671607040.git.christophe.jaillet@wanadoo.fr (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series ixp4xx_eth: Fix an error handling path in ixp4xx_eth_probe() | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch fail ERROR: do not use assignment in if condition
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Christophe JAILLET Dec. 21, 2022, 7:17 a.m. UTC
If an error occurs after a successful ixp4xx_mdio_register() call, it
should be undone by a corresponding ixp4xx_mdio_remove().

Add the missing call in the error handling path, as already done in the
remove function.

Fixes: 2098c18d6cf6 ("IXP4xx: Add PHYLIB support to Ethernet driver.")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/net/ethernet/xscale/ixp4xx_eth.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Michal Swiatkowski Dec. 21, 2022, 6:50 p.m. UTC | #1
On Wed, Dec 21, 2022 at 08:17:52AM +0100, Christophe JAILLET wrote:
> If an error occurs after a successful ixp4xx_mdio_register() call, it
> should be undone by a corresponding ixp4xx_mdio_remove().

What about error when mdio_bus is 0? It means that mdio_register can
return no error, but sth happen and there is no need to call mdio_remove
in this case?

I mean:
 /* If the instance with the MDIO bus has not yet appeared,
  * defer probing until it gets probed.
  */
  if (!mdio_bus)
	return -EPROBE_DEFER;
> 
> Add the missing call in the error handling path, as already done in the
> remove function.
> 
> Fixes: 2098c18d6cf6 ("IXP4xx: Add PHYLIB support to Ethernet driver.")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
>  drivers/net/ethernet/xscale/ixp4xx_eth.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/xscale/ixp4xx_eth.c b/drivers/net/ethernet/xscale/ixp4xx_eth.c
> index 3b0c5f177447..007d68b385a5 100644
> --- a/drivers/net/ethernet/xscale/ixp4xx_eth.c
> +++ b/drivers/net/ethernet/xscale/ixp4xx_eth.c
> @@ -1490,8 +1490,10 @@ static int ixp4xx_eth_probe(struct platform_device *pdev)
>  
>  	netif_napi_add_weight(ndev, &port->napi, eth_poll, NAPI_WEIGHT);
netif_napi_add_weight() doesn't need to be unrolled in case of error
(call netif_napi_del() or something)?

Thanks

>  
> -	if (!(port->npe = npe_request(NPE_ID(port->id))))
> -		return -EIO;
> +	if (!(port->npe = npe_request(NPE_ID(port->id)))) {
> +		err = -EIO;
> +		goto err_remove_mdio;
> +	}
>  
>  	port->plat = plat;
>  	npe_port_tab[NPE_ID(port->id)] = port;
> @@ -1530,6 +1532,8 @@ static int ixp4xx_eth_probe(struct platform_device *pdev)
>  err_free_mem:
>  	npe_port_tab[NPE_ID(port->id)] = NULL;
>  	npe_release(port->npe);
> +err_remove_mdio:
> +	ixp4xx_mdio_remove();
>  	return err;
>  }
>  
> -- 
> 2.34.1
>
Jakub Kicinski Dec. 22, 2022, 1:38 a.m. UTC | #2
On Wed, 21 Dec 2022 19:50:23 +0100 Michal Swiatkowski wrote:
> On Wed, Dec 21, 2022 at 08:17:52AM +0100, Christophe JAILLET wrote:
> > If an error occurs after a successful ixp4xx_mdio_register() call, it
> > should be undone by a corresponding ixp4xx_mdio_remove().  
> 
> What about error when mdio_bus is 0? It means that mdio_register can
> return no error, but sth happen and there is no need to call mdio_remove
> in this case?
> 
> I mean:
>  /* If the instance with the MDIO bus has not yet appeared,
>   * defer probing until it gets probed.
>   */
>   if (!mdio_bus)
> 	return -EPROBE_DEFER;

Indeed, I think a closer look is warranted, this code operates on
global variables, it's also not clear to me whether it's safe to always
call remove, even if has_mdio is false?

> > Add the missing call in the error handling path, as already done in the
> > remove function.
> > 
> > Fixes: 2098c18d6cf6 ("IXP4xx: Add PHYLIB support to Ethernet driver.")
> > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> > ---
> >  drivers/net/ethernet/xscale/ixp4xx_eth.c | 8 ++++++--
> >  1 file changed, 6 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/net/ethernet/xscale/ixp4xx_eth.c b/drivers/net/ethernet/xscale/ixp4xx_eth.c
> > index 3b0c5f177447..007d68b385a5 100644
> > --- a/drivers/net/ethernet/xscale/ixp4xx_eth.c
> > +++ b/drivers/net/ethernet/xscale/ixp4xx_eth.c
> > @@ -1490,8 +1490,10 @@ static int ixp4xx_eth_probe(struct platform_device *pdev)
> >  
> >  	netif_napi_add_weight(ndev, &port->napi, eth_poll, NAPI_WEIGHT);  
> netif_napi_add_weight() doesn't need to be unrolled in case of error
> (call netif_napi_del() or something)?

free_netdev() cleans it up automatically
diff mbox series

Patch

diff --git a/drivers/net/ethernet/xscale/ixp4xx_eth.c b/drivers/net/ethernet/xscale/ixp4xx_eth.c
index 3b0c5f177447..007d68b385a5 100644
--- a/drivers/net/ethernet/xscale/ixp4xx_eth.c
+++ b/drivers/net/ethernet/xscale/ixp4xx_eth.c
@@ -1490,8 +1490,10 @@  static int ixp4xx_eth_probe(struct platform_device *pdev)
 
 	netif_napi_add_weight(ndev, &port->napi, eth_poll, NAPI_WEIGHT);
 
-	if (!(port->npe = npe_request(NPE_ID(port->id))))
-		return -EIO;
+	if (!(port->npe = npe_request(NPE_ID(port->id)))) {
+		err = -EIO;
+		goto err_remove_mdio;
+	}
 
 	port->plat = plat;
 	npe_port_tab[NPE_ID(port->id)] = port;
@@ -1530,6 +1532,8 @@  static int ixp4xx_eth_probe(struct platform_device *pdev)
 err_free_mem:
 	npe_port_tab[NPE_ID(port->id)] = NULL;
 	npe_release(port->npe);
+err_remove_mdio:
+	ixp4xx_mdio_remove();
 	return err;
 }