lkml.org 
[lkml]   [2026]   [Aug]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH net-next 2/2] tools: ynl: check alloc fails in generated code
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

\
 
 \ /
  Last update: 2026-08-04 23:35    [W:0.060 / U:1.619 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and my Meterkast|Read the blog