tools: ynl-gen: fix nested array counting
authorAsbjørn Sloth Tønnesen <ast@fiberby.net>
Tue, 2 Sep 2025 15:59:59 +0000 (15:59 +0000)
committerJakub Kicinski <kuba@kernel.org>
Wed, 3 Sep 2025 22:18:34 +0000 (15:18 -0700)
commitb4ada0618eed0fbd1b1630f73deb048c592b06a1
treefad66dd6c6f810711b5f798423db20e9f1c938d5
parentc5142df58d5a19a0615414037f256cd5ca39f7c5
tools: ynl-gen: fix nested array counting

The blamed commit introduced the concept of split attribute
counting, and later allocating an array to hold them, however
TypeArrayNest wasn't updated to use the new counting variable.

Abbreviated example from tools/net/ynl/generated/nl80211-user.c:
nl80211_if_combination_attributes_parse(...):
  unsigned int n_limits = 0;
  [...]
  ynl_attr_for_each(attr, nlh, yarg->ys->family->hdr_len)
if (type == NL80211_IFACE_COMB_LIMITS)
ynl_attr_for_each_nested(attr2, attr)
dst->_count.limits++;
  if (n_limits) {
dst->_count.limits = n_limits;
/* allocate and parse attributes */
  }

In the above example n_limits is guaranteed to always be 0,
hence the conditional is unsatisfiable and is optimized out.

This patch changes the attribute counting to use n_limits++ in the
attribute counting loop in the above example.

Fixes: 58da455b31ba ("tools: ynl-gen: improve unwind on parsing errors")
Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net>
Link: https://patch.msgid.link/20250902160001.760953-1-ast@fiberby.net
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/net/ynl/pyynl/ynl_gen_c.py