* [PATCH v2] rust: block: use pin_init::zeroed
@ 2026-01-29 3:07 Jason Hall
2026-01-29 5:27 ` Onur Özkan
0 siblings, 1 reply; 3+ messages in thread
From: Jason Hall @ 2026-01-29 3:07 UTC (permalink / raw)
To: a.hindborg, ojeda
Cc: lossin, boqun.feng, aliceryhl, rust-for-linux, linux-block,
Jason Hall
Replace manual unsafe zeroing of block structures with the safe
pin_init::zeroed() helper.
Suggested-by: Benno Lossin <lossin@kernel.org>
Link: https://github.com/Rust-for-Linux/linux/issues/1189
Signed-off-by: Jason Hall <jason.kei.hall@gmail.com>
---
rust/kernel/block/mq/gen_disk.rs | 4 +---
rust/kernel/block/mq/tag_set.rs | 4 +---
2 files changed, 2 insertions(+), 6 deletions(-)
diff --git a/rust/kernel/block/mq/gen_disk.rs b/rust/kernel/block/mq/gen_disk.rs
index 1ce815c8cdab..649c3d9b1ff9 100644
--- a/rust/kernel/block/mq/gen_disk.rs
+++ b/rust/kernel/block/mq/gen_disk.rs
@@ -106,9 +106,7 @@ pub fn build<T: Operations>(
// SAFETY: T::QueueData was created by the call to `into_foreign()` above
drop(unsafe { T::QueueData::from_foreign(data) });
});
-
- // SAFETY: `bindings::queue_limits` contain only fields that are valid when zeroed.
- let mut lim: bindings::queue_limits = unsafe { core::mem::zeroed() };
+ let mut lim: bindings::queue_limits = pin_init::zeroed();
lim.logical_block_size = self.logical_block_size;
lim.physical_block_size = self.physical_block_size;
diff --git a/rust/kernel/block/mq/tag_set.rs b/rust/kernel/block/mq/tag_set.rs
index c3cf56d52bee..dae9df408a86 100644
--- a/rust/kernel/block/mq/tag_set.rs
+++ b/rust/kernel/block/mq/tag_set.rs
@@ -38,9 +38,7 @@ pub fn new(
num_tags: u32,
num_maps: u32,
) -> impl PinInit<Self, error::Error> {
- // SAFETY: `blk_mq_tag_set` only contains integers and pointers, which
- // all are allowed to be 0.
- let tag_set: bindings::blk_mq_tag_set = unsafe { core::mem::zeroed() };
+ let tag_set: bindings::blk_mq_tag_set = pin_init::zeroed();
let tag_set: Result<_> = core::mem::size_of::<RequestDataWrapper>()
.try_into()
.map(|cmd_size| {
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] rust: block: use pin_init::zeroed
2026-01-29 3:07 [PATCH v2] rust: block: use pin_init::zeroed Jason Hall
@ 2026-01-29 5:27 ` Onur Özkan
2026-01-29 5:32 ` Onur Özkan
0 siblings, 1 reply; 3+ messages in thread
From: Onur Özkan @ 2026-01-29 5:27 UTC (permalink / raw)
To: Jason Hall
Cc: a.hindborg, ojeda, lossin, boqun.feng, aliceryhl, rust-for-linux,
linux-block
On Wed, 28 Jan 2026 20:07:32 -0700
Jason Hall <jason.kei.hall@gmail.com> wrote:
> Replace manual unsafe zeroing of block structures with the safe
> pin_init::zeroed() helper.
>
> Suggested-by: Benno Lossin <lossin@kernel.org>
> Link: https://github.com/Rust-for-Linux/linux/issues/1189
> Signed-off-by: Jason Hall <jason.kei.hall@gmail.com>
> ---
> rust/kernel/block/mq/gen_disk.rs | 4 +---
> rust/kernel/block/mq/tag_set.rs | 4 +---
> 2 files changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/rust/kernel/block/mq/gen_disk.rs
> b/rust/kernel/block/mq/gen_disk.rs index 1ce815c8cdab..649c3d9b1ff9
> 100644 --- a/rust/kernel/block/mq/gen_disk.rs
> +++ b/rust/kernel/block/mq/gen_disk.rs
> @@ -106,9 +106,7 @@ pub fn build<T: Operations>(
> // SAFETY: T::QueueData was created by the call to
> `into_foreign()` above drop(unsafe { T::QueueData::from_foreign(data)
> }); });
> -
> - // SAFETY: `bindings::queue_limits` contain only fields that
> are valid when zeroed.
> - let mut lim: bindings::queue_limits = unsafe {
> core::mem::zeroed() };
> + let mut lim: bindings::queue_limits = pin_init::zeroed();
>
> lim.logical_block_size = self.logical_block_size;
> lim.physical_block_size = self.physical_block_size;
> diff --git a/rust/kernel/block/mq/tag_set.rs
> b/rust/kernel/block/mq/tag_set.rs index c3cf56d52bee..dae9df408a86
> 100644 --- a/rust/kernel/block/mq/tag_set.rs
> +++ b/rust/kernel/block/mq/tag_set.rs
> @@ -38,9 +38,7 @@ pub fn new(
> num_tags: u32,
> num_maps: u32,
> ) -> impl PinInit<Self, error::Error> {
> - // SAFETY: `blk_mq_tag_set` only contains integers and
> pointers, which
> - // all are allowed to be 0.
> - let tag_set: bindings::blk_mq_tag_set = unsafe {
> core::mem::zeroed() };
> + let tag_set: bindings::blk_mq_tag_set = pin_init::zeroed();
> let tag_set: Result<_> =
> core::mem::size_of::<RequestDataWrapper>() .try_into()
> .map(|cmd_size| {
Reviewed-by: Onur Özkan <work@onurozkan.dev>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] rust: block: use pin_init::zeroed
2026-01-29 5:27 ` Onur Özkan
@ 2026-01-29 5:32 ` Onur Özkan
0 siblings, 0 replies; 3+ messages in thread
From: Onur Özkan @ 2026-01-29 5:32 UTC (permalink / raw)
To: Jason Hall
Cc: a.hindborg, ojeda, lossin, boqun.feng, aliceryhl, rust-for-linux,
linux-block
On Thu, 29 Jan 2026 08:27:10 +0300
Onur Özkan <work@onurozkan.dev> wrote:
> On Wed, 28 Jan 2026 20:07:32 -0700
> Jason Hall <jason.kei.hall@gmail.com> wrote:
>
> > Replace manual unsafe zeroing of block structures with the safe
> > pin_init::zeroed() helper.
> >
> > Suggested-by: Benno Lossin <lossin@kernel.org>
> > Link: https://github.com/Rust-for-Linux/linux/issues/1189
> > Signed-off-by: Jason Hall <jason.kei.hall@gmail.com>
> > ---
> > rust/kernel/block/mq/gen_disk.rs | 4 +---
> > rust/kernel/block/mq/tag_set.rs | 4 +---
> > 2 files changed, 2 insertions(+), 6 deletions(-)
> >
> > diff --git a/rust/kernel/block/mq/gen_disk.rs
> > b/rust/kernel/block/mq/gen_disk.rs index 1ce815c8cdab..649c3d9b1ff9
> > 100644 --- a/rust/kernel/block/mq/gen_disk.rs
> > +++ b/rust/kernel/block/mq/gen_disk.rs
> > @@ -106,9 +106,7 @@ pub fn build<T: Operations>(
> > // SAFETY: T::QueueData was created by the call to
> > `into_foreign()` above drop(unsafe {
> > T::QueueData::from_foreign(data) }); });
> > -
> > - // SAFETY: `bindings::queue_limits` contain only fields
> > that are valid when zeroed.
> > - let mut lim: bindings::queue_limits = unsafe {
> > core::mem::zeroed() };
> > + let mut lim: bindings::queue_limits = pin_init::zeroed();
> >
> > lim.logical_block_size = self.logical_block_size;
> > lim.physical_block_size = self.physical_block_size;
> > diff --git a/rust/kernel/block/mq/tag_set.rs
> > b/rust/kernel/block/mq/tag_set.rs index c3cf56d52bee..dae9df408a86
> > 100644 --- a/rust/kernel/block/mq/tag_set.rs
> > +++ b/rust/kernel/block/mq/tag_set.rs
> > @@ -38,9 +38,7 @@ pub fn new(
> > num_tags: u32,
> > num_maps: u32,
> > ) -> impl PinInit<Self, error::Error> {
> > - // SAFETY: `blk_mq_tag_set` only contains integers and
> > pointers, which
> > - // all are allowed to be 0.
> > - let tag_set: bindings::blk_mq_tag_set = unsafe {
> > core::mem::zeroed() };
> > + let tag_set: bindings::blk_mq_tag_set = pin_init::zeroed();
> > let tag_set: Result<_> =
> > core::mem::size_of::<RequestDataWrapper>() .try_into()
> > .map(|cmd_size| {
>
> Reviewed-by: Onur Özkan <work@onurozkan.dev>
Hmm, I just saw this [1].
[1]:
https://lore.kernel.org/rust-for-linux/176900687943.9724.14786712604002245962.b4-ty@kernel.dk/
It looks like this change has already been applied. :/
-Onur
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-01-29 5:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-29 3:07 [PATCH v2] rust: block: use pin_init::zeroed Jason Hall
2026-01-29 5:27 ` Onur Özkan
2026-01-29 5:32 ` Onur Özkan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox