From: "Asbjørn Sloth Tønnesen" <ast@fiberby.net>
To: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: "Asbjørn Sloth Tønnesen" <ast@fiberby.net>,
"Alexei Starovoitov" <ast@kernel.org>,
"Andrew Lunn" <andrew+netdev@lunn.ch>,
"Arkadiusz Kubalewski" <arkadiusz.kubalewski@intel.com>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Daniel Zahka" <daniel.zahka@gmail.com>,
"Donald Hunter" <donald.hunter@gmail.com>,
"Jacob Keller" <jacob.e.keller@intel.com>,
"Jesper Dangaard Brouer" <hawk@kernel.org>,
"Jiri Pirko" <jiri@resnulli.us>,
"Joe Damato" <jdamato@fastly.com>,
"John Fastabend" <john.fastabend@gmail.com>,
"Jonathan Corbet" <corbet@lwn.net>,
"Simon Horman" <horms@kernel.org>,
"Stanislav Fomichev" <sdf@fomichev.me>,
"Toke Høiland-Jørgensen" <toke@redhat.com>,
"Vadim Fedorenko" <vadim.fedorenko@linux.dev>,
"Willem de Bruijn" <willemb@google.com>,
bpf@vger.kernel.org, netdev@vger.kernel.org,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH net-next 4/6] tools: ynl-gen: add generic p_wrap() helper
Date: Mon, 13 Oct 2025 16:50:01 +0000 [thread overview]
Message-ID: <20251013165005.83659-5-ast@fiberby.net> (raw)
In-Reply-To: <20251013165005.83659-1-ast@fiberby.net>
Previously only write_func_prot() was performing line wrapping.
As the next patch in this series also requires line wrapping,
then this patch introduces a generic line wrapping helper in
CodeWriter called p_wrap(), which can be used in both cases.
This patch causes a change in the generated prototype for
psp_device_get_locked(), as the skb argument actually fits
on the first line, while not exceeding 80 characters.
No functional changes.
Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net>
---
net/psp/psp-nl-gen.h | 4 +--
tools/net/ynl/pyynl/ynl_gen_c.py | 42 +++++++++++++++++++-------------
2 files changed, 27 insertions(+), 19 deletions(-)
diff --git a/net/psp/psp-nl-gen.h b/net/psp/psp-nl-gen.h
index 25268ed11fb56..ac5f59b4f498c 100644
--- a/net/psp/psp-nl-gen.h
+++ b/net/psp/psp-nl-gen.h
@@ -14,8 +14,8 @@
/* Common nested types */
extern const struct nla_policy psp_keys_nl_policy[PSP_A_KEYS_SPI + 1];
-int psp_device_get_locked(const struct genl_split_ops *ops,
- struct sk_buff *skb, struct genl_info *info);
+int psp_device_get_locked(const struct genl_split_ops *ops, struct sk_buff *skb,
+ struct genl_info *info);
int psp_assoc_device_get_locked(const struct genl_split_ops *ops,
struct sk_buff *skb, struct genl_info *info);
void
diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen_c.py
index b00762721280c..1201c2ac352ea 100755
--- a/tools/net/ynl/pyynl/ynl_gen_c.py
+++ b/tools/net/ynl/pyynl/ynl_gen_c.py
@@ -1693,6 +1693,27 @@ class CodeWriter:
ind += add_ind
self._out.write('\t' * ind + line + '\n')
+ def p_wrap(self, prefix, parts):
+ assert(len(parts) > 0)
+ ts = 8
+ pfx_len = len(prefix)
+ pfx_ind_tabs = pfx_len // ts
+ pfx_ind = '\t' * pfx_ind_tabs + ' ' * (pfx_len % ts)
+ max_len = 80 - (self._ind * ts)
+ is_first_line = True
+ buf = f'{prefix}{parts[0]}'
+ for part in parts[1:]:
+ next_buf = f'{buf} {part}'
+ if len(next_buf) <= max_len:
+ buf = next_buf
+ else:
+ self.p(buf)
+ buf = f'{pfx_ind}{part}'
+ if is_first_line:
+ max_len -= pfx_ind_tabs * (ts-1)
+ is_first_line = False
+ self.p(buf)
+
def nl(self):
self._nl = True
@@ -1751,23 +1772,10 @@ class CodeWriter:
v = ''
elif qual_ret[-1] != '*':
v += ' '
- v += name + '('
- ind = '\t' * (len(v) // 8) + ' ' * (len(v) % 8)
- delta_ind = len(v) - len(ind)
- v += args[0]
- i = 1
- while i < len(args):
- next_len = len(v) + len(args[i])
- if v[0] == '\t':
- next_len += delta_ind
- if next_len > 76:
- self.p(v + ',')
- v = ind
- else:
- v += ', '
- v += args[i]
- i += 1
- self.p(v + ')' + suffix)
+
+ parts = [f'{arg},' for arg in args[:-1]]
+ parts.append(f'{args[-1]}){suffix}')
+ self.p_wrap(f'{v}{name}(', parts)
def write_func_lvar(self, local_vars):
if not local_vars:
--
2.51.0
next prev parent reply other threads:[~2025-10-13 16:51 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-13 16:49 [PATCH net-next 0/6] tools: ynl-gen: generate flags better Asbjørn Sloth Tønnesen
2025-10-13 16:49 ` [PATCH net-next 1/6] tools: ynl-gen: bitshift the flag values in the generated code Asbjørn Sloth Tønnesen
2025-10-13 23:07 ` Jacob Keller
2025-10-14 16:27 ` Asbjørn Sloth Tønnesen
2025-10-14 0:53 ` Jakub Kicinski
2025-10-14 16:49 ` Asbjørn Sloth Tønnesen
2025-10-14 19:24 ` Jakub Kicinski
2025-10-13 16:49 ` [PATCH net-next 2/6] tools: ynl-gen: refactor render-max enum generation Asbjørn Sloth Tønnesen
2025-10-14 0:58 ` Jakub Kicinski
2025-10-14 17:04 ` Asbjørn Sloth Tønnesen
2025-10-14 19:26 ` Jakub Kicinski
2025-10-13 16:50 ` [PATCH net-next 3/6] tools: ynl-gen: use uapi mask definition in NLA_POLICY_MASK Asbjørn Sloth Tønnesen
2025-10-14 0:59 ` Jakub Kicinski
2025-10-14 17:29 ` Asbjørn Sloth Tønnesen
2025-10-14 19:32 ` Jakub Kicinski
2025-10-13 16:50 ` Asbjørn Sloth Tønnesen [this message]
2025-10-13 16:50 ` [PATCH net-next 5/6] tools: ynl-gen: construct bitflag masks in generated headers Asbjørn Sloth Tønnesen
2025-10-13 16:50 ` [PATCH net-next 6/6] tools: ynl-gen: allow custom naming of render-max definitions Asbjørn Sloth Tønnesen
2025-10-13 23:10 ` [PATCH net-next 0/6] tools: ynl-gen: generate flags better Jacob Keller
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=20251013165005.83659-5-ast@fiberby.net \
--to=ast@fiberby.net \
--cc=andrew+netdev@lunn.ch \
--cc=arkadiusz.kubalewski@intel.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=corbet@lwn.net \
--cc=daniel.zahka@gmail.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=edumazet@google.com \
--cc=hawk@kernel.org \
--cc=horms@kernel.org \
--cc=jacob.e.keller@intel.com \
--cc=jdamato@fastly.com \
--cc=jiri@resnulli.us \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
--cc=toke@redhat.com \
--cc=vadim.fedorenko@linux.dev \
--cc=willemb@google.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®