[PATCH v1 net-next 2/2] net: mscc: ocelot: check return values of writes during reset

Colin Foster posted 2 patches 3 years, 6 months ago
There is a newer version of this series
[PATCH v1 net-next 2/2] net: mscc: ocelot: check return values of writes during reset
Posted by Colin Foster 3 years, 6 months ago
The ocelot_reset() function utilizes regmap_field_write() but wasn't
checking return values. While this won't cause issues for the current MMIO
regmaps, it could be an issue for externally controlled interfaces.

Add checks for these return values.

Signed-off-by: Colin Foster <colin.foster@in-advantage.com>
---
 drivers/net/ethernet/mscc/ocelot_vsc7514.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/mscc/ocelot_vsc7514.c b/drivers/net/ethernet/mscc/ocelot_vsc7514.c
index 79b7af36b4f4..415b7f4c7277 100644
--- a/drivers/net/ethernet/mscc/ocelot_vsc7514.c
+++ b/drivers/net/ethernet/mscc/ocelot_vsc7514.c
@@ -211,8 +211,13 @@ static int ocelot_reset(struct ocelot *ocelot)
 	int err;
 	u32 val;
 
-	regmap_field_write(ocelot->regfields[SYS_RESET_CFG_MEM_INIT], 1);
-	regmap_field_write(ocelot->regfields[SYS_RESET_CFG_MEM_ENA], 1);
+	err = regmap_field_write(ocelot->regfields[SYS_RESET_CFG_MEM_INIT], 1);
+	if (err)
+		return err;
+
+	err = regmap_field_write(ocelot->regfields[SYS_RESET_CFG_MEM_ENA], 1);
+	if (err)
+		return err;
 
 	/* MEM_INIT is a self-clearing bit. Wait for it to be cleared (should be
 	 * 100us) before enabling the switch core.
@@ -222,10 +227,13 @@ static int ocelot_reset(struct ocelot *ocelot)
 	if (IS_ERR_VALUE(err))
 		return err;
 
-	regmap_field_write(ocelot->regfields[SYS_RESET_CFG_MEM_ENA], 1);
-	regmap_field_write(ocelot->regfields[SYS_RESET_CFG_CORE_ENA], 1);
+	err = regmap_field_write(ocelot->regfields[SYS_RESET_CFG_MEM_ENA], 1);
+	if (err)
+		return err;
 
-	return 0;
+	err = regmap_field_write(ocelot->regfields[SYS_RESET_CFG_CORE_ENA], 1);
+
+	return err;
 }
 
 /* Watermark encode
-- 
2.25.1
Re: [PATCH v1 net-next 2/2] net: mscc: ocelot: check return values of writes during reset
Posted by Vladimir Oltean 3 years, 6 months ago
On Fri, Sep 16, 2022 at 12:13:49PM -0700, Colin Foster wrote:
> -	regmap_field_write(ocelot->regfields[SYS_RESET_CFG_MEM_ENA], 1);
> -	regmap_field_write(ocelot->regfields[SYS_RESET_CFG_CORE_ENA], 1);
> +	err = regmap_field_write(ocelot->regfields[SYS_RESET_CFG_MEM_ENA], 1);
> +	if (err)
> +		return err;
>  
> -	return 0;
> +	err = regmap_field_write(ocelot->regfields[SYS_RESET_CFG_CORE_ENA], 1);
> +
> +	return err;
>  }

A kernel janitor will come and patch this up to:

	return regmap_field_write(ocelot->regfields[SYS_RESET_CFG_CORE_ENA], 1);

so it's better to do it yourself.
Re: [PATCH v1 net-next 2/2] net: mscc: ocelot: check return values of writes during reset
Posted by Colin Foster 3 years, 6 months ago
On Fri, Sep 16, 2022 at 10:40:10PM +0000, Vladimir Oltean wrote:
> On Fri, Sep 16, 2022 at 12:13:49PM -0700, Colin Foster wrote:
> > -	regmap_field_write(ocelot->regfields[SYS_RESET_CFG_MEM_ENA], 1);
> > -	regmap_field_write(ocelot->regfields[SYS_RESET_CFG_CORE_ENA], 1);
> > +	err = regmap_field_write(ocelot->regfields[SYS_RESET_CFG_MEM_ENA], 1);
> > +	if (err)
> > +		return err;
> >  
> > -	return 0;
> > +	err = regmap_field_write(ocelot->regfields[SYS_RESET_CFG_CORE_ENA], 1);
> > +
> > +	return err;
> >  }
> 
> A kernel janitor will come and patch this up to:
> 
> 	return regmap_field_write(ocelot->regfields[SYS_RESET_CFG_CORE_ENA], 1);
> 
> so it's better to do it yourself.

Good catch. That and removing the IS_ERR_VALUE macro from patch 1 and
I'll resubmit after the weekend.