diff mbox series

[net-next,v3,1/2] tools: ynl-gen: fix enum index in _decode_enum(..)

Message ID 20230718162225.231775-2-arkadiusz.kubalewski@intel.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series tools: ynl-gen: fix parse multi-attr enum attribute | 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: 9 this patch: 9
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 9 this patch: 9
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: 9 this patch: 9
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

Kubalewski, Arkadiusz July 18, 2023, 4:22 p.m. UTC
Remove wrong index adjustement, which is leftover from adding
support for sparse enums.
enum.entries_by_val() function shall not subtract the start-value, as
it is indexed with real enum value.

Fixes: c311aaa74ca1 ("tools: ynl: fix enum-as-flags in the generic CLI")
Signed-off-by: Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com>
---
 tools/net/ynl/lib/ynl.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Jakub Kicinski July 19, 2023, 3:17 a.m. UTC | #1
On Tue, 18 Jul 2023 18:22:24 +0200 Arkadiusz Kubalewski wrote:
> -        i = attr_spec.get('value-start', 0)
>          if 'enum-as-flags' in attr_spec and attr_spec['enum-as-flags']:
> +            i = attr_spec.get('value-start', 0)

Just:
		i = 0
Kubalewski, Arkadiusz July 19, 2023, 9:09 p.m. UTC | #2
>From: Jakub Kicinski <kuba@kernel.org>
>Sent: Wednesday, July 19, 2023 5:17 AM
>
>On Tue, 18 Jul 2023 18:22:24 +0200 Arkadiusz Kubalewski wrote:
>> -        i = attr_spec.get('value-start', 0)
>>          if 'enum-as-flags' in attr_spec and attr_spec['enum-as-flags']:
>> +            i = attr_spec.get('value-start', 0)
>
>Just:
>		i = 0

Sure, will do.

Thank you!
Arkadiusz

>--
>pw-bot: cr
Simon Horman July 21, 2023, 8:54 a.m. UTC | #3
On Tue, Jul 18, 2023 at 06:22:24PM +0200, Arkadiusz Kubalewski wrote:
> Remove wrong index adjustement, which is leftover from adding

nit: adjustement -> adjustment

...
Kubalewski, Arkadiusz July 25, 2023, 10:20 a.m. UTC | #4
>From: Simon Horman <simon.horman@corigine.com>
>Sent: Friday, July 21, 2023 10:55 AM
>
>On Tue, Jul 18, 2023 at 06:22:24PM +0200, Arkadiusz Kubalewski wrote:
>> Remove wrong index adjustement, which is leftover from adding
>
>nit: adjustement -> adjustment
>

Yes, fixed.

Thank you!
Arkadiusz

>...
diff mbox series

Patch

diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
index 1b3a36fbb1c3..5db7d47067f9 100644
--- a/tools/net/ynl/lib/ynl.py
+++ b/tools/net/ynl/lib/ynl.py
@@ -420,8 +420,8 @@  class YnlFamily(SpecFamily):
     def _decode_enum(self, rsp, attr_spec):
         raw = rsp[attr_spec['name']]
         enum = self.consts[attr_spec['enum']]
-        i = attr_spec.get('value-start', 0)
         if 'enum-as-flags' in attr_spec and attr_spec['enum-as-flags']:
+            i = attr_spec.get('value-start', 0)
             value = set()
             while raw:
                 if raw & 1:
@@ -429,7 +429,7 @@  class YnlFamily(SpecFamily):
                 raw >>= 1
                 i += 1
         else:
-            value = enum.entries_by_val[raw - i].name
+            value = enum.entries_by_val[raw].name
         rsp[attr_spec['name']] = value
 
     def _decode_binary(self, attr, attr_spec):