Message ID | 20200919192809.29120-1-alex.dewar90@gmail.com |
---|---|
State | Accepted |
Delegated to: | David Miller |
Headers | show |
Series | [v2] net: dsa: mt7530: Add some return-value checks | expand |
Hi Alex, Thanks for your patch. By linux/scripts/checkpatch.pl On Sun, 2020-09-20 at 03:28 +0800, Alex Dewar wrote: [..] > @@ -1631,9 +1635,11 @@ mt7530_setup(struct dsa_switch *ds) > mt7530_rmw(priv, MT7530_PCR_P(i), PCR_MATRIX_MASK, > PCR_MATRIX_CLR); > > - if (dsa_is_cpu_port(ds, i)) > - mt753x_cpu_port_enable(ds, i); > - else > + if (dsa_is_cpu_port(ds, i)) { > + ret = mt753x_cpu_port_enable(ds, i); > + if (ret) > + return ret; > + } else > mt7530_port_disable(ds, i); CHECK: braces {} should be used on all arms of this statement CHECK: Unbalanced braces around else statement > > /* Enable consistent egress tag */ > @@ -1785,9 +1791,11 @@ mt7531_setup(struct dsa_switch *ds) > > mt7530_set(priv, MT7531_DBG_CNT(i), MT7531_DIS_CLR); > > - if (dsa_is_cpu_port(ds, i)) > - mt753x_cpu_port_enable(ds, i); > - else > + if (dsa_is_cpu_port(ds, i)) { > + ret = mt753x_cpu_port_enable(ds, i); > + if (ret) > + return ret; > + } else > mt7530_port_disable(ds, i); CHECK: braces {} should be used on all arms of this statement CHECK: Unbalanced braces around else statement [..] regards landen
On 2020-09-24 13:13, Landen Chao wrote: > Hi Alex, > > Thanks for your patch. By linux/scripts/checkpatch.pl > > On Sun, 2020-09-20 at 03:28 +0800, Alex Dewar wrote: > [..] >> @@ -1631,9 +1635,11 @@ mt7530_setup(struct dsa_switch *ds) >> mt7530_rmw(priv, MT7530_PCR_P(i), PCR_MATRIX_MASK, >> PCR_MATRIX_CLR); >> >> - if (dsa_is_cpu_port(ds, i)) >> - mt753x_cpu_port_enable(ds, i); >> - else >> + if (dsa_is_cpu_port(ds, i)) { >> + ret = mt753x_cpu_port_enable(ds, i); >> + if (ret) >> + return ret; >> + } else >> mt7530_port_disable(ds, i); > CHECK: braces {} should be used on all arms of this statement > CHECK: Unbalanced braces around else statement >> >> /* Enable consistent egress tag */ >> @@ -1785,9 +1791,11 @@ mt7531_setup(struct dsa_switch *ds) >> >> mt7530_set(priv, MT7531_DBG_CNT(i), MT7531_DIS_CLR); >> >> - if (dsa_is_cpu_port(ds, i)) >> - mt753x_cpu_port_enable(ds, i); >> - else >> + if (dsa_is_cpu_port(ds, i)) { >> + ret = mt753x_cpu_port_enable(ds, i); >> + if (ret) >> + return ret; >> + } else >> mt7530_port_disable(ds, i); > CHECK: braces {} should be used on all arms of this statement > CHECK: Unbalanced braces around else statement > > [..] > regards landen Hi Landen, Sorry about this... I usually run checkpatch over my patches. Would you like me to send a separate fix or a v3? Best, Alex
On Thu, 2020-09-24 at 14:11 +0100, Alex Dewar wrote: > On 2020-09-24 13:13, Landen Chao wrote: > > Hi Alex, > > > > Thanks for your patch. By linux/scripts/checkpatch.pl > > > > On Sun, 2020-09-20 at 03:28 +0800, Alex Dewar wrote: > > [..] > >> @@ -1631,9 +1635,11 @@ mt7530_setup(struct dsa_switch *ds) > >> mt7530_rmw(priv, MT7530_PCR_P(i), PCR_MATRIX_MASK, > >> PCR_MATRIX_CLR); > >> > >> - if (dsa_is_cpu_port(ds, i)) > >> - mt753x_cpu_port_enable(ds, i); > >> - else > >> + if (dsa_is_cpu_port(ds, i)) { > >> + ret = mt753x_cpu_port_enable(ds, i); > >> + if (ret) > >> + return ret; > >> + } else > >> mt7530_port_disable(ds, i); > > CHECK: braces {} should be used on all arms of this statement > > CHECK: Unbalanced braces around else statement > >> > >> /* Enable consistent egress tag */ > >> @@ -1785,9 +1791,11 @@ mt7531_setup(struct dsa_switch *ds) > >> > >> mt7530_set(priv, MT7531_DBG_CNT(i), MT7531_DIS_CLR); > >> > >> - if (dsa_is_cpu_port(ds, i)) > >> - mt753x_cpu_port_enable(ds, i); > >> - else > >> + if (dsa_is_cpu_port(ds, i)) { > >> + ret = mt753x_cpu_port_enable(ds, i); > >> + if (ret) > >> + return ret; > >> + } else > >> mt7530_port_disable(ds, i); > > CHECK: braces {} should be used on all arms of this statement > > CHECK: Unbalanced braces around else statement > > > > [..] > > regards landen > Hi Landen, > > Sorry about this... I usually run checkpatch over my patches. Would you > like me to send a separate fix or a v3? > > Best, > Alex Hi Alex, Because v2 has not been merged yet, could you help to fix it in v3? regards landen
diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index 61388945d316..cb3efa7de7a8 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -945,10 +945,14 @@ static int mt753x_cpu_port_enable(struct dsa_switch *ds, int port) { struct mt7530_priv *priv = ds->priv; + int ret; /* Setup max capability of CPU port at first */ - if (priv->info->cpu_port_config) - priv->info->cpu_port_config(ds, port); + if (priv->info->cpu_port_config) { + ret = priv->info->cpu_port_config(ds, port); + if (ret) + return ret; + } /* Enable Mediatek header mode on the cpu port */ mt7530_write(priv, MT7530_PVC_P(port), @@ -1631,9 +1635,11 @@ mt7530_setup(struct dsa_switch *ds) mt7530_rmw(priv, MT7530_PCR_P(i), PCR_MATRIX_MASK, PCR_MATRIX_CLR); - if (dsa_is_cpu_port(ds, i)) - mt753x_cpu_port_enable(ds, i); - else + if (dsa_is_cpu_port(ds, i)) { + ret = mt753x_cpu_port_enable(ds, i); + if (ret) + return ret; + } else mt7530_port_disable(ds, i); /* Enable consistent egress tag */ @@ -1785,9 +1791,11 @@ mt7531_setup(struct dsa_switch *ds) mt7530_set(priv, MT7531_DBG_CNT(i), MT7531_DIS_CLR); - if (dsa_is_cpu_port(ds, i)) - mt753x_cpu_port_enable(ds, i); - else + if (dsa_is_cpu_port(ds, i)) { + ret = mt753x_cpu_port_enable(ds, i); + if (ret) + return ret; + } else mt7530_port_disable(ds, i); /* Enable consistent egress tag */ @@ -2276,6 +2284,7 @@ mt7531_cpu_port_config(struct dsa_switch *ds, int port) struct mt7530_priv *priv = ds->priv; phy_interface_t interface; int speed; + int ret; switch (port) { case 5: @@ -2293,6 +2302,8 @@ mt7531_cpu_port_config(struct dsa_switch *ds, int port) priv->p6_interface = interface; break; + default: + return -EINVAL; } if (interface == PHY_INTERFACE_MODE_2500BASEX) @@ -2300,7 +2311,9 @@ mt7531_cpu_port_config(struct dsa_switch *ds, int port) else speed = SPEED_1000; - mt7531_mac_config(ds, port, MLO_AN_FIXED, interface); + ret = mt7531_mac_config(ds, port, MLO_AN_FIXED, interface); + if (ret) + return ret; mt7530_write(priv, MT7530_PMCR_P(port), PMCR_CPU_PORT_SETTING(priv->id)); mt753x_phylink_mac_link_up(ds, port, MLO_AN_FIXED, interface, NULL,
In mt7531_cpu_port_config(), if the variable port is neither 5 nor 6, then variable interface will be used uninitialised. Change the function to return -EINVAL in this case. As the return value of mt7531_cpu_port_config() is never checked (even though it returns an int) add a check in the correct place so that the error can be passed up the call stack. Now that we correctly handle errors thrown in this function, also check the return value of mt7531_mac_config() in case an error occurs here. Also add misisng checks to mt7530_setup() and mt7531_setup(), which are another level further up the call stack. Fixes: c288575f7810 ("net: dsa: mt7530: Add the support of MT7531 switch") Addresses-Coverity: 1496993 ("Uninitialized variables") Signed-off-by: Alex Dewar <alex.dewar90@gmail.com> --- v2: - fix typo in commit message - split variable declarations onto multiple lines (Gustavo) - add additional checks for mt753*_setup (Landen) drivers/net/dsa/mt7530.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-)