mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com>
To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	kuba@kernel.org, davem@davemloft.net, pabeni@redhat.com,
	edumazet@google.com, chuck.lever@oracle.com
Cc: Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com>
Subject: [PATCH net-next] tools: ynl-gen: fix NLA_POLICY_MAX on enums with value
Date: Wed, 14 Jun 2023 01:17:08 +0200	[thread overview]
Message-ID: <20230613231709.150622-2-arkadiusz.kubalewski@intel.com> (raw)
In-Reply-To: <20230613231709.150622-1-arkadiusz.kubalewski@intel.com>

Policy defines max as length of enum list, if enum attribute is
defined with a value, generated netlink policy max value is wrong.
Calculate proper max value for policy where enums that are given
explicit value.

Signed-off-by: Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com>
---
 tools/net/ynl/ynl-gen-c.py | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/tools/net/ynl/ynl-gen-c.py b/tools/net/ynl/ynl-gen-c.py
index 4c12c6f8968e..9adcd785db0b 100755
--- a/tools/net/ynl/ynl-gen-c.py
+++ b/tools/net/ynl/ynl-gen-c.py
@@ -279,7 +279,16 @@ class TypeScalar(Type):
         elif 'enum' in self.attr:
             enum = self.family.consts[self.attr['enum']]
             cnt = len(enum['entries'])
-            return f"NLA_POLICY_MAX({policy}, {cnt - 1})"
+            values = [0] * cnt
+            for i in range(cnt):
+                if 'value' in enum['entries'][i]:
+                    values[i] = enum['entries'][i]['value']
+                else:
+                    if i == 0:
+                        values[i] = 0;
+                    else:
+                        values[i] = values[i - 1] + 1
+            return f"NLA_POLICY_MAX({policy}, {max(values)})"
         return super()._attr_policy(policy)
 
     def _attr_typol(self):
-- 
2.37.3


  reply	other threads:[~2023-06-13 23:19 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-13 23:17 [PATCH net-next] tools: ynl-gen: fix nested policy attribute type Arkadiusz Kubalewski
2023-06-13 23:17 ` Arkadiusz Kubalewski [this message]
2023-06-13 23:17 ` [PATCH net-next] tools: ynl-gen: generate docs for <name>_max/_mask enums Arkadiusz Kubalewski
2023-06-14  0:59   ` Jakub Kicinski
2023-06-14 12:48     ` Kubalewski, Arkadiusz
2023-06-14 17:38       ` Jakub Kicinski
2023-06-14 22:11         ` Kubalewski, Arkadiusz
2023-06-15  4:17           ` Jakub Kicinski
2023-06-14  0:50 ` [PATCH net-next] tools: ynl-gen: fix nested policy attribute type Jakub Kicinski
2023-06-14 12:28   ` Kubalewski, Arkadiusz

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=20230613231709.150622-2-arkadiusz.kubalewski@intel.com \
    --to=arkadiusz.kubalewski@intel.com \
    --cc=chuck.lever@oracle.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --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

all inboxes | Powered by JetHome®