diff mbox series

[net-next,1/8] tools: ynl: fix render-max for flags definition

Message ID b4359cc25819674de797029eb7e4a746853c1df4.1678200041.git.lorenzo@kernel.org (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series update xdp_features flag according to NIC re-configuration | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 20 this patch: 20
netdev/cc_maintainers fail 1 blamed authors not CCed: sdf@google.com; 1 maintainers not CCed: sdf@google.com
netdev/build_clang success Errors and warnings before: 18 this patch: 18
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 20 this patch: 20
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 17 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Lorenzo Bianconi March 7, 2023, 2:53 p.m. UTC
Properly manage render-max property for flags definition type
introducing mask value and setting it to (last_element << 1) - 1
instead of adding max value set to last_element + 1

Fixes: be5bea1cc0bf ("net: add basic C code generators for Netlink")
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 tools/net/ynl/ynl-gen-c.py | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Comments

Jakub Kicinski March 8, 2023, 8:06 a.m. UTC | #1
On Tue,  7 Mar 2023 15:53:58 +0100 Lorenzo Bianconi wrote:
> Properly manage render-max property for flags definition type
> introducing mask value and setting it to (last_element << 1) - 1
> instead of adding max value set to last_element + 1
> 
> Fixes: be5bea1cc0bf ("net: add basic C code generators for Netlink")
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> ---
>  tools/net/ynl/ynl-gen-c.py | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/net/ynl/ynl-gen-c.py b/tools/net/ynl/ynl-gen-c.py
> index 274e9c566f61..f2e41dd962d4 100755
> --- a/tools/net/ynl/ynl-gen-c.py
> +++ b/tools/net/ynl/ynl-gen-c.py
> @@ -1995,9 +1995,14 @@ def render_uapi(family, cw):
>  
>              if const.get('render-max', False):
>                  cw.nl()
> -                max_name = c_upper(name_pfx + 'max')
> -                cw.p('__' + max_name + ',')
> -                cw.p(max_name + ' = (__' + max_name + ' - 1)')
> +                if const['type'] == 'flags':
> +                    max_name = c_upper(name_pfx + 'mask')
> +                    max_val = f' = {(entry.user_value() << 1) - 1},'

Hm, why not use const.get_mask() here? Rather than the last entry?

> +                    cw.p(max_name + max_val)
> +                else:
> +                    max_name = c_upper(name_pfx + 'max')
> +                    cw.p('__' + max_name + ',')
> +                    cw.p(max_name + ' = (__' + max_name + ' - 1)')
>              cw.block_end(line=';')
>              cw.nl()
>          elif const['type'] == 'const':
Lorenzo Bianconi March 8, 2023, 10:28 a.m. UTC | #2
> On Tue,  7 Mar 2023 15:53:58 +0100 Lorenzo Bianconi wrote:
> > Properly manage render-max property for flags definition type
> > introducing mask value and setting it to (last_element << 1) - 1
> > instead of adding max value set to last_element + 1
> > 
> > Fixes: be5bea1cc0bf ("net: add basic C code generators for Netlink")
> > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> > ---
> >  tools/net/ynl/ynl-gen-c.py | 11 ++++++++---
> >  1 file changed, 8 insertions(+), 3 deletions(-)
> > 
> > diff --git a/tools/net/ynl/ynl-gen-c.py b/tools/net/ynl/ynl-gen-c.py
> > index 274e9c566f61..f2e41dd962d4 100755
> > --- a/tools/net/ynl/ynl-gen-c.py
> > +++ b/tools/net/ynl/ynl-gen-c.py
> > @@ -1995,9 +1995,14 @@ def render_uapi(family, cw):
> >  
> >              if const.get('render-max', False):
> >                  cw.nl()
> > -                max_name = c_upper(name_pfx + 'max')
> > -                cw.p('__' + max_name + ',')
> > -                cw.p(max_name + ' = (__' + max_name + ' - 1)')
> > +                if const['type'] == 'flags':
> > +                    max_name = c_upper(name_pfx + 'mask')
> > +                    max_val = f' = {(entry.user_value() << 1) - 1},'
> 
> Hm, why not use const.get_mask() here? Rather than the last entry?

actually I did this change but it ended up in patch 3/8. I will fix it in v2.

Regards,
Lorenzo

> 
> > +                    cw.p(max_name + max_val)
> > +                else:
> > +                    max_name = c_upper(name_pfx + 'max')
> > +                    cw.p('__' + max_name + ',')
> > +                    cw.p(max_name + ' = (__' + max_name + ' - 1)')
> >              cw.block_end(line=';')
> >              cw.nl()
> >          elif const['type'] == 'const':
>
diff mbox series

Patch

diff --git a/tools/net/ynl/ynl-gen-c.py b/tools/net/ynl/ynl-gen-c.py
index 274e9c566f61..f2e41dd962d4 100755
--- a/tools/net/ynl/ynl-gen-c.py
+++ b/tools/net/ynl/ynl-gen-c.py
@@ -1995,9 +1995,14 @@  def render_uapi(family, cw):
 
             if const.get('render-max', False):
                 cw.nl()
-                max_name = c_upper(name_pfx + 'max')
-                cw.p('__' + max_name + ',')
-                cw.p(max_name + ' = (__' + max_name + ' - 1)')
+                if const['type'] == 'flags':
+                    max_name = c_upper(name_pfx + 'mask')
+                    max_val = f' = {(entry.user_value() << 1) - 1},'
+                    cw.p(max_name + max_val)
+                else:
+                    max_name = c_upper(name_pfx + 'max')
+                    cw.p('__' + max_name + ',')
+                    cw.p(max_name + ' = (__' + max_name + ' - 1)')
             cw.block_end(line=';')
             cw.nl()
         elif const['type'] == 'const':