netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
	Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next 08/10] tools: ynl-gen: generate alloc and free helpers for req
Date: Thu,  1 Jun 2023 19:35:46 -0700	[thread overview]
Message-ID: <20230602023548.463441-9-kuba@kernel.org> (raw)
In-Reply-To: <20230602023548.463441-1-kuba@kernel.org>

We expect user to allocate requests with calloc(),
make things a bit more consistent and provide helpers.
Generate free calls, too.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 tools/net/ynl/ynl-gen-c.py | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/tools/net/ynl/ynl-gen-c.py b/tools/net/ynl/ynl-gen-c.py
index 7d833a42e060..4a7ca2823270 100755
--- a/tools/net/ynl/ynl-gen-c.py
+++ b/tools/net/ynl/ynl-gen-c.py
@@ -1476,6 +1476,14 @@ _C_KW = {
     return 'obj'
 
 
+def print_alloc_wrapper(ri, direction):
+    name = op_prefix(ri, direction)
+    ri.cw.write_func_prot(f'static inline struct {name} *', f"{name}_alloc", [f"void"])
+    ri.cw.block_start()
+    ri.cw.p(f'return calloc(1, sizeof(struct {name}));')
+    ri.cw.block_end()
+
+
 def print_free_prototype(ri, direction, suffix=';'):
     name = op_prefix(ri, direction)
     arg = free_arg_name(direction)
@@ -1523,6 +1531,7 @@ _C_KW = {
 
 def print_type_helpers(ri, direction, deref=False):
     print_free_prototype(ri, direction)
+    ri.cw.nl()
 
     if ri.ku_space == 'user' and direction == 'request':
         for _, attr in ri.struct[direction].member_list():
@@ -1531,6 +1540,7 @@ _C_KW = {
 
 
 def print_req_type_helpers(ri):
+    print_alloc_wrapper(ri, "request")
     print_type_helpers(ri, "request")
 
 
@@ -1554,6 +1564,12 @@ _C_KW = {
     print_type(ri, "request")
 
 
+def print_req_free(ri):
+    if 'request' not in ri.op[ri.op_mode]:
+        return
+    _free_type(ri, 'request', ri.struct['request'])
+
+
 def print_rsp_type(ri):
     if (ri.op_mode == 'do' or ri.op_mode == 'dump') and 'reply' in ri.op[ri.op_mode]:
         direction = 'reply'
@@ -2344,6 +2360,7 @@ _C_KW = {
                 if 'do' in op and 'event' not in op:
                     cw.p(f"/* {op.enum_name} - do */")
                     ri = RenderInfo(cw, parsed, args.mode, op, op_name, "do")
+                    print_req_free(ri)
                     print_rsp_free(ri)
                     parse_rsp_msg(ri)
                     print_req(ri)
-- 
2.40.1


  parent reply	other threads:[~2023-06-02  2:35 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-02  2:35 [PATCH net-next 00/10] tools: ynl-gen: dust off the user space code Jakub Kicinski
2023-06-02  2:35 ` [PATCH net-next 01/10] tools: ynl-gen: add extra headers for user space Jakub Kicinski
2023-06-02  2:35 ` [PATCH net-next 02/10] tools: ynl-gen: fix unused / pad attribute handling Jakub Kicinski
2023-06-02  2:35 ` [PATCH net-next 03/10] tools: ynl-gen: don't override pure nested struct Jakub Kicinski
2023-06-02  2:35 ` [PATCH net-next 04/10] tools: ynl-gen: loosen type consistency check for events Jakub Kicinski
2023-06-02  2:35 ` [PATCH net-next 05/10] tools: ynl-gen: add error checking for nested structs Jakub Kicinski
2023-06-02  2:35 ` [PATCH net-next 06/10] tools: ynl-gen: generate enum-to-string helpers Jakub Kicinski
2023-06-02  2:35 ` [PATCH net-next 07/10] tools: ynl-gen: move the response reading logic into YNL Jakub Kicinski
2023-06-02  2:35 ` Jakub Kicinski [this message]
2023-06-02  2:35 ` [PATCH net-next 09/10] tools: ynl-gen: switch to family struct Jakub Kicinski
2023-06-02  2:35 ` [PATCH net-next 10/10] tools: ynl-gen: generate static descriptions of notifications Jakub Kicinski
2023-06-03  6:30 ` [PATCH net-next 00/10] tools: ynl-gen: dust off the user space code 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=20230602023548.463441-9-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --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;
as well as URLs for NNTP newsgroup(s).