Skip to content

Commit 93e505a

Browse files
committed
tools: ynl-gen-c: improve support for empty nests
Empty nests are the same size as a flag at the netlink level (just a 4 byte nlattr without a payload). They are sometimes useful in case we want to only communicate a presence of something but may want to add more details later. This may be the case in the upcoming io_uring ZC patches, for example. Improve handling of nested empty structs. We already support empty structs since a lot of netlink replies are empty, but for nested ones we need minor tweaks to avoid pointless empty lines and unused variables. Acked-by: Stanislav Fomichev <[email protected]> Reviewed-by: Nicolas Dichtel <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent a3116a4 commit 93e505a

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

tools/net/ynl/ynl-gen-c.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,7 +1783,14 @@ def parse_rsp_nested(ri, struct):
17831783
f'{struct.ptr_name}dst = yarg->data;']
17841784
init_lines = []
17851785

1786-
_multi_parse(ri, struct, init_lines, local_vars)
1786+
if struct.member_list():
1787+
_multi_parse(ri, struct, init_lines, local_vars)
1788+
else:
1789+
# Empty nest
1790+
ri.cw.block_start()
1791+
ri.cw.p('return 0;')
1792+
ri.cw.block_end()
1793+
ri.cw.nl()
17871794

17881795

17891796
def parse_rsp_msg(ri, deref=False):
@@ -2610,7 +2617,8 @@ def render_uapi(family, cw):
26102617
val = attr.value
26112618
val += 1
26122619
cw.p(attr.enum_name + suffix)
2613-
cw.nl()
2620+
if attr_set.items():
2621+
cw.nl()
26142622
cw.p(attr_set.cnt_name + ('' if max_by_define else ','))
26152623
if not max_by_define:
26162624
cw.p(f"{attr_set.max_name} = {max_value}")

0 commit comments

Comments
 (0)