lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <m2ldof9sxs.fsf@gmail.com>
Date: Wed, 23 Jul 2025 10:07:11 +0100
From: Donald Hunter <donald.hunter@...il.com>
To: Jakub Kicinski <kuba@...nel.org>
Cc: davem@...emloft.net,  netdev@...r.kernel.org,  edumazet@...gle.com,
  pabeni@...hat.com,  andrew+netdev@...n.ch,  horms@...nel.org,
  almasrymina@...gle.com,  sdf@...ichev.me
Subject: Re: [PATCH net-next 3/5] tools: ynl-gen: print alloc helper for
 multi-val attrs

Jakub Kicinski <kuba@...nel.org> writes:

> In general YNL provides allocation and free helpers for types.
> For pure nested structs which are used as multi-attr (and therefore
> have to be allocated dynamically) we already print a free helper
> as it's needed by free of the containing struct.
>
> Add printing of the alloc helper for consistency. The helper
> takes the number of entries to allocate as an argument, e.g.:
>
>   static inline struct netdev_queue_id *netdev_queue_id_alloc(unsigned int n)
>   {
> 	return calloc(n, sizeof(struct netdev_queue_id));
>   }
>
> Signed-off-by: Jakub Kicinski <kuba@...nel.org>
> ---
>  tools/net/ynl/pyynl/ynl_gen_c.py | 19 ++++++++++++++++---
>  1 file changed, 16 insertions(+), 3 deletions(-)
>
> diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen_c.py
> index dc78542e6c88..0394b786aa93 100755
> --- a/tools/net/ynl/pyynl/ynl_gen_c.py
> +++ b/tools/net/ynl/pyynl/ynl_gen_c.py
> @@ -2472,11 +2472,22 @@ _C_KW = {
>      return 'obj'
>  
>  
> -def print_alloc_wrapper(ri, direction):
> +def print_alloc_wrapper(ri, direction, struct=None):
>      name = op_prefix(ri, direction)
> -    ri.cw.write_func_prot(f'static inline struct {name} *', f"{name}_alloc", [f"void"])
> +    struct_name = name
> +    if ri.type_name_conflict:
> +        struct_name += '_'
> +
> +    arg = ["void"]

Minor nit: maybe should be args since it is a list, or change it to
arg = "void" and listify in the write_func_prot() call.

Reviewed-by: Donald Hunter <donald.hunter@...il.com>

> +    cnt = "1"
> +    if struct and struct.in_multi_val:
> +        arg = ["unsigned int n"]
> +        cnt = "n"
> +
> +    ri.cw.write_func_prot(f'static inline struct {struct_name} *',
> +                          f"{name}_alloc", arg)
>      ri.cw.block_start()
> -    ri.cw.p(f'return calloc(1, sizeof(struct {name}));')
> +    ri.cw.p(f'return calloc({cnt}, sizeof(struct {struct_name}));')
>      ri.cw.block_end()
>  
>  
> @@ -2547,6 +2558,8 @@ _C_KW = {
>      _print_type(ri, "", struct)
>  
>      if struct.request and struct.in_multi_val:
> +        print_alloc_wrapper(ri, "", struct)
> +        ri.cw.nl()
>          free_rsp_nested_prototype(ri)
>          ri.cw.nl()

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ