]> www.infradead.org Git - users/hch/misc.git/commit
tools: ynl-gen: individually free previous values on double set
authorJakub Kicinski <kuba@kernel.org>
Mon, 14 Apr 2025 21:18:46 +0000 (14:18 -0700)
committerJakub Kicinski <kuba@kernel.org>
Thu, 17 Apr 2025 01:09:41 +0000 (18:09 -0700)
commitce6cb8113c842b94e77364b247c4f85c7b34e0c2
tree1a99f0ef128e10631b8ea9624187fdb8f3cb00b4
parentdfa464b4a603984d648a9beb9bce72df5858c1e2
tools: ynl-gen: individually free previous values on double set

When user calls request_attrA_set() multiple times (for the same
attribute), and attrA is of type which allocates memory -
we try to free the previously associated values. For array
types (including multi-attr) we have only freed the array,
but the array may have contained pointers.

Refactor the code generation for free attr and reuse the generated
lines in setters to flush out the previous state. Since setters
are static inlines in the header we need to add forward declarations
for the free helpers of pure nested structs. Track which types get
used by arrays and include the right forwad declarations.

At least ethtool string set and bit set would not be freed without
this. Tho, admittedly, overriding already set attribute twice is likely
a very very rare thing to do.

Fixes: be5bea1cc0bf ("net: add basic C code generators for Netlink")
Reviewed-by: Donald Hunter <donald.hunter@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Link: https://patch.msgid.link/20250414211851.602096-4-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/net/ynl/pyynl/ynl_gen_c.py