From: Andrew Lunn <andrew@lunn.ch>
To: Zou Wei <zou_wei@huawei.com>
Cc: rain.1986.08.12@gmail.com, zyjzyj2000@gmail.com,
davem@davemloft.net, kuba@kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH -next] net: nvidia: forcedeth: remove useless if/else
Date: Thu, 29 Oct 2020 13:24:20 +0100 [thread overview]
Message-ID: <20201029122420.GG933237@lunn.ch> (raw)
In-Reply-To: <1603938614-53589-1-git-send-email-zou_wei@huawei.com>
On Thu, Oct 29, 2020 at 10:30:14AM +0800, Zou Wei wrote:
> Fix the following coccinelle report:
>
> ./drivers/net/ethernet/nvidia/forcedeth.c:3479:8-10:
> WARNING: possible condition with no effect (if == else)
>
> Both branches are the same, so remove the else if/else altogether.
>
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Zou Wei <zou_wei@huawei.com>
> ---
> drivers/net/ethernet/nvidia/forcedeth.c | 3 ---
> 1 file changed, 3 deletions(-)
>
> diff --git a/drivers/net/ethernet/nvidia/forcedeth.c b/drivers/net/ethernet/nvidia/forcedeth.c
> index 2fc10a3..87ed7e1 100644
> --- a/drivers/net/ethernet/nvidia/forcedeth.c
> +++ b/drivers/net/ethernet/nvidia/forcedeth.c
> @@ -3476,9 +3476,6 @@ static int nv_update_linkspeed(struct net_device *dev)
> } else if (adv_lpa & LPA_10FULL) {
> newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
> newdup = 1;
> - } else if (adv_lpa & LPA_10HALF) {
> - newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
> - newdup = 0;
> } else {
> newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
> newdup = 0;
I think the original code is more readable. The idea is, you look at
what each end of the link can do, and work your way from fastest to
slowest finding one in common. That is what the four if () do. If
there is no speed in common, the link is probably not going to work,
but default to 10Half, because all devices should in theory support
that. That is the last else. The change makes it a lot less clear
about this last past.
How about this instead. It keeps the idea of, we have nothing else
better, do 10Half.
This is not even compile tested.
Andrew
diff --git a/drivers/net/ethernet/nvidia/forcedeth.c b/drivers/net/ethernet/nvidia/forcedeth.c
index 2fc10a36afa4..f626bd6c0dfc 100644
--- a/drivers/net/ethernet/nvidia/forcedeth.c
+++ b/drivers/net/ethernet/nvidia/forcedeth.c
@@ -3467,6 +3467,8 @@ static int nv_update_linkspeed(struct net_device *dev)
/* FIXME: handle parallel detection properly */
adv_lpa = lpa & adv;
+ newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
+ newdup = 0;
if (adv_lpa & LPA_100FULL) {
newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
newdup = 1;
@@ -3479,9 +3481,6 @@ static int nv_update_linkspeed(struct net_device *dev)
} else if (adv_lpa & LPA_10HALF) {
newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
newdup = 0;
- } else {
- newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
- newdup = 0;
}
set_speed:
prev parent reply other threads:[~2020-10-29 12:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-29 2:30 Zou Wei
2020-10-29 12:24 ` Andrew Lunn [this message]
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=20201029122420.GG933237@lunn.ch \
--to=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=rain.1986.08.12@gmail.com \
--cc=zou_wei@huawei.com \
--cc=zyjzyj2000@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
all inboxes | Powered by JetHome®