[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20211206162510.35b85e74@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com>
Date: Mon, 6 Dec 2021 16:25:10 -0800
From: Jakub Kicinski <kuba@...nel.org>
To: Marek BehĂșn <kabel@...nel.org>
Cc: Andrew Lunn <andrew@...n.ch>, Ameer Hamza <amhamza.mgc@...il.com>,
vivien.didelot@...il.com, f.fainelli@...il.com, olteanv@...il.com,
davem@...emloft.net, netdev@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] net: dsa: mv88e6xxx: initialize return variable on
declaration
On Mon, 6 Dec 2021 23:29:53 +0100 Marek BehĂșn wrote:
> On Mon, 6 Dec 2021 14:21:03 +0100
> Andrew Lunn <andrew@...n.ch> wrote:
>
> > On Mon, Dec 06, 2021 at 04:32:19PM +0500, Ameer Hamza wrote:
> > > Uninitialized err variable defined in mv88e6393x_serdes_power
> > > function may cause undefined behaviour if it is called from
> > > mv88e6xxx_serdes_power_down context.
> > >
> > > Addresses-Coverity: 1494644 ("Uninitialized scalar variable")
> > >
> > > Signed-off-by: Ameer Hamza <amhamza.mgc@...il.com>
> > > ---
> > > drivers/net/dsa/mv88e6xxx/serdes.c | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/net/dsa/mv88e6xxx/serdes.c b/drivers/net/dsa/mv88e6xxx/serdes.c
> > > index 55273013bfb5..33727439724a 100644
> > > --- a/drivers/net/dsa/mv88e6xxx/serdes.c
> > > +++ b/drivers/net/dsa/mv88e6xxx/serdes.c
> > > @@ -1507,7 +1507,7 @@ int mv88e6393x_serdes_power(struct mv88e6xxx_chip *chip, int port, int lane,
> > > bool on)
> > > {
> > > u8 cmode = chip->ports[port].cmode;
> > > - int err;
> > > + int err = 0;
> > >
> > > if (port != 0 && port != 9 && port != 10)
> > > return -EOPNOTSUPP;
> >
> > Hi Marek
> >
> > This warning likely comes from cmode not being a SERDES mode, and that
> > is not handles in the switch statementing. Do we want an
> >
> > default:
> > err = EINVAL;
> >
> > ?
>
> currently all the .serdes_power() methods return 0 for non-serdes ports.
> This is because the way it is written, these methods are not called if
> there is not a serdes lane for a given port.
>
> For this issue with err variable undefined, to fix it we should simply
> set int err=0 at the beginning of mv88e6393x_serdes_power(), to make it
> behave like other serdes_power() methods do in serdes.c.
Any objections to using a default case in the switch statement, tho?
I agree with Andrew that default statement would make the reasoning
clearer than just setting the variable at the start of the function.
Powered by blists - more mailing lists