Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: horms@kernel.org
Cc: donald.hunter@gmail.com, kuba@kernel.org, davem@davemloft.net,
	edumazet@kernel.org, pabeni@redhat.com, ast@fiberby.net,
	cel@kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH net-next v2] tools: ynl-gen: avoid shadow local variable declarations
Date: Tue, 24 Nov 2026 15:53:26 +0000	[thread overview]
Message-ID: <179553560643.3135.4325165389540156144@kernel.org> (raw)
In-Reply-To: <20261123-ynl-scope-v2-1-f5b8c6bb31c1@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] In `_multi_parse()` (tools/net/ynl/pyynl/ynl_gen_c.py), the
  patch moves the per-attribute counter declarations `unsigned int…
- [Low] In `_multi_parse()`, the patch removes the block-local
  `ri.cw.p('unsigned int len;')` from the multi-attr string branch but…

--

tools: ynl-gen: avoid shadow local variable declarations

This commit moves the block-scoped len declarations in _multi_parse() to
function scope, using the set-based mechanism from commit 099902fc66f8. It
also renames the size_t variant of len to size, so two variables with
different types don't share a name in the same scope.

> diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen_c.py
> index 4aca51396a9e2..80b541619df49 100755
> --- a/tools/net/ynl/pyynl/ynl_gen_c.py
> +++ b/tools/net/ynl/pyynl/ynl_gen_c.py

[ ... ]

> @@ -2218,7 +2218,14 @@ def _multi_parse(ri, struct, init_lines, local_vars):
>      all_multi = indexed_arrays | multi_attrs
>  
>      for arg in sorted(all_multi):
> -        local_vars.append(f"unsigned int n_{struct[arg].c_name} = 0;")
> +        aspec = struct[arg]
> +        var_set.add(f'unsigned int n_{struct[arg].c_name} = 0;')
> +        if aspec.type == 'binary' and 'struct' in aspec:
> +            var_set.add('size_t size;')
> +        elif aspec.type == 'string':
> +            var_set.add('unsigned int len;')
> +
> +    local_vars += list(var_set)

[Severity: Medium]

Can this make the generator output differ from run to run?

The n_ counter declarations used to be appended in sorted(all_multi)
order. Now they go into var_set. The order of list(var_set) follows
Python's set iteration order, which depends on the randomized str hash
(PYTHONHASHSEED).

After that, CodeWriter.write_func_lvar() only does:

        local_vars.sort(key=len, reverse=True)

That sort is stable and uses only the length. Declarations of equal length
keep whatever order the set gave them.

This looks reachable in-tree today. In Documentation/netlink/specs/nfsd.yaml,
the server-stats-get dump reply has the multi-attr members proc2-ops,
proc3-ops and proc4-ops. They generate:

    unsigned int n_proc2_ops = 0;
    unsigned int n_proc3_ops = 0;
    unsigned int n_proc4_ops = 0;

All three have the same length. Their order in the generated nfsd-user.c
parse function can change between runs on the same spec. That hurts
reproducible builds of the YNL user library. It also defeats the
filecmp.cmp() check in CodeWriter that skips rewriting unchanged output.

The n_ names are already unique per attribute, so they don't need
deduplication; only len and size do. Would it work to keep
local_vars.append() for the n_ counters, or to use
local_vars += sorted(var_set) instead?

The commit message also doesn't mention that the n_ declarations now go
into the set.

>  
>      ri.cw.block_start()
>      ri.cw.write_func_lvar(local_vars)
> @@ -2304,13 +2311,12 @@ def _multi_parse(ri, struct, init_lines, local_vars):

[ ... ]

>          elif aspec.type == 'string':
> -            ri.cw.p('unsigned int len;')
>              ri.cw.nl()
>              ri.cw.p('len = strnlen(ynl_attr_get_str(attr), ynl_attr_data_len(attr));')

[Severity: Low]

This isn't a bug, but should the ri.cw.nl() be removed along with the
declaration?

This branch is emitted right after block_start() opens the
if (ynl_attr_type(attr) == ...) block. CodeWriter.p() writes the pending
newline before the next line, so the generated C now has a blank line
right after the opening brace. checkpatch flags that ("Blank lines aren't
necessary after an open brace").

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123-ynl-scope-v2-1-f5b8c6bb31c1%40kernel.org

      reply	other threads:[~2026-11-24 15:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 15:52 [PATCH net-next v2] tools: ynl-gen: avoid shadow local variable declarations Simon Horman
2026-11-24 15:53 ` netdev-bot+sashiko [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=179553560643.3135.4325165389540156144@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=ast@fiberby.net \
    --cc=cel@kernel.org \
    --cc=davem@davemloft.net \
    --cc=donald.hunter@gmail.com \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --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