Re: [PATCH net-next 2/2] tools: ynl: check alloc fails in generated code
Jakub Kicinski <[email protected]> Tue, 4 Aug 2026 14:33:59 -0700
| Newsgroups | gmane.linux.network,gmane.linux.kernel |
|---|---|
| Message-ID | <[email protected]> |
On Mon, 3 Aug 2026 20:16:52 +0000 Thaison Phan wrote:
> def _setter_lines(self, ri, member, presence):
> - return [f"{presence} = len;",
> - f"{member} = malloc({presence});",
> + return [f"{member} = malloc(len);",
> + f"if (!{member})",
> + "return;",
> + f"{presence} = len;",
> f'memcpy({member}, {self.c_name}, {presence});']
Silently eating errors in setters does not seem great, better to crash
and make it clear than things are not working than have a silently
misconfigured system?
AI also points out that setters are preceded by a free (in case we're
replacing existing attr, multiple sets on a single attr are allowed)
So if alloc fails we'll end up with NULL ptr and len from previous
allocation.
Maybe tackle the setters in a separate patch, and keep patch 2 scoped
to the easier case?
--
pw-bot: cr