From: David Sterba <dsterba@suse.cz>
To: Colin Ian King <colin.i.king@gmail.com>
Cc: Chris Mason <clm@fb.com>, Josef Bacik <josef@toxicpanda.com>,
David Sterba <dsterba@suse.com>,
linux-btrfs@vger.kernel.org, kernel-janitors@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH][next] btrfs: remove shadowed declaration of variable i in for-loops
Date: Thu, 30 Nov 2023 23:50:33 +0100 [thread overview]
Message-ID: <20231130225033.GV18929@twin.jikos.cz> (raw)
In-Reply-To: <20231130150811.2208562-1-colin.i.king@gmail.com>
On Thu, Nov 30, 2023 at 03:08:11PM +0000, Colin Ian King wrote:
> The variable i is declared at the start of function btrfs_qgroup_inherit
> however there are two for-loops that redeclare the variable using a C99
> declaration, causes name shadowing. I believe there is no need for this
> local scoping of i in the loop, so replace the declaration in the loops
> with assignments.
>
> Cleans up clang scan build warnings:
>
> fs/btrfs/qgroup.c:3194:12: warning: declaration shadows a local variable [-Wshadow]
> 3194 | for (int i = 0; i < inherit->num_qgroups; i++) {
> | ^
> fs/btrfs/qgroup.c:3089:6: note: previous declaration is here
> 3089 | int i;
> | ^
> fs/btrfs/qgroup.c:3321:12: warning: declaration shadows a local variable [-Wshadow]
> 3321 | for (int i = 0; i < inherit->num_qgroups; i++)
> | ^
> fs/btrfs/qgroup.c:3089:6: note: previous declaration is here
> 3089 | int i;
> | ^
>
> Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
> ---
> fs/btrfs/qgroup.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
> index ce446d9d7f23..b1f93dbf468c 100644
> --- a/fs/btrfs/qgroup.c
> +++ b/fs/btrfs/qgroup.c
> @@ -3191,7 +3191,7 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
> ret = -ENOMEM;
> goto out;
> }
> - for (int i = 0; i < inherit->num_qgroups; i++) {
> + for (i = 0; i < inherit->num_qgroups; i++) {
We want to use the for(...) local definitions, so this should change the
function scope 'i'.
prev parent reply other threads:[~2023-11-30 22:57 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-30 15:08 Colin Ian King
2023-11-30 22:50 ` David Sterba [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=20231130225033.GV18929@twin.jikos.cz \
--to=dsterba@suse.cz \
--cc=clm@fb.com \
--cc=colin.i.king@gmail.com \
--cc=dsterba@suse.com \
--cc=josef@toxicpanda.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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®