From nobody Mon Dec 1 22:05:09 2025 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DAB81261B6E for ; Sat, 29 Nov 2025 12:15:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764418528; cv=none; b=kxqk5MHvHLBVd9GUsrO3dagivxtf0LutQCZKIgfFgJ9esqBfPpEE9Zc7oAVo+mELwk1PjmvFJ20ir7P4xYJ2AU4sm3tCNBh1lO2LFHqQFD3bDhIaDwx09AFJ+o8hpvaOLzcUgPa6Ng/nz0xBzLNJ1SQ0dQH0N6eUQ1kE8pv/HXA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764418528; c=relaxed/simple; bh=xY0uWZHryLCto/bq7hjsFu2HnqYzhnHE9bfKCs5x3yw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=AgKPpbwMOGhar8BThFWuB+pjLI+Nv5jxx5PpYCcjOEKUWnjOvy65VF++rl9K87GVExXh7L3D9xGg/L/d5CQ0EWaPv/SWANGdkaTSVWzPe8hPmvcqa1n45KuEXfBG8t87XnkZyRceUZ38+l3jozgj5U6FrRtXLY3dEN5W/lpf7Gc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=DP+0Dr7o; arc=none smtp.client-ip=209.85.210.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DP+0Dr7o" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-7b9c17dd591so2391401b3a.3 for ; Sat, 29 Nov 2025 04:15:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764418526; x=1765023326; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=IHfM4Xy0kC8kiXxllr4QHorgmLl9IzarnsBKUByCQ+4=; b=DP+0Dr7ofDSoqRo5y7Ks4lIIwq/V9G3dMBar9Pb9zr03I+tjGr7ZwVw0c+yiCVeyff NlexUiQtOwo9kFT5c6RRHfCTd1rmGpRDi3FrYto+t1OXREORIinuj9VZ8JVjT3osG4Oo W24Qcp5TkuZDUwwSD+E9VI4RFXZGzoAQORNw+iAWR/tbrjDHt7vw1i1Pv9pgdxVg32gp 9pHZB0iAQWEc+JNoNNEvVrx+FjWCHidzFLwSWRxZBh6pXlpFJKxUEAurVvSzmCtIXrf+ 0iql4LHLB/Z8R3WIxwAK7e6KXNhDp+jNt9XIRuAIbq8pPwtnKsmq98YDRHB2dAEGB3o7 yjEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764418526; x=1765023326; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=IHfM4Xy0kC8kiXxllr4QHorgmLl9IzarnsBKUByCQ+4=; b=Kbs8cr19OoOdZx1ZU294udQ7wmYeiommERvbgRvca+O6soRVdcd5lsc0OJwr2z+vEF U8GeYhuRse/VSqpN/uUYHrmlx5XU6RVN/Dz/GpLROrYi+MAqjRAtaYGl/dO7G8FV9UN4 kue+tNI66KLYjGGAbOOUKE+KRdfG67hCsGz4xEYnTq5r1FZR5acWmqu+GcwkHh+GCVH3 vLSlP6r3h3czVW3icPAUw7oEEN1lagtmx4WRWPrlvGRNxWrnBDQctUZbAh+8bUPWbBut pIlkt+Swepp1vEKi6oiMxJiRCDyJrw92FChIGpW7euvFbilPCpOOJzOCPW/iz+bsoaLV 4Njw== X-Forwarded-Encrypted: i=1; AJvYcCXf93GIHwyKv+jFJywiCs/i45aSs/9IrHGd5NA+iITEB/viHxFGQG3HMbH6N9ARERLATqo4n66CUZ+HAFo=@vger.kernel.org X-Gm-Message-State: AOJu0YyKmbSoLioIIaQWjgjG1sFA2IRxVYSmLhnAjRlLlDDjPmxGrBzR Gwk8WWl4gzaptHII+yKjY21azVZq+l74KL2Yl1/Bz9m//l6LTO3By5Gu X-Gm-Gg: ASbGncvbs4DR99PLD5McrbvkmNsRHvcXF2QzaprYPBy1mgAG7MuHiL5rglwSPPGE7X7 qsJCqgrS8XC5I3GKlaOwoJiF4iXTJ0UJLxlqHytTgYAjuoOqKWlF0m8vsykbBBMmQo3qFnRnnWd +OPRtXsBi5OA0MEJZWxm2TZ31rtMVEuYqEuR/hOFmK2FhIYcUp624gqsZPGWH/P5VvOD/oK7ljm fOPSM7ltCnVFUYkcJ8mGrW8kfCiHmoIvrx8P/JhwcDbWA3ARi/NMDnfrg0jjJGS5N0xt5oo6pCL 59gI5i0dO5YQP9tzdtpDTaA9Wzn2n6yirztLHGGzpA/9yJbc7etfuGo6rxHfsPuCnxk5+jz4dwD aperqMzTyXQgEglRkJnB59c34WuBgoueocHbVgRF4m6icW28VBl8JeN3GfrYhX/pCqgzoycwC3y ObSJ6la/9nu8XlSCRHei/ZI/5S9Mr+YQ47qqz8G3YPuL7d9SVzqbFaf6o49H0x/Ned X-Google-Smtp-Source: AGHT+IHuaKornl3F87kZqBy2wb2ySuqsQ81vIH+V1Eri71hS2x8Lag2ULOa/Xbl3KuIq1yg+grXA6Q== X-Received: by 2002:a05:6a00:1a8f:b0:7a2:8308:3c8b with SMTP id d2e1a72fcca58-7ca879e80a7mr17623751b3a.10.1764418526157; Sat, 29 Nov 2025 04:15:26 -0800 (PST) Received: from atharv-HP-Pavilion-x360-2-in-1-Laptop-14-ek1xxx.. ([103.216.213.160]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7d15e7db577sm7858615b3a.31.2025.11.29.04.15.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Nov 2025 04:15:25 -0800 (PST) From: Atharv Dubey To: arnd@arndb.de, gregkh@linuxfoundation.org Cc: ojeda@kernel.org, alex.gaynor@gmail.com, boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu, dakr@kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Atharv Dubey Subject: [PATCH v2] rust: miscdevice: use `pin_init::zeroed()` for C type initialization Date: Sat, 29 Nov 2025 17:45:13 +0530 Message-ID: <20251129121513.20738-1-atharvd440@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Replace manual zero-initialization using `MaybeUninit::zeroed().assume_init()` with `pin_init::zeroed()`. The `pin_init` helper provides a safer and clearer API for zero-initializing C structs without requiring an `unsafe` block. Link: https://github.com/Rust-for-Linux/linux/issues/1189 Signed-off-by: Atharv Dubey Reviewed-by: Alexandre Courbot --- Changes in v2: - Remove the Unwanted Comments. rust/kernel/miscdevice.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/rust/kernel/miscdevice.rs b/rust/kernel/miscdevice.rs index d698cddcb4a5..ba64c8a858f0 100644 --- a/rust/kernel/miscdevice.rs +++ b/rust/kernel/miscdevice.rs @@ -20,7 +20,7 @@ seq_file::SeqFile, types::{ForeignOwnable, Opaque}, }; -use core::{marker::PhantomData, mem::MaybeUninit, pin::Pin}; +use core::{marker::PhantomData, pin::Pin}; =20 /// Options for creating a misc device. #[derive(Copy, Clone)] @@ -32,8 +32,7 @@ pub struct MiscDeviceOptions { impl MiscDeviceOptions { /// Create a raw `struct miscdev` ready for registration. pub const fn into_raw(self) -> bindings::miscdevice { - // SAFETY: All zeros is valid for this C type. - let mut result: bindings::miscdevice =3D unsafe { MaybeUninit::zer= oed().assume_init() }; + let mut result: bindings::miscdevice =3D pin_init::zeroed(); result.minor =3D bindings::MISC_DYNAMIC_MINOR as ffi::c_int; result.name =3D crate::str::as_char_ptr_in_const_context(self.name= ); result.fops =3D MiscdeviceVTable::::build(); @@ -420,8 +419,7 @@ impl MiscdeviceVTable { } else { None }, - // SAFETY: All zeros is a valid value for `bindings::file_operatio= ns`. - ..unsafe { MaybeUninit::zeroed().assume_init() } + ..pin_init::zeroed() }; =20 const fn build() -> &'static bindings::file_operations { --=20 2.43.0