The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Thaison Phan <thaisonphan@google.com>
To: kuba@kernel.org
Cc: ast@fiberby.net, davem@davemloft.net, donald.hunter@gmail.com,
	 edumazet@google.com, gfengyuan@google.com, horms@kernel.org,
	 linux-kernel@vger.kernel.org, matttbe@kernel.org,
	netdev@vger.kernel.org,  pabeni@redhat.com, stani@google.com,
	thaisonphan@google.com
Subject: Re: [PATCH net-next 2/2] tools: ynl: check alloc fails in generated code
Date: Wed,  5 Aug 2026 13:42:32 +0000	[thread overview]
Message-ID: <20260805134232.3378922-1-thaisonphan@google.com> (raw)
In-Reply-To: <20260804143359.702b0237@kernel.org>

> 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?

I was thinking that the user could check for NULL in the struct field that
the setter was allocating for to see if something went wrong, but that is
probably not ideal either since a user might assume with the void return
there can be no errors, and I didn't realize the field is not guaranteed to
be NULL when it is passed in.

> 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.

That makes sense, so we could have an unreported free() on the key someone
using the setter might think is still allocated. We could maybe delay the
free() until after the malloc() works, and maybe we could return an error
code in setters that allocate to let users know something went wrong.

> Maybe tackle the setters in a separate patch, and keep patch 2 scoped
> to the easier case?

That sounds like a good idea to me. I'll make v2 only tackle the getters
and look into a different way to handle the setters.

Thanks,
Thaison

      reply	other threads:[~2026-08-05 13:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-03 20:16 [PATCH net-next 0/2] tools: ynl: update NULL pointer handling in generated code Thaison Phan
2026-08-03 20:16 ` [PATCH net-next 1/2] tools: ynl: check for null ptr on dump free Thaison Phan
2026-08-04 21:25   ` Jakub Kicinski
2026-08-05 13:14     ` Thaison Phan
2026-08-06  0:07       ` Jakub Kicinski
2026-08-03 20:16 ` [PATCH net-next 2/2] tools: ynl: check alloc fails in generated code Thaison Phan
2026-08-04 21:33   ` Jakub Kicinski
2026-08-05 13:42     ` Thaison Phan [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260805134232.3378922-1-thaisonphan@google.com \
    --to=thaisonphan@google.com \
    --cc=ast@fiberby.net \
    --cc=davem@davemloft.net \
    --cc=donald.hunter@gmail.com \
    --cc=edumazet@google.com \
    --cc=gfengyuan@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matttbe@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stani@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox