From: "Marek Behún" <kabel@kernel.org>
To: Andrew Lunn <andrew@lunn.ch>
Cc: Ameer Hamza <amhamza.mgc@gmail.com>,
vivien.didelot@gmail.com, f.fainelli@gmail.com,
olteanv@gmail.com, davem@davemloft.net, kuba@kernel.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] net: dsa: mv88e6xxx: initialize return variable on declaration
Date: Mon, 6 Dec 2021 23:29:53 +0100 [thread overview]
Message-ID: <20211206232953.065c0dc9@thinkpad> (raw)
In-Reply-To: <Ya4OP+jQYd/UwiQK@lunn.ch>
On Mon, 6 Dec 2021 14:21:03 +0100
Andrew Lunn <andrew@lunn.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@gmail.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;
>
> ?
>
> Andrew
Hi Andrew,
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.
But a refactor may be needed for serdes_power() methods, at least
because they are a little weird. But it should be unrelated to this fix.
In serdes.h we have static inline functions
mv88e6xxx_serdes_power_up(chip, port, lane)
mv88e6xxx_serdes_power_down(chip, port, lane)
(These simply call the serdes_power() method of chip ops, with
additional boolean argument to specify powerup/powerdown.
Also for these we first need to determine lane for a port. If lane
does not exists, these should not be called.)
In chip.c we have function
mv88e6xxx_serdes_power(chip, port, on)
(This finds if the port has a lane, and if so, calls, if on=true
mv88e6xxx_serdes_power_up()
from serdes.h, and then
mv88e6xxx_serdes_irq_request()
also from serdes.h
and if on=false, calls _irq_free() & _serdes_power_down()
)
So if I call
mv88e6xxx_serdes_power(chip, port, true)
it goes
mv88e6xxx_serdes_power_up(chip, port, lane)
chip->info->ops->serdes_power(chip, port, lane, true)
so the `on` argument is used in some places, but in other places there
are two functions instead.
Which I find a little weird.
Marek
next prev parent reply other threads:[~2021-12-06 22:30 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-06 11:32 [PATCH] net: dsa: mv88e6xxx: initialize return variable on declaration Ameer Hamza
2021-12-06 13:21 ` Andrew Lunn
2021-12-06 22:29 ` Marek Behún [this message]
2021-12-07 0:25 ` Jakub Kicinski
2021-12-07 13:06 ` Marek Behún
2021-12-08 14:04 ` [PATCH v2] net: dsa: mv88e6xxx: error handling for serdes_power functions Ameer Hamza
2021-12-08 14:09 ` Ameer Hamza
2021-12-08 15:04 ` Jakub Kicinski
2021-12-08 15:40 ` Marek Behún
2021-12-08 15:58 ` [PATCH v3] " Ameer Hamza
2021-12-08 16:18 ` Marek Behún
2021-12-09 1:28 ` Jakub Kicinski
2021-12-09 4:06 ` Ameer Hamza
2021-12-09 4:07 ` [PATCH v4] " Ameer Hamza
2021-12-09 4:15 ` Ameer Hamza
2021-12-09 15:50 ` patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211206232953.065c0dc9@thinkpad \
--to=kabel@kernel.org \
--cc=amhamza.mgc@gmail.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=f.fainelli@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=vivien.didelot@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).