From: "Danilo Krummrich" <dakr@kernel.org>
To: "Alexandre Courbot" <acourbot@nvidia.com>
Cc: "Thorsten Blum" <blum@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>, "Gary Guo" <gary@garyguo.net>,
"Timur Tabi" <ttabi@nvidia.com>,
"Robin Murphy" <robin.murphy@arm.com>,
"Tim Kovalenko" <tim.kovalenko@proton.me>,
<nova-gpu@lists.linux.dev>, <dri-devel@lists.freedesktop.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] gpu: nova-core: firmware: fwsec: use zeroed() to zero-pad buffers
Date: Wed, 07 Oct 2026 10:42:45 +0200 [thread overview]
Message-ID: <DLYH15Z18TCO.5CK2MNXMZUG2@kernel.org> (raw)
In-Reply-To: <DLY6MDDAUDFL.142WKY7PWTNDU@nvidia.com>
On Wed Oct 7, 2026 at 2:33 AM CEST, Alexandre Courbot wrote:
> On Wed Oct 7, 2026 at 7:20 AM JST, Danilo Krummrich wrote:
>> On Tue Oct 6, 2026 at 12:04 PM CEST, Thorsten Blum wrote:
>>> - let mut ucode = KVec::with_capacity(aligned_code_size, GFP_KERNEL)?;
>>> - ucode.extend_from_slice(code, GFP_KERNEL)?;
>>> - ucode.resize(aligned_code_size, 0, GFP_KERNEL)?;
>>> -
>>> + let mut ucode = KVec::zeroed(aligned_code_size, GFP_KERNEL)?;
>>> + ucode[..code.len()].copy_from_slice(code);
>>
>> I kinda dislike that this is now a potential panic, but it does better express
>> the intent.
>
> IMHO the original code expresses the intent just as well, and avoids
> writing the area covered by `code` twice, on top of not introducing a
> potential panic site.
I'm referring to the fact that the original code expresses "I may allocate"
three times, while the intent is that the allocation is exactly
aligned_code_size.
This is much more clear with the new code, if we really want to avoid a
potential panic here, we could use get_mut(), but the ergonomics isn't great.
That said, I wouldn't mind adding something like Vec::extend_within_capacity(),
which fails if there's not enough capacity.
Thanks,
Danilo
next prev parent reply other threads:[~2026-10-07 8:42 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-06 10:04 [PATCH] gpu: nova-core: firmware: fwsec: use zeroed() to zero-pad buffers Thorsten Blum
2026-10-06 22:20 ` Danilo Krummrich
2026-10-07 0:33 ` Alexandre Courbot
2026-10-07 8:42 ` Danilo Krummrich [this message]
2026-10-07 12:12 ` Alexandre Courbot
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=DLYH15Z18TCO.5CK2MNXMZUG2@kernel.org \
--to=dakr@kernel.org \
--cc=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=aliceryhl@google.com \
--cc=blum@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=nova-gpu@lists.linux.dev \
--cc=robin.murphy@arm.com \
--cc=simona@ffwll.ch \
--cc=tim.kovalenko@proton.me \
--cc=ttabi@nvidia.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.