netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Donald Hunter <donald.hunter@gmail.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: davem@davemloft.net,  netdev@vger.kernel.org,
	 edumazet@google.com, pabeni@redhat.com,  andrew+netdev@lunn.ch,
	 horms@kernel.org, daniel@iogearbox.net,  sdf@fomichev.me,
	 jacob.e.keller@intel.com
Subject: Re: [PATCH net 1/8] tools: ynl-gen: don't declare loop iterator in place
Date: Wed, 16 Apr 2025 11:06:39 +0100	[thread overview]
Message-ID: <m234e8mndc.fsf@gmail.com> (raw)
In-Reply-To: <20250414211851.602096-2-kuba@kernel.org> (Jakub Kicinski's message of "Mon, 14 Apr 2025 14:18:44 -0700")

Jakub Kicinski <kuba@kernel.org> writes:

> The codegen tries to follow the "old" C style and declare loop
> iterators at the start of the block / function. Only nested
> request handling breaks this style, so adjust it.
>
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> ---
>  tools/net/ynl/pyynl/ynl_gen_c.py | 25 +++++++++++++++++++++----
>  1 file changed, 21 insertions(+), 4 deletions(-)
>
> diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen_c.py
> index a1427c537030..305f5696bc4f 100755
> --- a/tools/net/ynl/pyynl/ynl_gen_c.py
> +++ b/tools/net/ynl/pyynl/ynl_gen_c.py
> @@ -654,10 +654,10 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S
>      def attr_put(self, ri, var):
>          if self.attr['type'] in scalars:
>              put_type = self.type
> -            ri.cw.p(f"for (unsigned int i = 0; i < {var}->n_{self.c_name}; i++)")
> +            ri.cw.p(f"for (i = 0; i < {var}->n_{self.c_name}; i++)")
>              ri.cw.p(f"ynl_attr_put_{put_type}(nlh, {self.enum_name}, {var}->{self.c_name}[i]);")
>          elif 'type' not in self.attr or self.attr['type'] == 'nest':
> -            ri.cw.p(f"for (unsigned int i = 0; i < {var}->n_{self.c_name}; i++)")
> +            ri.cw.p(f"for (i = 0; i < {var}->n_{self.c_name}; i++)")
>              self._attr_put_line(ri, var, f"{self.nested_render_name}_put(nlh, " +
>                                  f"{self.enum_name}, &{var}->{self.c_name}[i])")
>          else:
> @@ -1644,11 +1644,23 @@ _C_KW = {
>  
>  
>  def put_req_nested(ri, struct):
> +    local_vars = []
> +    init_lines = []
> +
> +    local_vars.append('struct nlattr *nest;')
> +    init_lines.append("nest = ynl_attr_nest_start(nlh, attr_type);")

Minor nit: the series uses += ['...'] elsewhere, is it worth being
consistent?

Either way,
Reviewed-by: Donald Hunter <donald.hunter@gmail.com>

  reply	other threads:[~2025-04-16 10:18 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-14 21:18 [PATCH net 0/8] ynl: avoid leaks in attr override and spec fixes for C Jakub Kicinski
2025-04-14 21:18 ` [PATCH net 1/8] tools: ynl-gen: don't declare loop iterator in place Jakub Kicinski
2025-04-16 10:06   ` Donald Hunter [this message]
2025-04-16 13:45     ` Jakub Kicinski
2025-04-16 16:20       ` Keller, Jacob E
2025-04-14 21:18 ` [PATCH net 2/8] tools: ynl-gen: move local vars after the opening bracket Jakub Kicinski
2025-04-16  9:56   ` Donald Hunter
2025-04-14 21:18 ` [PATCH net 3/8] tools: ynl-gen: individually free previous values on double set Jakub Kicinski
2025-04-16 10:06   ` Donald Hunter
2025-04-14 21:18 ` [PATCH net 4/8] tools: ynl-gen: make sure we validate subtype of array-nest Jakub Kicinski
2025-04-16 10:07   ` Donald Hunter
2025-04-14 21:18 ` [PATCH net 5/8] netlink: specs: rt-link: add an attr layer around alt-ifname Jakub Kicinski
2025-04-16 10:08   ` Donald Hunter
2025-04-14 21:18 ` [PATCH net 6/8] netlink: specs: rtnetlink: attribute naming corrections Jakub Kicinski
2025-04-16 10:09   ` Donald Hunter
2025-04-14 21:18 ` [PATCH net 7/8] netlink: specs: rt-link: adjust mctp attribute naming Jakub Kicinski
2025-04-16 10:10   ` Donald Hunter
2025-04-14 21:18 ` [PATCH net 8/8] netlink: specs: rt-neigh: prefix struct nfmsg members with ndm Jakub Kicinski
2025-04-16 10:11   ` Donald Hunter
2025-04-15 17:39 ` [PATCH net 0/8] ynl: avoid leaks in attr override and spec fixes for C Jacob Keller
2025-04-17  1:21 ` patchwork-bot+netdevbpf

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=m234e8mndc.fsf@gmail.com \
    --to=donald.hunter@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=jacob.e.keller@intel.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf@fomichev.me \
    /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;
as well as URLs for NNTP newsgroup(s).