rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rust: acpi: replace manual zero-initialization with `pin_init::zeroed()`
@ 2025-11-29 12:27 Atharv Dubey
  2025-12-01  3:36 ` Alexandre Courbot
  0 siblings, 1 reply; 3+ messages in thread
From: Atharv Dubey @ 2025-11-29 12:27 UTC (permalink / raw)
  To: rafael, lenb
  Cc: ojeda, alex.gaynor, boqun.feng, gary, bjorn3_gh, lossin,
	a.hindborg, aliceryhl, tmgross, dakr, linux-acpi, rust-for-linux,
	linux-kernel, Atharv Dubey

Use `pin_init::zeroed()` instead of `core::mem::zeroed()` for initializing
`acpi_device_id`. This removes an explicit unsafe block and aligns ACPI
initialization with the pin-init conversion used across the Rust tree.

Link: https://github.com/Rust-for-Linux/linux/issues/1189
Signed-off-by: Atharv Dubey <atharvd440@gmail.com>
---
 rust/kernel/acpi.rs | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/rust/kernel/acpi.rs b/rust/kernel/acpi.rs
index 37e1161c1298..9b8efa623130 100644
--- a/rust/kernel/acpi.rs
+++ b/rust/kernel/acpi.rs
@@ -39,9 +39,7 @@ impl DeviceId {
     pub const fn new(id: &'static CStr) -> Self {
         let src = id.to_bytes_with_nul();
         build_assert!(src.len() <= Self::ACPI_ID_LEN, "ID exceeds 16 bytes");
-        // Replace with `bindings::acpi_device_id::default()` once stabilized for `const`.
-        // SAFETY: FFI type is valid to be zero-initialized.
-        let mut acpi: bindings::acpi_device_id = unsafe { core::mem::zeroed() };
+        let mut acpi: bindings::acpi_device_id = pin_init::zeroed();
         let mut i = 0;
         while i < src.len() {
             acpi.id[i] = src[i];
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] rust: acpi: replace manual zero-initialization with `pin_init::zeroed()`
  2025-11-29 12:27 [PATCH] rust: acpi: replace manual zero-initialization with `pin_init::zeroed()` Atharv Dubey
@ 2025-12-01  3:36 ` Alexandre Courbot
  2025-12-01 14:31   ` Atharv Dubey
  0 siblings, 1 reply; 3+ messages in thread
From: Alexandre Courbot @ 2025-12-01  3:36 UTC (permalink / raw)
  To: Atharv Dubey, rafael, lenb
  Cc: ojeda, alex.gaynor, boqun.feng, gary, bjorn3_gh, lossin,
	a.hindborg, aliceryhl, tmgross, dakr, linux-acpi, rust-for-linux,
	linux-kernel

On Sat Nov 29, 2025 at 9:27 PM JST, Atharv Dubey wrote:
> Use `pin_init::zeroed()` instead of `core::mem::zeroed()` for initializing
> `acpi_device_id`. This removes an explicit unsafe block and aligns ACPI
> initialization with the pin-init conversion used across the Rust tree.
>
> Link: https://github.com/Rust-for-Linux/linux/issues/1189
> Signed-off-by: Atharv Dubey <atharvd440@gmail.com>
> ---
>  rust/kernel/acpi.rs | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/rust/kernel/acpi.rs b/rust/kernel/acpi.rs
> index 37e1161c1298..9b8efa623130 100644
> --- a/rust/kernel/acpi.rs
> +++ b/rust/kernel/acpi.rs
> @@ -39,9 +39,7 @@ impl DeviceId {
>      pub const fn new(id: &'static CStr) -> Self {
>          let src = id.to_bytes_with_nul();
>          build_assert!(src.len() <= Self::ACPI_ID_LEN, "ID exceeds 16 bytes");
> -        // Replace with `bindings::acpi_device_id::default()` once stabilized for `const`.

Let's keep this comment as well.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] rust: acpi: replace manual zero-initialization with `pin_init::zeroed()`
  2025-12-01  3:36 ` Alexandre Courbot
@ 2025-12-01 14:31   ` Atharv Dubey
  0 siblings, 0 replies; 3+ messages in thread
From: Atharv Dubey @ 2025-12-01 14:31 UTC (permalink / raw)
  To: Alexandre Courbot
  Cc: rafael, lenb, ojeda, alex.gaynor, boqun.feng, gary, bjorn3_gh,
	lossin, a.hindborg, aliceryhl, tmgross, dakr, linux-acpi,
	rust-for-linux, linux-kernel

On Mon, Dec 01, 2025 at 12:36:22PM +0900, Alexandre Courbot wrote:
> On Sat Nov 29, 2025 at 9:27 PM JST, Atharv Dubey wrote:
> > Use `pin_init::zeroed()` instead of `core::mem::zeroed()` for initializing
> > `acpi_device_id`. This removes an explicit unsafe block and aligns ACPI
> > initialization with the pin-init conversion used across the Rust tree.
> >
> > Link: https://github.com/Rust-for-Linux/linux/issues/1189
> > Signed-off-by: Atharv Dubey <atharvd440@gmail.com>
> > ---
> >  rust/kernel/acpi.rs | 4 +---
> >  1 file changed, 1 insertion(+), 3 deletions(-)
> >
> > diff --git a/rust/kernel/acpi.rs b/rust/kernel/acpi.rs
> > index 37e1161c1298..9b8efa623130 100644
> > --- a/rust/kernel/acpi.rs
> > +++ b/rust/kernel/acpi.rs
> > @@ -39,9 +39,7 @@ impl DeviceId {
> >      pub const fn new(id: &'static CStr) -> Self {
> >          let src = id.to_bytes_with_nul();
> >          build_assert!(src.len() <= Self::ACPI_ID_LEN, "ID exceeds 16 bytes");
> > -        // Replace with `bindings::acpi_device_id::default()` once stabilized for `const`.
> 
> Let's keep this comment as well.
> > Sure, will add the comment in V2 of the patch  
> > -Atharv

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-12-01 14:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-29 12:27 [PATCH] rust: acpi: replace manual zero-initialization with `pin_init::zeroed()` Atharv Dubey
2025-12-01  3:36 ` Alexandre Courbot
2025-12-01 14:31   ` Atharv Dubey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).