From: Andrew Lunn <andrew@lunn.ch>
To: Breno Leitao <leitao@debian.org>
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
Nicolas Dichtel <nicolas.dichtel@6wind.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next] net: Remove redundant variable declaration in __dev_change_flags()
Date: Fri, 14 Feb 2025 14:33:45 +0100 [thread overview]
Message-ID: <1d7e3018-9c82-4a00-8e10-3451b4a19a0d@lunn.ch> (raw)
In-Reply-To: <20250214-old_flags-v1-1-29096b9399a9@debian.org>
On Fri, Feb 14, 2025 at 04:47:49AM -0800, Breno Leitao wrote:
> The old_flags variable is declared twice in __dev_change_flags(),
> causing a shadow variable warning. This patch fixes the issue by
> removing the redundant declaration, reusing the existing old_flags
> variable instead.
>
> net/core/dev.c:9225:16: warning: declaration shadows a local variable [-Wshadow]
> 9225 | unsigned int old_flags = dev->flags;
> | ^
> net/core/dev.c:9185:15: note: previous declaration is here
> 9185 | unsigned int old_flags = dev->flags;
> | ^
> 1 warning generated.
>
> This change has no functional impact on the code, as the inner variable
> does not affect the outer one. The fix simply eliminates the unnecessary
> declaration and resolves the warning.
I'm not a compiler person... but there might be some subtlety here:
int __dev_change_flags(struct net_device *dev, unsigned int flags,
struct netlink_ext_ack *extack)
{
unsigned int old_flags = dev->flags;
int ret;
This old_flags gets the value of flags at the time of entry into the
function.
...
if ((old_flags ^ flags) & IFF_UP) {
if (old_flags & IFF_UP)
__dev_close(dev);
else
ret = __dev_open(dev, extack);
}
If you dig down into __dev_close(dev) you find
dev->flags &= ~IFF_UP;
then
...
if ((flags ^ dev->gflags) & IFF_PROMISC) {
int inc = (flags & IFF_PROMISC) ? 1 : -1;
unsigned int old_flags = dev->flags;
This inner old_flags now has the IFF_UP removed, and so is different
to the outer old_flags.
The outer old_flags is not used after this point, so in the end it
might not matter, but that fact i felt i needed to look deeper at the
code suggests the commit message needs expanding to include more
analyses.
> Fixes: 991fb3f74c142e ("dev: always advertise rx_flags changes via netlink")
I suppose there is also a danger here this code has at some point in
the past has been refactored, such that the outer old_flags was used
at some point? Backporting this patch could then break something? Did
you check for this? Again, a comment in the commit message that you
have checked this is safe to backport would be nice.
Andrew
---
pw-bot: cr
next prev parent reply other threads:[~2025-02-14 13:33 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-14 12:47 Breno Leitao
2025-02-14 13:27 ` Mateusz Polchlopek
2025-02-14 13:33 ` Andrew Lunn [this message]
2025-02-14 14:21 ` Breno Leitao
2025-02-14 15:02 ` Andrew Lunn
2025-02-14 16:09 ` Breno Leitao
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=1d7e3018-9c82-4a00-8e10-3451b4a19a0d@lunn.ch \
--to=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=leitao@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=nicolas.dichtel@6wind.com \
--cc=pabeni@redhat.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®