Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp398740pxx; Thu, 29 Oct 2020 05:26:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3iiYH8jNkVQggjrJ2O/pze8v/UeY4U6uOd4iL+VyuduCH8c3aMoKdps1te44sCWwi+7k7 X-Received: by 2002:a17:906:1446:: with SMTP id q6mr3896812ejc.549.1603974392918; Thu, 29 Oct 2020 05:26:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603974392; cv=none; d=google.com; s=arc-20160816; b=UJkXdvUiNFORK/bLcHP0ZrKOwH7pLVyb7f9UbahL/XjZUwKUbY7MBNO1RCYZzheLvv KVfp3FNUX2Zq13ezU4HLdSAyEJkA6wvFhTg2eS+lftPuwWoCcXnJwxMJ/b3YkfIEKII6 /a0uZbG2DZVGWlz7lJruRi7eiWpdBLkTPmtfy5PVyl3ValGfSco01bdbAcjJr9j0Asob m6WvxYQ1Q+17rpUav64xEbzYACrsC4JkE8Yr3YS/ytKkSuUxZ8ZJOjPgn5JdlxvVI/s4 SrWw/1c23T6+zvAvG8Z0ihXtb672tbc/6W6kqnJG/qh7e8O7au0MVwbUla28dzveY4a2 mqgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=uM1OiYsoO5JnWb9bfZHAnKxU3U7G/VFVdsIZSjji3eM=; b=MABKZjYpVGz3Adhnv+w0GKp5XERPVrA/VPAKGeVEczSxzT5Tt5U2QowT7BH1mfVMaV zRBWYhnR0pZGuQ9nP9DHSZ3w4JWJHHbS9feDm1rdSMCAtTiFaAwZppVnqdRcg8cT4W7b e8xWp9elwacxK1ht5KTHhtoTRaB2nsspWzVvQ71Yg6xcQ99/xXzr5yMJkM4n3N2/ntyM RwVM8tysJgEX7gj+HBrPq01qfqzTZOJPfstt8qHbXbTLOPVKyyOUENuWh3YpACAuAo+l 5E2QNuVPth/L3kPHx/t/1tj4NztTEkqQ+osMoj2mmK3eRT05EYaABrSbUOpzPXQg5z4B Hf0Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d4si2028045edo.178.2020.10.29.05.26.10; Thu, 29 Oct 2020 05:26:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726235AbgJ2MYf (ORCPT + 99 others); Thu, 29 Oct 2020 08:24:35 -0400 Received: from vps0.lunn.ch ([185.16.172.187]:51958 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725355AbgJ2MYf (ORCPT ); Thu, 29 Oct 2020 08:24:35 -0400 Received: from andrew by vps0.lunn.ch with local (Exim 4.94) (envelope-from ) id 1kY6ya-0049Sx-4A; Thu, 29 Oct 2020 13:24:20 +0100 Date: Thu, 29 Oct 2020 13:24:20 +0100 From: Andrew Lunn To: Zou Wei 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 Message-ID: <20201029122420.GG933237@lunn.ch> References: <1603938614-53589-1-git-send-email-zou_wei@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1603938614-53589-1-git-send-email-zou_wei@huawei.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > Signed-off-by: Zou Wei > --- > 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: