Skip to content

Commit

Permalink
tools: ynl-gen: fix unused / pad attribute handling
Browse files Browse the repository at this point in the history
Unused and Pad attributes don't carry information.
Unused should never exist, and be rejected.
Pad should be silently skipped.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jakub Kicinski committed Jun 3, 2023
1 parent 91dfaef commit 6ad4983
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions tools/net/ynl/ynl-gen-c.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def attr_get(self, ri, var, first):
for line in lines:
ri.cw.p(line)
ri.cw.block_end()
return True

def _setter_lines(self, ri, member, presence):
raise Exception(f"Setter not implemented for class type {self.type}")
Expand Down Expand Up @@ -197,6 +198,12 @@ class TypeUnused(Type):
def presence_type(self):
return ''

def arg_member(self, ri):
return []

def _attr_get(self, ri, var):
return ['return MNL_CB_ERROR;'], None, None

def _attr_typol(self):
return '.type = YNL_PT_REJECT, '

Expand All @@ -208,8 +215,14 @@ class TypePad(Type):
def presence_type(self):
return ''

def arg_member(self, ri):
return []

def _attr_typol(self):
return '.type = YNL_PT_REJECT, '
return '.type = YNL_PT_IGNORE, '

def attr_get(self, ri, var, first):
pass

def attr_policy(self, cw):
pass
Expand Down Expand Up @@ -1211,8 +1224,9 @@ def _multi_parse(ri, struct, init_lines, local_vars):

first = True
for _, arg in struct.member_list():
arg.attr_get(ri, 'dst', first=first)
first = False
good = arg.attr_get(ri, 'dst', first=first)
# First may be 'unused' or 'pad', ignore those
first &= not good

ri.cw.block_end()
ri.cw.nl()
Expand Down

0 comments on commit 6ad4983

Please sign in to comment.