From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f43.google.com (mail-dl1-f43.google.com [74.125.82.43]) (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 ED83D2F690F for ; Thu, 25 Jun 2026 22:50:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782427808; cv=none; b=Xkw08EsNT6kJQhOYNweoEd2csn8rZcqpKmcZDmJUCfMGEbi0atKj1a0mZ+I/tL6LR3X7Wy2oPeI8KLiP5jxemo/349ne6EGVHAd7AMfrUWqr72+unjMDnwq8ujHbcHRHItQvlrEp02ZFGhe/K9AroHsRMIAl9nesnaKHPuYeUdE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782427808; c=relaxed/simple; bh=7riy9zn2yRm3WP7DkxKFf+IbEEHQoczVIT4zDHaLIko=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=YmMng2hK6XOG172AohllykRd16zgbEVk14hfYNXO76+TZAvaxyZROQbTWdWRVVtz1y/biXDmm1ShZz0k50rIIaDLauxmdWy0xexCsJqhs3zmtRh0vgmmkPPhXHBslF7oRDOTT+pEpSelTWO8rdBmEHeprhQD66jiU5WughK9Mbg= 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=Bo0l7lWC; arc=none smtp.client-ip=74.125.82.43 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="Bo0l7lWC" Received: by mail-dl1-f43.google.com with SMTP id a92af1059eb24-1363fe80fe8so907803c88.0 for ; Thu, 25 Jun 2026 15:50:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782427806; x=1783032606; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:message-id:date :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=zP2Z25CXAppf+hFBp9V7dUyW6AOwxGrvIlERxMVxgnc=; b=Bo0l7lWCXORfkC78gIbdnmgrxIpunS2187gWXOVy79lwdMp/o6ew1lBY8YB7lbcLSV iUY8YkD/Gvj99K+CQp7KOdsUIlrCXkTstV01CO/fu8y5+c+YCQ659IJX6/Q29l5krNCp TfCClpJzgbQMuu5+9nvvo0+jyFFtBZta1et3GtX3N/Amd+GZjDgEm60U5rIln2xsfaYk kPiIv8B/z8WQOA5pnerutENBqovFJlYHi3RVj2iaoPuej4zcvInluV/wBX1AaUTeih8K y2VQvhYXOssWi+gEsWO6Eh8JQlmerVacCSmdjOI7Spfqhe6eO6sjMmSGRBW+DhmsHmTN iKwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782427806; x=1783032606; h=content-transfer-encoding:content-type: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:content-type; bh=zP2Z25CXAppf+hFBp9V7dUyW6AOwxGrvIlERxMVxgnc=; b=iJxsrj1Tum22nmGUashvEhToRaYSY6twGNLmyEymjZUFtiyJKgnwthRU2ZgkGcCc3a 2Vly7THUBQeAPH2YtLJuTTATcxh6YM5lkaUhP0p6YKPCXE8qFsp4cXLoiN1B2aoxHtqV kQozYvasZN+2UhANtcY/DRLpgsOFYdP6+VcsX2sHCPryGBEAw1Eker6zqdCqnNktGyuV Lj9eczSXW1NIXUpXb4+Z3XgtovPVDSyNnGZW+JtO8i+DPN3eRLWSEIjMj17eeNRPI3Gt YrrQk8x++W9vyagne5KCq5F5UfXEUptRxTR6zOL783zsyhvl9NUHCOxDLdmHA3mI7Xci XB0g== X-Forwarded-Encrypted: i=1; AFNElJ9dNIoGW5t0RF2ty0UxMM6SmhhQotloF4PByn+DBC+8M6AUnsZo4RtUapQDplaCswkfWjbetfySY6a8K+M=@vger.kernel.org X-Gm-Message-State: AOJu0YwHZ2ta2282fRqZhxj50MVUtauhKRBx4vYg7Oa7h6C7jdS7/NtE beEfN7bxD6m7V8znjurZ1iBZxyCzIP7eZtk9621xo/+vV9Sx8YheC18= X-Gm-Gg: AfdE7ckJqwOTuTpCOOGAKAnKXXuqzs66YlzRpQLuxgdzViUBR9Ox5jT994oYI8nDnje Y5RaBDpSBfRmkpAqKHFIHAdoS1r8iUoBxaNSd+0itincRsKtXqGVLXoi29cT/HpkaxTcKf7921v quCIdk/wKj8h9kdf5Lurftktz/wnY2dPeJs+29sVskZDS+l7IHVwpwkcB6tkipo3uDfkd02TOQl MKAJydhFdE+ow4bz6GTVNDfFb7NYztyQZsC4vpkNKdKJE57zThNXJsFvqTsZM5gQ3r7XJArK2dm rdh/7uyuH0ZCrRO+DFa49t32xwde9Z6izLM8IDQ2xpauDY8llltZ6/hjMwlnbZWJwwzOc/qPHM5 s/wFXUd5KemqXfG7TwcsC/x9o6OOjE5zu9VQGQ+GIZuCiX/3BZXjFtUWLbaM2UTUFId3qsmOB1B K3rbwfkHWj8lTDUJ5fmMo5kiTeXeWeMm1XvGbeDbMXeD0EFTu5XPvXAkCxjyLacd8D X-Received: by 2002:a05:7022:e0e:b0:12d:de3f:f3e5 with SMTP id a92af1059eb24-139dbac8312mr4114702c88.37.1782427805939; Thu, 25 Jun 2026 15:50:05 -0700 (PDT) Received: from localhost.localdomain ([186.158.238.108]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-139d8f77602sm10771239c88.8.2026.06.25.15.50.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jun 2026 15:50:05 -0700 (PDT) From: =?UTF-8?q?Nicol=C3=A1s=20Antinori?= To: Greg Kroah-Hartman Cc: =?UTF-8?q?Nicol=C3=A1s=20Antinori?= , Alexandre Courbot , Alice Ryhl , Miguel Ojeda , Andreas Hindborg , Benno Lossin , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Boqun Feng , Daniel Almeida , Danilo Krummrich , Gary Guo , =?UTF-8?q?Onur=20=C3=96zkan?= , Shuah Khan , Tamir Duberstein , Trevor Gross , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel-mentees@lists.linux.dev Subject: [PATCH] usb: rust: Use pin_init::zeroed for usb_device_id initialization Date: Thu, 25 Jun 2026 19:49:22 -0300 Message-ID: <20260625224927.404258-1-nico.antinori.7@gmail.com> X-Mailer: git-send-email 2.47.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All types in `bindings` implement `Zeroable` if they can. This enables using `pin_init::zeroed()` for `usb_device_id` initialization instead of relying on `..unsafe { MaybeUninit::zeroed().assume_init() }`. This change improves readability and removes unnecessary unsafe blocks. Link: https://github.com/Rust-for-Linux/linux/issues/1189 Suggested-by: Benno Lossin Signed-off-by: Nicolás Antinori --- rust/kernel/usb.rs | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/rust/kernel/usb.rs b/rust/kernel/usb.rs index 7aff0c82d0af..bbf85366d2c9 100644 --- a/rust/kernel/usb.rs +++ b/rust/kernel/usb.rs @@ -24,11 +24,8 @@ }; use core::{ marker::PhantomData, - mem::{ - offset_of, - MaybeUninit, // - }, - ptr::NonNull, + mem::offset_of, + ptr::NonNull, // }; /// An adapter for the registration of USB drivers. @@ -130,8 +127,7 @@ pub const fn from_id(vendor: u16, product: u16) -> Self { match_flags: bindings::USB_DEVICE_ID_MATCH_DEVICE as u16, idVendor: vendor, idProduct: product, - // SAFETY: It is safe to use all zeroes for the other fields of `usb_device_id`. - ..unsafe { MaybeUninit::zeroed().assume_init() } + ..pin_init::zeroed() }) } @@ -143,8 +139,7 @@ pub const fn from_device_ver(vendor: u16, product: u16, bcd_lo: u16, bcd_hi: u16 idProduct: product, bcdDevice_lo: bcd_lo, bcdDevice_hi: bcd_hi, - // SAFETY: It is safe to use all zeroes for the other fields of `usb_device_id`. - ..unsafe { MaybeUninit::zeroed().assume_init() } + ..pin_init::zeroed() }) } @@ -155,8 +150,7 @@ pub const fn from_device_info(class: u8, subclass: u8, protocol: u8) -> Self { bDeviceClass: class, bDeviceSubClass: subclass, bDeviceProtocol: protocol, - // SAFETY: It is safe to use all zeroes for the other fields of `usb_device_id`. - ..unsafe { MaybeUninit::zeroed().assume_init() } + ..pin_init::zeroed() }) } @@ -167,8 +161,7 @@ pub const fn from_interface_info(class: u8, subclass: u8, protocol: u8) -> Self bInterfaceClass: class, bInterfaceSubClass: subclass, bInterfaceProtocol: protocol, - // SAFETY: It is safe to use all zeroes for the other fields of `usb_device_id`. - ..unsafe { MaybeUninit::zeroed().assume_init() } + ..pin_init::zeroed() }) } @@ -180,8 +173,7 @@ pub const fn from_device_interface_class(vendor: u16, product: u16, class: u8) - idVendor: vendor, idProduct: product, bInterfaceClass: class, - // SAFETY: It is safe to use all zeroes for the other fields of `usb_device_id`. - ..unsafe { MaybeUninit::zeroed().assume_init() } + ..pin_init::zeroed() }) } @@ -193,8 +185,7 @@ pub const fn from_device_interface_protocol(vendor: u16, product: u16, protocol: idVendor: vendor, idProduct: product, bInterfaceProtocol: protocol, - // SAFETY: It is safe to use all zeroes for the other fields of `usb_device_id`. - ..unsafe { MaybeUninit::zeroed().assume_init() } + ..pin_init::zeroed() }) } @@ -206,8 +197,7 @@ pub const fn from_device_interface_number(vendor: u16, product: u16, number: u8) idVendor: vendor, idProduct: product, bInterfaceNumber: number, - // SAFETY: It is safe to use all zeroes for the other fields of `usb_device_id`. - ..unsafe { MaybeUninit::zeroed().assume_init() } + ..pin_init::zeroed() }) } @@ -227,8 +217,7 @@ pub const fn from_device_and_interface_info( bInterfaceClass: class, bInterfaceSubClass: subclass, bInterfaceProtocol: protocol, - // SAFETY: It is safe to use all zeroes for the other fields of `usb_device_id`. - ..unsafe { MaybeUninit::zeroed().assume_init() } + ..pin_init::zeroed() }) } } -- 2.47.3