mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alexander Lobakin <aleksander.lobakin@intel.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Paolo Abeni <pabeni@redhat.com>,
	Dmitry Safonov <0x7f454c46@gmail.com>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	<nex.sw.ncis.osdt.itp.upstreaming@intel.com>,
	<netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH net-next 2/2] netdev_queues: fix -Wshadow / Sparse shadow warnings throughout the file
Date: Tue, 2 Apr 2024 13:53:54 +0200	[thread overview]
Message-ID: <912d1f9f-a88d-4751-8d91-b82a75f82a32@intel.com> (raw)
In-Reply-To: <20240329135344.1a310f31@kernel.org>

From: Jakub Kicinski <kuba@kernel.org>
Date: Fri, 29 Mar 2024 13:53:44 -0700

> On Fri, 29 Mar 2024 13:18:57 -0700 Jakub Kicinski wrote:
>>> Sparse:
>>>
>>> drivers/net/ethernet/intel/idpf/idpf_txrx.c:1992:16: warning: symbol '_res' shadows an earlier one
>>> drivers/net/ethernet/intel/idpf/idpf_txrx.c:1992:16: originally declared here  
>>
>> I don't see these building with LLVM=1 W=12 C=1
>> and I really don't like complicating the code because the compiler
>> is stupid. Can't you solve this with some renames? Add another

It's not the compiler, its warnings are valid actually. Shadowing makes
it very easy to confuse variables and make bugs...

>> underscore or something?
> 
> I'm stupid I tried on the test branch which already had your fix..

:D Sometimes it happens.

> 
> This is enough:
> 
> diff --git a/include/net/netdev_queues.h b/include/net/netdev_queues.h
> index 1ec408585373..2270fbb99cf7 100644
> --- a/include/net/netdev_queues.h
> +++ b/include/net/netdev_queues.h
> @@ -89,7 +89,7 @@ struct netdev_stat_ops {
>  
>  #define netif_txq_try_stop(txq, get_desc, start_thrs)			\
>  	({								\
> -		int _res;						\
> +		int __res;						\
>  									\
>  		netif_tx_stop_queue(txq);				\
>  		/* Producer index and stop bit must be visible		\
> @@ -101,12 +101,12 @@ struct netdev_stat_ops {
>  		/* We need to check again in a case another		\
>  		 * CPU has just made room available.			\
>  		 */							\
> -		_res = 0;						\
> +		__res = 0;						\
>  		if (unlikely(get_desc >= start_thrs)) {			\
>  			netif_tx_start_queue(txq);			\
> -			_res = -1;					\
> +			__res = -1;					\
>  		}							\
> -		_res;							\
> +		__res;							\
>  	})								\
>  
>  /**

But what if there's a function which calls one of these functions and
already has _res or __res or something? I know renaming is enough for
the warnings I mentioned, but without __UNIQUE_ID() anything can happen
anytime, so I wanted to fix that once and for all :z

I already saw some macros which have a layer of indirection for
__UNIQUE_ID(), but previously they didn't and then there were fixes
which added underscores, renamed variables etc etc...

Thanks,
Olek

  parent reply	other threads:[~2024-04-02 11:55 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-29 16:59 [PATCH net-next 0/2] net: fix variable shadowing spam from headers Alexander Lobakin
2024-03-29 16:59 ` [PATCH net-next 1/2] net/tcp: fix -Wshadow / Sparse shadow warnings in tcp_hash_fail() Alexander Lobakin
2024-03-29 17:00 ` [PATCH net-next 2/2] netdev_queues: fix -Wshadow / Sparse shadow warnings throughout the file Alexander Lobakin
2024-03-29 20:18   ` Jakub Kicinski
2024-03-29 20:18     ` Jakub Kicinski
2024-03-29 20:53     ` Jakub Kicinski
2024-03-29 20:53       ` Jakub Kicinski
2024-04-02 11:53       ` Alexander Lobakin [this message]
2024-04-02 12:45         ` Eric Dumazet
2024-04-02 15:53           ` Alexander Lobakin
2024-04-02 16:48             ` Jakub Kicinski

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=912d1f9f-a88d-4751-8d91-b82a75f82a32@intel.com \
    --to=aleksander.lobakin@intel.com \
    --cc=0x7f454c46@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nex.sw.ncis.osdt.itp.upstreaming@intel.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®