Re: [PATCH net 3/4] tools: ynl-gen: fix nested array counting

Jakub Kicinski <[email protected]>
Newsgroups com.zx2c4.lists.wireguard,org.kernel.vger.linux-kernel,org.kernel.vger.netdev
Message-ID <[email protected]>
On Mon,  1 Sep 2025 14:50:22 +0000 Asbjørn Sloth Tønnesen wrote:
> 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.

Looks good, thanks!

Reviewed-by: Jakub Kicinski <[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.