Skip to content

Commit ad4fafc

Browse files
kuba-moodavem330
authored andcommitted
tools: ynl: use 1 as the default for first entry in attrs/ops
Pretty much all families use value: 1 or reserve as unspec the first entry in attribute set and the first operation. Make this the default. Update documentation (the doc for values of operations just refers back to doc for attrs so updating only attrs). Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7cf9353 commit ad4fafc

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

Documentation/userspace-api/netlink/specs.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,12 @@ value
197197
Numerical attribute ID, used in serialized Netlink messages.
198198
The ``value`` property can be skipped, in which case the attribute ID
199199
will be the value of the previous attribute plus one (recursively)
200-
and ``0`` for the first attribute in the attribute set.
200+
and ``1`` for the first attribute in the attribute set.
201+
202+
Attributes (and operations) use ``1`` as the default value for the first
203+
entry (unlike enums in definitions which start from ``0``) because
204+
entry ``0`` is almost always reserved as undefined. Spec can explicitly
205+
set value to ``0`` if needed.
201206

202207
Note that the ``value`` of an attribute is defined only in its main set
203208
(not in subsets).

tools/net/ynl/lib/nlspec.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def __init__(self, family, yaml):
9696
self.attrs_by_val = collections.OrderedDict()
9797

9898
if self.subset_of is None:
99-
val = 0
99+
val = 1
100100
for elem in self.yaml['attributes']:
101101
if 'value' in elem:
102102
val = elem['value']
@@ -252,7 +252,7 @@ def add_unresolved(self, elem):
252252
self._resolution_list.append(elem)
253253

254254
def _dictify_ops_unified(self):
255-
val = 0
255+
val = 1
256256
for elem in self.yaml['operations']['list']:
257257
if 'value' in elem:
258258
val = elem['value']
@@ -263,7 +263,7 @@ def _dictify_ops_unified(self):
263263
self.msgs[op.name] = op
264264

265265
def _dictify_ops_directional(self):
266-
req_val = rsp_val = 0
266+
req_val = rsp_val = 1
267267
for elem in self.yaml['operations']['list']:
268268
if 'notify' in elem:
269269
if 'value' in elem:

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2044,14 +2044,17 @@ def render_uapi(family, cw):
20442044
max_value = f"({cnt_name} - 1)"
20452045

20462046
uapi_enum_start(family, cw, family['operations'], 'enum-name')
2047+
val = 0
20472048
for op in family.msgs.values():
20482049
if separate_ntf and ('notify' in op or 'event' in op):
20492050
continue
20502051

20512052
suffix = ','
2052-
if 'value' in op:
2053-
suffix = f" = {op['value']},"
2053+
if op.value != val:
2054+
suffix = f" = {op.value},"
2055+
val = op.value
20542056
cw.p(op.enum_name + suffix)
2057+
val += 1
20552058
cw.nl()
20562059
cw.p(cnt_name + ('' if max_by_define else ','))
20572060
if not max_by_define:

0 commit comments

Comments
 (0)