diff mbox series

[net,1/1] net: dsa: sja1105: fix error handling on NULL returned by xpcs_create()

Message ID 20210810063513.1757614-1-vee.khee.wong@linux.intel.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net,1/1] net: dsa: sja1105: fix error handling on NULL returned by xpcs_create() | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net
netdev/subject_prefix success Link
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link

Commit Message

Wong Vee Khee Aug. 10, 2021, 6:35 a.m. UTC
There is a possibility xpcs_create() returned a NULL and this is not
handled properly in the sja1105 driver.

Fixed this by using IS_ERR_ON_NULL() instead of IS_ERR().

Fixes: 3ad1d171548e ("net: dsa: sja1105: migrate to xpcs for SGMII")
Cc: Vladimir Olten <vladimir.oltean@nxp.com>
Signed-off-by: Wong Vee Khee <vee.khee.wong@linux.intel.com>
---
 drivers/net/dsa/sja1105/sja1105_mdio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Vladimir Oltean Aug. 10, 2021, 8:25 a.m. UTC | #1
Hi VK,

On Tue, Aug 10, 2021 at 02:35:13PM +0800, Wong Vee Khee wrote:
> There is a possibility xpcs_create() returned a NULL and this is not
> handled properly in the sja1105 driver.
> 
> Fixed this by using IS_ERR_ON_NULL() instead of IS_ERR().
> 
> Fixes: 3ad1d171548e ("net: dsa: sja1105: migrate to xpcs for SGMII")
> Cc: Vladimir Olten <vladimir.oltean@nxp.com>
> Signed-off-by: Wong Vee Khee <vee.khee.wong@linux.intel.com>
> ---
>  drivers/net/dsa/sja1105/sja1105_mdio.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/dsa/sja1105/sja1105_mdio.c b/drivers/net/dsa/sja1105/sja1105_mdio.c
> index 19aea8fb76f6..2c69a759ce6e 100644
> --- a/drivers/net/dsa/sja1105/sja1105_mdio.c
> +++ b/drivers/net/dsa/sja1105/sja1105_mdio.c
> @@ -438,7 +438,7 @@ static int sja1105_mdiobus_pcs_register(struct sja1105_private *priv)
>  		}
>  
>  		xpcs = xpcs_create(mdiodev, priv->phy_mode[port]);
> -		if (IS_ERR(xpcs)) {
> +		if (IS_ERR_OR_NULL(xpcs)) {
>  			rc = PTR_ERR(xpcs);
>  			goto out_pcs_free;
>  		}
> -- 
> 2.25.1
> 

I think posting to 'net' is a bit drastic for this patch. I agree it is
an issue but it has bothered absolutely nobody so far, and if sending
this patch to 'net' means you'll be blocked with your patches until the
'net'->'net-next' merge, I'm not sure it's worth it.

Anyway, I don't think that PTR_ERR(xpcs) does the right thing when
IS_NULL(xpcs). So how about you make this change:

-----------------------------[ cut here ]-----------------------------
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
index a5d150c5f3d8..ca12bf986d4d 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
@@ -415,7 +415,7 @@ int stmmac_xpcs_setup(struct mii_bus *bus)
 			continue;
 
 		xpcs = xpcs_create(mdiodev, mode);
-		if (IS_ERR_OR_NULL(xpcs)) {
+		if (IS_ERR(xpcs)) {
 			mdio_device_free(mdiodev);
 			continue;
 		}
diff --git a/drivers/net/pcs/pcs-xpcs.c b/drivers/net/pcs/pcs-xpcs.c
index 63fda3fc40aa..4bd61339823c 100644
--- a/drivers/net/pcs/pcs-xpcs.c
+++ b/drivers/net/pcs/pcs-xpcs.c
@@ -1089,7 +1089,7 @@ struct dw_xpcs *xpcs_create(struct mdio_device *mdiodev,
 
 	xpcs = kzalloc(sizeof(*xpcs), GFP_KERNEL);
 	if (!xpcs)
-		return NULL;
+		return ERR_PTR(-ENOMEM);
 
 	xpcs->mdiodev = mdiodev;
 
-----------------------------[ cut here ]-----------------------------
Wong Vee Khee Aug. 10, 2021, 8:33 a.m. UTC | #2
On Tue, Aug 10, 2021 at 08:25:29AM +0000, Vladimir Oltean wrote:
> Hi VK,
> 
> On Tue, Aug 10, 2021 at 02:35:13PM +0800, Wong Vee Khee wrote:
> > There is a possibility xpcs_create() returned a NULL and this is not
> > handled properly in the sja1105 driver.
> > 
> > Fixed this by using IS_ERR_ON_NULL() instead of IS_ERR().
> > 
> > Fixes: 3ad1d171548e ("net: dsa: sja1105: migrate to xpcs for SGMII")
> > Cc: Vladimir Olten <vladimir.oltean@nxp.com>
> > Signed-off-by: Wong Vee Khee <vee.khee.wong@linux.intel.com>
> > ---
> >  drivers/net/dsa/sja1105/sja1105_mdio.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/net/dsa/sja1105/sja1105_mdio.c b/drivers/net/dsa/sja1105/sja1105_mdio.c
> > index 19aea8fb76f6..2c69a759ce6e 100644
> > --- a/drivers/net/dsa/sja1105/sja1105_mdio.c
> > +++ b/drivers/net/dsa/sja1105/sja1105_mdio.c
> > @@ -438,7 +438,7 @@ static int sja1105_mdiobus_pcs_register(struct sja1105_private *priv)
> >  		}
> >  
> >  		xpcs = xpcs_create(mdiodev, priv->phy_mode[port]);
> > -		if (IS_ERR(xpcs)) {
> > +		if (IS_ERR_OR_NULL(xpcs)) {
> >  			rc = PTR_ERR(xpcs);
> >  			goto out_pcs_free;
> >  		}
> > -- 
> > 2.25.1
> > 
> 
> I think posting to 'net' is a bit drastic for this patch. I agree it is
> an issue but it has bothered absolutely nobody so far, and if sending
> this patch to 'net' means you'll be blocked with your patches until the
> 'net'->'net-next' merge, I'm not sure it's worth it.
>

Sounds reasonable for me. I will marked V2 to target net-next.
 
> Anyway, I don't think that PTR_ERR(xpcs) does the right thing when
> IS_NULL(xpcs). So how about you make this change:
> 
> -----------------------------[ cut here ]-----------------------------
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> index a5d150c5f3d8..ca12bf986d4d 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> @@ -415,7 +415,7 @@ int stmmac_xpcs_setup(struct mii_bus *bus)
>  			continue;
>  
>  		xpcs = xpcs_create(mdiodev, mode);
> -		if (IS_ERR_OR_NULL(xpcs)) {
> +		if (IS_ERR(xpcs)) {
>  			mdio_device_free(mdiodev);
>  			continue;
>  		}
> diff --git a/drivers/net/pcs/pcs-xpcs.c b/drivers/net/pcs/pcs-xpcs.c
> index 63fda3fc40aa..4bd61339823c 100644
> --- a/drivers/net/pcs/pcs-xpcs.c
> +++ b/drivers/net/pcs/pcs-xpcs.c
> @@ -1089,7 +1089,7 @@ struct dw_xpcs *xpcs_create(struct mdio_device *mdiodev,
>  
>  	xpcs = kzalloc(sizeof(*xpcs), GFP_KERNEL);
>  	if (!xpcs)
> -		return NULL;
> +		return ERR_PTR(-ENOMEM);
>  
>  	xpcs->mdiodev = mdiodev;
>  
> -----------------------------[ cut here ]-----------------------------
diff mbox series

Patch

diff --git a/drivers/net/dsa/sja1105/sja1105_mdio.c b/drivers/net/dsa/sja1105/sja1105_mdio.c
index 19aea8fb76f6..2c69a759ce6e 100644
--- a/drivers/net/dsa/sja1105/sja1105_mdio.c
+++ b/drivers/net/dsa/sja1105/sja1105_mdio.c
@@ -438,7 +438,7 @@  static int sja1105_mdiobus_pcs_register(struct sja1105_private *priv)
 		}
 
 		xpcs = xpcs_create(mdiodev, priv->phy_mode[port]);
-		if (IS_ERR(xpcs)) {
+		if (IS_ERR_OR_NULL(xpcs)) {
 			rc = PTR_ERR(xpcs);
 			goto out_pcs_free;
 		}