* [PATCH] gpu: nova-core: firmware: fwsec: use zeroed() to zero-pad buffers
@ 2026-10-06 10:04 Thorsten Blum
2026-10-06 22:20 ` Danilo Krummrich
0 siblings, 1 reply; 3+ messages in thread
From: Thorsten Blum @ 2026-10-06 10:04 UTC (permalink / raw)
To: Danilo Krummrich, Alice Ryhl, Alexandre Courbot, David Airlie,
Simona Vetter, Gary Guo, Timur Tabi, Robin Murphy, Tim Kovalenko
Cc: Thorsten Blum, nova-gpu, dri-devel, linux-kernel
Use KVec::zeroed() to allocate the zero-padded microcode buffer and copy
the bootloader code into it. Also use KVVec::zeroed() to initialize the
firmware object's leading zero padding.
Signed-off-by: Thorsten Blum <blum@kernel.org>
---
drivers/gpu/nova-core/firmware/fwsec/bootloader.rs | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/nova-core/firmware/fwsec/bootloader.rs b/drivers/gpu/nova-core/firmware/fwsec/bootloader.rs
index ec4d92317a93..37dcd4bf4711 100644
--- a/drivers/gpu/nova-core/firmware/fwsec/bootloader.rs
+++ b/drivers/gpu/nova-core/firmware/fwsec/bootloader.rs
@@ -137,10 +137,8 @@ pub(crate) fn new(
.align_up(Alignment::new::<{ falcon::MEM_BLOCK_ALIGNMENT }>())
.ok_or(EINVAL)?;
- 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);
ucode
};
@@ -162,8 +160,7 @@ pub(crate) fn new(
.ok_or(EOVERFLOW)?
};
- let mut firmware_obj = KVVec::new();
- firmware_obj.extend_with(align_padding, 0u8, GFP_KERNEL)?;
+ let mut firmware_obj = KVVec::zeroed(align_padding, GFP_KERNEL)?;
firmware_obj.extend_from_slice(firmware.ucode.0.as_slice(), GFP_KERNEL)?;
(
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] gpu: nova-core: firmware: fwsec: use zeroed() to zero-pad buffers
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
0 siblings, 1 reply; 3+ messages in thread
From: Danilo Krummrich @ 2026-10-06 22:20 UTC (permalink / raw)
To: Thorsten Blum
Cc: Alice Ryhl, Alexandre Courbot, David Airlie, Simona Vetter,
Gary Guo, Timur Tabi, Robin Murphy, Tim Kovalenko, nova-gpu,
dri-devel, linux-kernel
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.
Can you please add a corresponding // PANIC comment?
Thanks,
Danilo
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] gpu: nova-core: firmware: fwsec: use zeroed() to zero-pad buffers
2026-10-06 22:20 ` Danilo Krummrich
@ 2026-10-07 0:33 ` Alexandre Courbot
0 siblings, 0 replies; 3+ messages in thread
From: Alexandre Courbot @ 2026-10-07 0:33 UTC (permalink / raw)
To: Danilo Krummrich
Cc: Thorsten Blum, Alice Ryhl, David Airlie, Simona Vetter, Gary Guo,
Timur Tabi, Robin Murphy, Tim Kovalenko, nova-gpu, dri-devel,
linux-kernel
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-10-07 0:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®