From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 621903B14AB;
	Fri,  5 Jun 2026 13:04:57 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1780664698; cv=none; b=SboThdtvgnjkgY7y/Q6DQ4WNc5TWf2TcxUs2hqkqVHLlqexPnbPoGUAkxU35K0s7lYOKjf9n8qBPECziVmRnq+am2KybMwYKK+vX07fixxV96JHT+Z3tzROCI9Dies9yhFSpDBO9HXHHIRqH2yh7w499eGAIJerIxXYaYZl/Hnc=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1780664698; c=relaxed/simple;
	bh=y8SrsZf4Er1k5T4KxEmOkOYdCLVERYK0qajWVQobk+g=;
	h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:
	 In-Reply-To:To:Cc; b=tdJyMlm5fu2CuNHQBUFON5UEcHNQJ1R889oZDZJXRCqNgLeVOPRsDnz5gRnN82rjrUvnxTU915t2/kR95MCt4vjOv+dJqkOBaX1yeKrxaO7aYMuPa27QrtBjVBWq1JcKYwmfty/6dRltJuZ+paolUdp7++3eSv+kPcVYjJojBAY=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JSEgcKUs; arc=none smtp.client-ip=100.103.45.18
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JSEgcKUs"
Received: by smtp.kernel.org (Postfix) with ESMTPSA id 590441F00893;
	Fri,  5 Jun 2026 13:04:54 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1780664697;
	bh=J8xWN6FwFJntxASihgK6OAXFm1JzLZteeOE+ZioOK3g=;
	h=From:Date:Subject:References:In-Reply-To:To:Cc;
	b=JSEgcKUsg+yJVkb9iYduhcgHuxOM0UK445MNEB/QOyjamoX/C8+KLCaoR9SMuJQZz
	 OJIuqpR+XCAlSTE1ILatHnBZLNwgUWnZCe+I005hQhpkb8yF54rnm6Ll+A5qucRHbV
	 JoRfa3T6cFocEQkJ61mwDqbfyoD0rVx4fG1FoookV5v3ktcG4cTff1DX2aDs5TDgVj
	 +2fI17BXd0ZydDzZjnQdZrcy3Hk615Z/58e6XinXW9xFzLnTmtCgUadh2HFvUiuteO
	 Jne+fZ4x5gR3FK6dkxekj6VmO4i4/KOPRCJb4WuX65F8HNuL5tNUQsroOJIUZK4jE3
	 49Jp/lo7rNByQ==
From: Andreas Hindborg <a.hindborg@kernel.org>
Date: Fri, 05 Jun 2026 15:04:39 +0200
Subject: [PATCH v2 2/2] rust: impl_flags: add bitwise operations with the
 underlying type
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Message-Id: <20260605-impl-flags-additions-v2-2-0d27242f460b@kernel.org>
References: <20260605-impl-flags-additions-v2-0-0d27242f460b@kernel.org>
In-Reply-To: <20260605-impl-flags-additions-v2-0-0d27242f460b@kernel.org>
To: Miguel Ojeda <ojeda@kernel.org>, Gary Guo <gary@garyguo.net>, 
 =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= <bjorn3_gh@protonmail.com>, 
 Benno Lossin <lossin@kernel.org>, Alice Ryhl <aliceryhl@google.com>, 
 Trevor Gross <tmgross@umich.edu>, Danilo Krummrich <dakr@kernel.org>, 
 Boqun Feng <boqun@kernel.org>, Boqun Feng <boqun@kernel.org>
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, 
 Andreas Hindborg <a.hindborg@kernel.org>
X-Mailer: b4 0.16-dev
X-Developer-Signature: v=1; a=openpgp-sha256; l=1476; i=a.hindborg@kernel.org;
 h=from:subject:message-id; bh=y8SrsZf4Er1k5T4KxEmOkOYdCLVERYK0qajWVQobk+g=;
 b=owEBbQKS/ZANAwAKAfpQKQiqxb3QAcsmYgBqIsloYZBCseRps0SseKyEZHcMuXu4a1vgsADpn
 NP2dRMVpnyJAjMEAAEKAB0WIQRXitnI2WZ2JirAaob6UCkIqsW90AUCaiLJaAAKCRD6UCkIqsW9
 0H86D/4pSci7tqXk4gsSChFFDPjYVNmSnDk1ukzTJWo66JIjGq0KKM10xlONbxtti9nmCkxxj6b
 hYjSY+u4AkFwVXtwdtGA7jxAAmHcD9xIqLw9beJpLLuTuDUFXGh2nEbxt3erU1UtjQrSzAd/1oK
 Ul/TVqafteiinMz6jeeY4VGUVe8c1RQU33CUxdLC6q4pKpN0e0L+NDiJn0mA2ZeFYhrcCEOj8QT
 Gbq48gXCcYTXetPBMcGkyqg+EAOijBJVg39e3JtpBlghi/mKSr802QSM1rzrLhyzNQaOc+fDvWj
 YRbaZcP1LNRLmCoVIWtNbqKmEZ4PXLYyxG+6N7XWT0Q6XIjy7cOt/sy+x1UxOwq6qondIPTVLhJ
 BEyr0Rzev5pQRUqk2AFqYgHAazTfHunH/AW0dHtqVoYzIMqWx8puRlsryR8V1XnF/LqXvrb2ziv
 fUk2smGUMyFFR9b+6DNaIrf8DJo8SvXKEHzb4mTbrsKJJdRzJEqvyE6P4ehvP7+bRNEAFWkm/Mc
 bhO82+TbKFaKrVyidQJSSdC8FzlxhZbFSJnFmp49XaLZpuDOggeUD9507/wLozEGyuZC7NfjnQo
 xn4qZJOJcCDJsb7GxgYTDQQSICy3ZvElMYU3Iz8P8SgiXCjSDAro73aNRBSxwChaHmBWumI9Tjg
 ojmN+24K3TwuQPQ==
X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp;
 fpr=3108C10F46872E248D1FB221376EB100563EF7A7

Add bitwise or operations between the flag value enum and the underlying
type. This is useful when manipulating flags from C API without round
tripping into the Rust flag container type:

  let mut lim: bindings::queue_limits = unsafe { core::mem::zeroed() };
  ...
  if self.write_cache {
      lim.features |= request::Feature::WriteCache;
  }

The above code would be needlessly verbose without this direct assignment
option.

Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
---
 rust/kernel/impl_flags.rs | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/rust/kernel/impl_flags.rs b/rust/kernel/impl_flags.rs
index 04a4b0a356df..8340740b2efb 100644
--- a/rust/kernel/impl_flags.rs
+++ b/rust/kernel/impl_flags.rs
@@ -280,6 +280,22 @@ fn not(self) -> Self::Output {
             }
         }
 
+        impl ::core::ops::BitOr<$flag> for $ty {
+            type Output = Self;
+
+            #[inline]
+            fn bitor(self, rhs: $flag) -> Self::Output {
+                self | <$flag as Into<Self>>::into(rhs)
+            }
+        }
+
+        impl ::core::ops::BitOrAssign<$flag> for $ty {
+            #[inline]
+            fn bitor_assign(&mut self, rhs: $flag) {
+                *self = *self | <$flag as Into<Self>>::into(rhs)
+            }
+        }
+
         impl $flags {
             /// Returns an empty instance where no flags are set.
             #[inline]

-- 
2.51.2



From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6FBDA3B14DE;
	Fri,  5 Jun 2026 13:05:00 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1780664701; cv=none; b=sCBkGQqKtwQwHF/zchbzWMAs3lsfZjjUwgfIFPXNkTokoaikhcF85dNTkFrPeY4SmTUkFzdRRhbXdethwKuu0iE9RRFfWYwhsuF+1UJfrp/uSsBDGb9lJOTDU+nZ/26uTUJpeg1qnb5i3/L64OrGdjRRc5xE5r5PKjdzDHxqXJE=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1780664701; c=relaxed/simple;
	bh=yn/uFktBaRKKfNXGcAf8tIjXvcECzndSbjOXGvHYTdQ=;
	h=From:Subject:Date:Message-Id:MIME-Version:Content-Type:To:Cc; b=IK7ber66vhQaGfrh3SVOKNRm/6fy4Q/frQB+XfIW7kEZlZLfRHKUGWb/3UZ4Bujxr0SOd06AnzUlC32jDKibHUpIbC4ld2yQIKzJ1r2V2h38ocS2Z5eqBNqQSnz8rnHA19KzwyckDioVDTxO2+1iA5sym9DnLyHgMteW5FMv1No=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=S1VYQuxp; arc=none smtp.client-ip=100.103.45.18
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="S1VYQuxp"
Received: by smtp.kernel.org (Postfix) with ESMTPSA id AACC21F00899;
	Fri,  5 Jun 2026 13:04:57 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1780664700;
	bh=o8DlpVD9LgwUgxNnhayGiKLF93CI9bcGHocJqlvcBWo=;
	h=From:Subject:Date:To:Cc;
	b=S1VYQuxpwZaRfq+JcCPZqXg0WkarpD6AURyA4a7k29p86Yu+aSYTTVI10xo+BEgJE
	 T81oPvG4Mz4XckhNXnIa2eY7B4rNRKvNANWnINt6I+v5prBJOxh2iSoB9Zv6+dfqgt
	 CSzYWXKd2QTIZRtxqNm0p/mYDYuvX/ckswD9AAiEocejeAwNXURyx06bfWUD5DCUzO
	 s8LVgprILGH8YtLCiTykvHVXsqq9gnuoKJsorfs/q3WspJYLb18DywdBnpUCzytNXE
	 f/tyLFCIBIOhrxkYkvE5gOOKHUO4T+SQ4SqVOLptbLF5n3Lq4fOlxMVlkZ+Sz034Vp
	 XUPxdBREOL6yw==
From: Andreas Hindborg <a.hindborg@kernel.org>
Subject: [PATCH v2 0/2] rust: impl_flags: add convenience functions
Date: Fri, 05 Jun 2026 15:04:37 +0200
Message-Id: <20260605-impl-flags-additions-v2-0-0d27242f460b@kernel.org>
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
X-B4-Tracking: v=1; b=H4sIAGXJImoC/32Py47CMAxFf6XyeoyS0Bdd8R+IRZI6xZo2haQTz
 Qj13ye0G1Ysj2Xfc/2ESIEpQlc8IVDiyLPPoL4KsDftB0LuM4MSqhZKVsjTfUQ36iGi7nte8n5
 EcSyFc9boypwgn94DOf7dYi/XnQM9fnL6sg/B6Eho52nipStSc5AYrIJ3ay6xO9W7k72ngLaWp
 6Y0qjGy7ZKCl+PGcZnD3/ZJkpvkc+kkUWBdHVvbOtOW0p6/KXgaD3MY4Lqu6z8U1k33HQEAAA=
 =
X-Change-ID: 20260215-impl-flags-additions-0340ffcba5b9
To: Miguel Ojeda <ojeda@kernel.org>, Gary Guo <gary@garyguo.net>, 
 =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= <bjorn3_gh@protonmail.com>, 
 Benno Lossin <lossin@kernel.org>, Alice Ryhl <aliceryhl@google.com>, 
 Trevor Gross <tmgross@umich.edu>, Danilo Krummrich <dakr@kernel.org>, 
 Boqun Feng <boqun@kernel.org>, Boqun Feng <boqun@kernel.org>
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, 
 Andreas Hindborg <a.hindborg@kernel.org>
X-Mailer: b4 0.16-dev
X-Developer-Signature: v=1; a=openpgp-sha256; l=2438; i=a.hindborg@kernel.org;
 h=from:subject:message-id; bh=yn/uFktBaRKKfNXGcAf8tIjXvcECzndSbjOXGvHYTdQ=;
 b=owEBbQKS/ZANAwAKAfpQKQiqxb3QAcsmYgBqIsln/ZVKz0GyKQTts7+oA8urwzMT4m6ubEw3C
 fn3Ru+/OhOJAjMEAAEKAB0WIQRXitnI2WZ2JirAaob6UCkIqsW90AUCaiLJZwAKCRD6UCkIqsW9
 0KpRD/oD59M2BdjmH1vMiYlreRj9zVtFKRYPYnVi6WMK7mFnDw/QUYZY+7FA9g3zRxhSrl+eOOE
 HBVpMLgmgqEGVASSqMow/0zarYmC0renRRreDDCofkJtpCAsPj7+rsUsqMQl2Lfb0xFgUl9+Jxs
 zF1e82qwsqoiDs2BC+T7HMEUuospPrGeefqn9K0g0+lXwSO+YWEaoDYlsevATEMQpYsb93YZRjr
 4VNEyROdhxi5CpeWTwRXqBKMJdhV5H4HNtq5/2nEGAieVOhppIdN/d4B7cvRntxC7gcEnN3h+Sw
 BIwyw/AkZiEecHFrt1fLferuYB+d4Jv98K92bWP+seTWKQ1usTjgZ91+tg2HxALQzzsFb9lybyC
 BVXZ9jyq/5HeEtGEvxNDH0fFdt84M/we/76fvrYQhjBZoxbRwFg1Y7LUQUtc2GKzqmyFtbZMS3O
 Wqsse/Y3YxljX3CYu+Io1OjpMK5wBzCltm4zy8iANhsK/fOqy5ICt9J16wCNIfsrBDamKfe+5Y6
 3Woaxfbyv/U9m/IaWwKf2TBmE1dTWTlO/RvtQx87aojBpCKtxTOw9VqS+ml8Oj1YfHFCzJb+N2D
 NVoTk+N+Xz432ibskWPiEa/B9yRF0rS+HiARRT+BTJAiWFEi7tXImZ8bh+VuS53Qfp2ADRp1U3f
 QNJOEKknnoX2sIQ==
X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp;
 fpr=3108C10F46872E248D1FB221376EB100563EF7A7

Add a few convenience functions that makes it easier to work with the
`impl_flags` module and C APIs.

These conversion functions are useful when assigning flags to C structs in
Rust abstractions:

  let mut lim = bindings::queue_limits::zeroed();

  if self.rotational {
      lim.features = Feature::Rotational.into();
  }

  if self.write_cache {
      lim.features |= Feature::WriteCache;
  }

Or when providing flags from C to Rust:

  impl<T: Operations> RequestInner<T> {
      pub fn flags(&self) -> Flags {
          // SAFETY: By C API contract and type invariant, `cmd_flags` is valid for read
          let flags = unsafe { (*self.0.get()).cmd_flags & !((1 << bindings::REQ_OP_BITS) - 1) };
          Flags::try_from(flags).expect("Request should have valid falgs")
      }
  }

Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
---
Changes in v2:
- Use an `as` cast instead of `core::mem::transmute` in
  `From<$flag> for $ty` (Miguel).
- Replace the `match` in `TryFrom::try_from` with an early-return
  `if` (Miguel)
- Construct the result directly instead of via `transmute` in `try_from`
  (Miguel).
- Use `Self` in the new conversion impls (Miguel).
- Mark `TryFrom::try_from` `#[inline]`.
- Extend the rustdoc example to demonstrate both new conversion
  impls (Miguel).
- Link to v1: https://msgid.link/20260215-impl-flags-additions-v1-0-6538c8fb841c@kernel.org

To: Miguel Ojeda <ojeda@kernel.org>
To: Boqun Feng <boqun@kernel.org>
To: Gary Guo <gary@garyguo.net>
To: Björn Roy Baron <bjorn3_gh@protonmail.com>
To: Benno Lossin <lossin@kernel.org>
To: Andreas Hindborg <a.hindborg@kernel.org>
To: Alice Ryhl <aliceryhl@google.com>
To: Trevor Gross <tmgross@umich.edu>
To: Danilo Krummrich <dakr@kernel.org>
Cc: rust-for-linux@vger.kernel.org
Cc: linux-kernel@vger.kernel.org

---
Andreas Hindborg (2):
      rust: impl_flags: add conversion functions
      rust: impl_flags: add bitwise operations with the underlying type

 rust/kernel/impl_flags.rs | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
---
base-commit: 9e0898f1c0f134c6bad146ca8578f73c3e40ac0a
change-id: 20260215-impl-flags-additions-0340ffcba5b9
prerequisite-change-id: 20260212-impl-flags-inner-c61974b27b18:v2
prerequisite-patch-id: 379fb78c07b554278fae3c42d84d62bcfcfa0d45

Best regards,
--  
Andreas Hindborg <a.hindborg@kernel.org>



From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10CFD3B14DC;
	Fri,  5 Jun 2026 13:05:03 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1780664705; cv=none; b=AhMoSlE6UMb0J8fJ1fOCLwSmuoWTcbL5+NnJ/ngko+c5/LTJO2CQ+/gnDN4e1kC8+sdhGus8Il0rkQgc5gkE6YVMQt2Aqo+7JekG6AEWYPfqDCiyqdVzDxVayQiYsCnL/1Fdry/1xTpA6xnT4GxaJrQJPcoky43w4OGsrK/An48=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1780664705; c=relaxed/simple;
	bh=ioMw3xPGSMtDGXeeXbbiCBXt5yGAIRMASDj8ubWaMeM=;
	h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:
	 In-Reply-To:To:Cc; b=aWrHsF1uCnbagYTLSn1MvybpLJYpe+pTFxS2/o5cTKPXPXTOo1KdcWVQ6aoNriBt70+LeiZSLfxH7UR9HKHd1LqYl+I/WVnCiwFCYPjBgU9NJ3QkbmivsCERmqb4oJQ4tp3nULX5wKuSA95v4d3SF2ucGakY/2Guk8aptELzUTE=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BxiVQDvI; arc=none smtp.client-ip=100.103.45.18
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BxiVQDvI"
Received: by smtp.kernel.org (Postfix) with ESMTPSA id 016E41F0089A;
	Fri,  5 Jun 2026 13:05:00 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1780664703;
	bh=Odg6jQOIPJGRNnkKjmmS4IoAqIuyjP6bRgIbkVWP8WM=;
	h=From:Date:Subject:References:In-Reply-To:To:Cc;
	b=BxiVQDvIHPhR7jGy3urehVvP/UBfpbOxgCeGuU13XlJuw4Hmx8ADtZklmnt5vjwN4
	 7BO0P7+szIxIZD+iFkYMGFZy9ifZlNM8DnnXcVfoiLkRWxYdk5HQiY0X7K9dmnNPWJ
	 9TTaftf7RBz8NqPqCJIjLknFY8IwHKpv/RS3QMbrLTWgUXFVEQqqYKDitchBwoXcof
	 /uqwb0PANeeUhvW3UaVLQzmuShK0+DIkR+OWgNrIBrxG416CGm2L69fpckBbwjmKVb
	 BE+gU83ZV/gh4GV6cGXzP9WYXmzTmH7LiIvZpC0qS0b+V6IXS5BxSC9CgdTBvKQ3aO
	 oIHssDXRKNqiQ==
From: Andreas Hindborg <a.hindborg@kernel.org>
Date: Fri, 05 Jun 2026 15:04:38 +0200
Subject: [PATCH v2 1/2] rust: impl_flags: add conversion functions
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Message-Id: <20260605-impl-flags-additions-v2-1-0d27242f460b@kernel.org>
References: <20260605-impl-flags-additions-v2-0-0d27242f460b@kernel.org>
In-Reply-To: <20260605-impl-flags-additions-v2-0-0d27242f460b@kernel.org>
To: Miguel Ojeda <ojeda@kernel.org>, Gary Guo <gary@garyguo.net>, 
 =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= <bjorn3_gh@protonmail.com>, 
 Benno Lossin <lossin@kernel.org>, Alice Ryhl <aliceryhl@google.com>, 
 Trevor Gross <tmgross@umich.edu>, Danilo Krummrich <dakr@kernel.org>, 
 Boqun Feng <boqun@kernel.org>, Boqun Feng <boqun@kernel.org>
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, 
 Andreas Hindborg <a.hindborg@kernel.org>
X-Mailer: b4 0.16-dev
X-Developer-Signature: v=1; a=openpgp-sha256; l=2232; i=a.hindborg@kernel.org;
 h=from:subject:message-id; bh=ioMw3xPGSMtDGXeeXbbiCBXt5yGAIRMASDj8ubWaMeM=;
 b=owEBbQKS/ZANAwAKAfpQKQiqxb3QAcsmYgBqIslnAcmiQK04rwXfchu57Cxi5cKsxAWbbHkIt
 qkOkJe0VkCJAjMEAAEKAB0WIQRXitnI2WZ2JirAaob6UCkIqsW90AUCaiLJZwAKCRD6UCkIqsW9
 0MtQD/9KJ31whqzYpkryipluRwxxZV2IlfYh39WLBY4dBcMJ4s9fM6wceppcdy1NYJGefFXEXGF
 2EYVX656D7psoc1+TyeYVsDxOyRG48U09FTxJgSIMFOHsYZHMIzF0g5y3HBgPCXK9pYMF4j6Ffk
 mwgW7NfNHhzVD5KUtW9ACYGWjEOHBVy9aDzxYxuyrPLrxpyJM/dmY+T5hU/21chRgxEVsxu7xr3
 0EyGyHV3Et6yUvB40kB5ZwgT5TgaliqhUiT11kcM1v/QiFpBl780qQ6sJtSe2XmMHsdayZUVjbW
 g+O60ewOUUFmcXNJC+EdtRC3GPMn50Yh+eJWPyuufw2ynaGo+edWaa8OcViUGUDmsd/9rqqNhgK
 KryU6SktdRgI2b4yCJB5kt4zua/iQ9LR8u+nxSYcn52/V+4Vn9vo7BxAf1/xa02ghGb6r1mh2Ub
 kbwg21t0gF1Oaw9f2owcXDttTkQTGeLxgTJPvL71EdZ8fQuBVFV+k7Qr0JDCACpstgduqjDtITR
 5tVxOOXw9RQHzAfWmGCN6nGJypDS5ab4uea5o3AE/tFEs7FlpEDECW3btgVRVu8aP1snEL92R04
 +WzIp45ja9wpwztNhYdjAHe+BNaXiR4rHV/Ts4+NbTREjRE5FDxubo4tn8p4gWjOt9McNpPi+yz
 ZYXOGSaU38uk/Og==
X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp;
 fpr=3108C10F46872E248D1FB221376EB100563EF7A7

Add two conversion functions to the `impl_flags!` macro:

 - A `From<_>` implementation to convert from the flag value enum to
   underlying type.

 - A `TryFrom<_> implementation to convert from the underlying
   representation to flag container type.

Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
---
 rust/kernel/impl_flags.rs | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/rust/kernel/impl_flags.rs b/rust/kernel/impl_flags.rs
index 1d39d54540dc..04a4b0a356df 100644
--- a/rust/kernel/impl_flags.rs
+++ b/rust/kernel/impl_flags.rs
@@ -77,6 +77,17 @@
 /// // representation — useful for passing the value to a C API.
 /// let raw: u32 = read_only.bits();
 /// assert_eq!(raw, Permission::Read as u32);
+///
+/// // Convert a single flag value to its underlying integer representation.
+/// let raw_read: u32 = Permission::Read.into();
+/// assert_eq!(raw_read, Permission::Read as u32);
+///
+/// // Construct a `Permissions` value from a raw integer. `TryFrom` rejects
+/// // integers whose set bits do not all correspond to declared flags.
+/// let parsed = Permissions::try_from(raw_read | Permission::Write as u32).unwrap();
+/// assert!(parsed.contains(Permission::Read));
+/// assert!(parsed.contains(Permission::Write));
+/// assert!(Permissions::try_from(1 << 7).is_err());
 /// ```
 #[macro_export]
 macro_rules! impl_flags {
@@ -119,6 +130,26 @@ fn from(value: $flags) -> Self {
             }
         }
 
+        impl ::core::convert::From<$flag> for $ty {
+            #[inline]
+            fn from(value: $flag) -> Self {
+                value as Self
+            }
+        }
+
+        impl ::core::convert::TryFrom<$ty> for $flags {
+            type Error = ::kernel::error::Error;
+
+            #[inline]
+            fn try_from(value: $ty) -> Result<Self, Self::Error> {
+                if value & !$flags::all_bits() != 0 {
+                    return Err(::kernel::error::code::EINVAL);
+                }
+
+                Ok(Self(value))
+            }
+        }
+
         impl ::core::ops::BitOr for $flags {
             type Output = Self;
             #[inline]

-- 
2.51.2



From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-dy1-f172.google.com (mail-dy1-f172.google.com [74.125.82.172])
	(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 4DB603195F0
	for <linux-kernel@vger.kernel.org>; Fri,  5 Jun 2026 18:17:49 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=74.125.82.172
ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1780683470; cv=pass; b=YnALDnmD9fhDbEtHi++Vnz9j9nnNMioVTXtXklDPVDIgawEkO0oXn6oXNHQm6+4Soex0pD+E8ByZLbaQHpkEXyewXPrvoR21cIT91Ax23fKbJw1PSBCjM6mcfqPGfRIVQbrxy2aR7nNXhBzztKqDrWoefxv2C3A3hn56CgdciYQ=
ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1780683470; c=relaxed/simple;
	bh=SUV8bIa7xH5CwJGgUZXFR3xAEViJqnFPZn3YTV50FSU=;
	h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject:
	 To:Cc:Content-Type; b=YJEKJ6g1pEnVRloCblCnuGOs44ZWG2u+qXAjJWhSOBiqclTcoLjrzCXNB9CKchdHRqt1x+LcsCV0e5Ggr7h5c3lj8c5ZTD3wQsGRrLRivydKfKXbqyXrhC685M57M2wK396nXKCjyhF7k7X779x5qRS49AHwKg0Wfxad7v7iuj0=
ARC-Authentication-Results:i=2; 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=DvM7EJaD; arc=pass smtp.client-ip=74.125.82.172
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="DvM7EJaD"
Received: by mail-dy1-f172.google.com with SMTP id 5a478bee46e88-304dc707bfbso126137eec.2
        for <linux-kernel@vger.kernel.org>; Fri, 05 Jun 2026 11:17:49 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1780683468; cv=none;
        d=google.com; s=arc-20240605;
        b=MeBJaNnOuYsEiGMeRBMYY0zN1NZVL4Qob994N3W/SRx3GV8jKINJfMnfCCTAJDmrao
         ikU46nVMr+vkLx8n9qak9qhByqsRkf6K88l8o39pUv3I5CWbpiOySTFqaqlCiD+iiP/F
         fR290CQgAc/yqNo4SfQeEwAFOx4w0GKMnQiJDAYKsi+sH9uASTIOhHanRHyXjeeBZ6aY
         5Z76c1EXS2hggyyaT2EhxP+K0o8rrvQ0pfogx6+s7pQdZHgRnJK2bmc7Ew6NPAEUWXaW
         tvId+pNGAA3o4HjYsQp3EmIR2MYLhEElRjsztIGiXMssBeHr6E1Is+Cra7wsPlsAu0Ax
         64yg==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605;
        h=content-transfer-encoding:cc:to:subject:message-id:date:from
         :in-reply-to:references:mime-version:dkim-signature;
        bh=nbNioASDYiYe7m9hRLWRsYGED5pw3vxbOwy669aTpMs=;
        fh=ayZ8hlVr4W+w9ir/IvyfohPnGkPX1IZ7NwE4xcNCEOQ=;
        b=F37l8CFJJUu2IuBfvESQ3v88/u861whffjphLCEO+GseAIM44FE0ydfcpzsEi1yo4S
         MFHWdoJwvrMAGMcFFOIPUeSHr2izVoNhaKrStGsnzU5GEtMLiXRK+TA5V17NHwoDiPQf
         DJ0drBENhEO8Cr4TABlfbulXADhNNvbjMMb7hN1YEwqmuOvS2j1KHbK4WRRAxvS/5QHF
         AHQMpSapzPIRcC6SRObrKymXvKNQE0ZSadhhy/gM7RDnCHWFTmzGMt6ApCM8kJVYh9Lz
         FTIBkXlfJr1rFELGoc9TM6CdH8NneMwGHu2qeIRdbbXyTXtU+/9iJE7EBEQzAi42tY7G
         uVog==;
        darn=vger.kernel.org
ARC-Authentication-Results: i=1; mx.google.com; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20251104; t=1780683468; x=1781288268; darn=vger.kernel.org;
        h=content-transfer-encoding:cc:to:subject:message-id:date:from
         :in-reply-to:references:mime-version:from:to:cc:subject:date
         :message-id:reply-to;
        bh=nbNioASDYiYe7m9hRLWRsYGED5pw3vxbOwy669aTpMs=;
        b=DvM7EJaDTE0ojJ73wSdgGRbMneqw98O7PEa9OEMm3QVJAdMuDzkDNE5uRgPNGqQOav
         OZ5nPAUx8hLFrvJ7i4cSMFcO4bvB56D0JjEBkeMW/VKy0dBdhZEZmWByfd1mqv2kcyoi
         P00IV9cV34DV4QR5P+djgk1vYjZ6h/lr6lt7VIrFIA3cBI21eudZqMJ1sglD9HojcmIc
         MBBYRfKi+njIPeNLzboepnEKYjgaUjABfrT3btc0+LEBoT9yJcDoPjtg4Yuvbmzjzb0F
         YQy6ECVut03hfaHwk+I1rG5fRy59Pq9fGDuynWwpXeVUG+zELK0FHj0Q6VhNHtuk6owZ
         2dDw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20251104; t=1780683468; x=1781288268;
        h=content-transfer-encoding:cc:to:subject:message-id:date:from
         :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from
         :to:cc:subject:date:message-id:reply-to;
        bh=nbNioASDYiYe7m9hRLWRsYGED5pw3vxbOwy669aTpMs=;
        b=C0WdKQPs+E989YRhhq7LaRKeoEpXQKWk5a4FxL7zLULL0pLH92r4fGxs00E5/+MrcJ
         m7rae+C8QmPZDC/zU3iUy3sVNoGW6mBQhkrOYPe4uAdUu85pjriHAMJA+6W+W1+8/Yf0
         CMKncSBLHHPyNdx2uhLMkt1ZSNLtdWpXymyqmpn3uUXFpEjWXAJoAR5kcjEP26ALZpi6
         uQ8HeXtSOdayQEyVZJkvST8xhveQMzXFuSRa3xuwhR8xuOiV9aaUa7Z8vlRNEQw8JdJb
         fxWKYX/Joil8D2zbMdAFEnNzzFDpRo+ggPsI53qE0gt0UAdwyOI6tzj+XsJQJ97uKCXy
         tBwQ==
X-Forwarded-Encrypted: i=1; AFNElJ8RfRojfHI6QZemqESxDckC6nIdhCCIxVmlbZwYH4H1eHNrywNfgcjYQxvjIy5Xf4wRJEEss0WAoQmmGWg=@vger.kernel.org
X-Gm-Message-State: AOJu0YwT9f228nMxz+Moj2vFGT74LxNzdQ05cXF8EBHOVhY9GIyiNcOM
	cWaucMiK3aaKSdmRJCYdlZtwOJrzXiuKGkt+iaiCRe5MBTTjrfOjETt82KChZNEnLrkBs1scsC/
	ulPVj0An4wgle8rHsVx9iLzRvSYgyG3w=
X-Gm-Gg: Acq92OFvIhgffSPJD1UJF9dl7wVqSZOpPLWfIu6sV+Kvfzcf6qED25uw0qRhQZKHTGE
	m3PqBdzzefGEZjze5u/qf1Kzh9ejqb5kZ+liVHo2CKpRGYkuR1x0E09T44JvXK3Ji9p98gpxzeJ
	Hs+Ex326o3Q6VIsW10HYGHvuDma8OW+wWzFg5LEul+VY5YQfS/2lPuOzn/+XBXM23r2NXaUwyt3
	CHeIY9s/4C5sNcy69rV6T1KH9H8lNMBEApi91xlfDjm/w1kLPKBBUoTA0kL55droi1pfg5p58Ci
	EKiyQtvae6O5Ycfa4rGkAusHOYY5dw1FhRkMPVSmg9n2kNddH0Mm18iljbEDqEJlG5MR8mtD85f
	RHwPnMXVyRl2uD8xeSDpitUdgvAoZLUeO7A==
X-Received: by 2002:a05:693c:2c11:b0:2f0:ddce:8468 with SMTP id
 5a478bee46e88-3077b452789mr1193477eec.8.1780683468446; Fri, 05 Jun 2026
 11:17:48 -0700 (PDT)
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
References: <20260605-impl-flags-additions-v2-0-0d27242f460b@kernel.org> <20260605-impl-flags-additions-v2-1-0d27242f460b@kernel.org>
In-Reply-To: <20260605-impl-flags-additions-v2-1-0d27242f460b@kernel.org>
From: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Date: Fri, 5 Jun 2026 20:17:35 +0200
X-Gm-Features: AVVi8CcSgmL6cbr5JoQ59E735TxcScRTrrOutp7KvaK9Qv6FIXdKOMjRoZ-Tf_A
Message-ID: <CANiq72ni6fg=C7Q_uXBH5mvOkdkOCdpSeKzejZ6OhxqsgqLw-g@mail.gmail.com>
Subject: Re: [PATCH v2 1/2] rust: impl_flags: add conversion functions
To: Andreas Hindborg <a.hindborg@kernel.org>, Gary Guo <gary@garyguo.net>
Cc: Miguel Ojeda <ojeda@kernel.org>, =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= <bjorn3_gh@protonmail.com>, 
	Benno Lossin <lossin@kernel.org>, Alice Ryhl <aliceryhl@google.com>, 
	Trevor Gross <tmgross@umich.edu>, Danilo Krummrich <dakr@kernel.org>, Boqun Feng <boqun@kernel.org>, 
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Fri, Jun 5, 2026 at 3:05=E2=80=AFPM Andreas Hindborg <a.hindborg@kernel.=
org> wrote:
>
> +                if value & !$flags::all_bits() !=3D 0 {

Can't this also be `Self`?

Cheers,
Miguel

From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-dl1-f46.google.com (mail-dl1-f46.google.com [74.125.82.46])
	(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 10939363C63
	for <linux-kernel@vger.kernel.org>; Fri,  5 Jun 2026 18:20:53 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=74.125.82.46
ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1780683655; cv=pass; b=X+GE9o6MH3yvVXc+MRTKNUXQ503JO65eP3orO4DpVPEVoa2nImO9xfNZBScX7snbRLYNVAWeLg8BF3QJl+QP67i52mVt+nsznKi78m48VIZd+BOEQv9UY9lUlh6YhkxeOgw3Kjp0TNdnh/XdfLYl3xDqN8KQW4R6pGch681z2yA=
ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1780683655; c=relaxed/simple;
	bh=Tv7+bwb6YfWfrz4piDdj+r43ZvwPktako8KiF7Yl+Gs=;
	h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject:
	 To:Cc:Content-Type; b=mV3uUUMKLUCIJZ/xwSB9aEP3vEbpQ5Bciqa3Sa4VZJTwZIUMY3dd184u/4YBF91RiU1rAbqT2bV3rHX2ydKtp/j4TKDlUblYdrqhAjKtx2ata5iMpLDIn9IM81x4GtCag05HC7f1QvKbchNf6yzkXguk734GR1Fan3uqsE6vREA=
ARC-Authentication-Results:i=2; 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=RjJjT0Px; arc=pass smtp.client-ip=74.125.82.46
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="RjJjT0Px"
Received: by mail-dl1-f46.google.com with SMTP id a92af1059eb24-137dd497007so140814c88.1
        for <linux-kernel@vger.kernel.org>; Fri, 05 Jun 2026 11:20:53 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1780683653; cv=none;
        d=google.com; s=arc-20240605;
        b=NsvuQW2BHF8GsX0SG1EebMVCI7WaPK0p5gU7TB3azPlV9KK4fFYQHPjDCEBNYd9GFc
         x1YdR9KSUduFcAkUiXOQmQKPn9i0uHGznvPXUgh0dPkySX2a56ocSR4Kf3GtkDxv+Z3U
         j35tLjRl1BdIR/rMOn0Sqca0dKOZdAB6q9yj/AiZqi51NdW6ECET/ypttqgcQ+AXzlz6
         0nl3jI/2B0q/5yHV6uv01GYl1uZQwyaG75bN4GY1nV8Kdm/ov6KS4jjju+cdXCIMorjP
         CQuR4aHerVWQGsaYHfgWPm09M95u0/HXdke5EhMAVU1A9ZmFaavqSZUomV3opvOC51dS
         fkiQ==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605;
        h=content-transfer-encoding:cc:to:subject:message-id:date:from
         :in-reply-to:references:mime-version:dkim-signature;
        bh=6pTatVJakjuHfmvAEENA/V/Qv+gKy0ipwl8zbFUhePo=;
        fh=kG7pqbB174mA098EJv8A6oirANbAPH4MrUKbNpHMuhc=;
        b=MGNMnB99NjQF114o3T0on3xPzoFyd6No+m+ihdS1ROGZ1AstAnEPR2wgM+aXhcsjA8
         BsbekKJkeDJ9lIPQXZosG+DA3KpqCa5lihbbzUisizSvU9RnnRwgCEyDwtj6QZiwNA6s
         fz5/m+p6c0q1B2JMg7tT3zqW2d1Ii4we6AT3BpQBMkY0UqdItJH+QDin5CQ04OlMf00L
         OQQO/02Sb6DHHZ2aRv/WaFEoRNV2F8jn1kdz0bOHNcc32CBdU0O373DQFmUVVIMxtl81
         KQnCSbEc8APnXnrkgNG3s0f1CrQl67YoBUxnQc0e7CAHLYCAXPxzv/kKvNgr5qEK86wG
         tPlQ==;
        darn=vger.kernel.org
ARC-Authentication-Results: i=1; mx.google.com; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20251104; t=1780683653; x=1781288453; darn=vger.kernel.org;
        h=content-transfer-encoding:cc:to:subject:message-id:date:from
         :in-reply-to:references:mime-version:from:to:cc:subject:date
         :message-id:reply-to;
        bh=6pTatVJakjuHfmvAEENA/V/Qv+gKy0ipwl8zbFUhePo=;
        b=RjJjT0PxyJva67btuj9zvBN4yTkmv4JKMGilrrN6DLDXR3E1aZfUHa0b/uUfOPRxnP
         BI51a66e420bt9XiUnBW5v5Jj1f6ZiFDMVMg9qU1GXHd+Jpl3eLHfzZfi/rW6c5HEeeZ
         8sIE2C3mBl4rsSbheq+80FI+bqkVw8bmdGLUjzuZCOSF77M75L1c6uHgS3wDrrs/sx7l
         DtHdnTyqdEPpNQLNsDxZ07NOl0dxHD5Fqx3qeZCEuYv0pQmQlodvmuIWvlqdHHWVa+Yg
         XS3ofzKbeoqvmccvqDg0Arc3LmphI5fEVRmjRg89x39vQl1qVJNWN765H5rchM52Hzhp
         A5yA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20251104; t=1780683653; x=1781288453;
        h=content-transfer-encoding:cc:to:subject:message-id:date:from
         :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from
         :to:cc:subject:date:message-id:reply-to;
        bh=6pTatVJakjuHfmvAEENA/V/Qv+gKy0ipwl8zbFUhePo=;
        b=Ko4kN9xsANWzhHaFU7fWR9Fq91kANZGy5tJajo4tPdKJ5xFmZ8MTZ5z4QIs/k1uP+e
         edJ6yh7q7nuLszWMGA2yBP6z+N+qQmYch6egad5j93TqLvtZ37AuNH5H0YABqKV28Znn
         jWwH38nIisiZaILBFqlPlehglitr2gPSop6dUCl353xDC8SVapDNSTbWg+R3yHv45QKJ
         WxZQ+4dNLTJS/m8p/RXyZ5w3qUdWga8XrxtEV+LpbDS7RAy+9TeVzsgXX4yJ9CWdf701
         CO741yR1DVJBaxr1XxCOmAn0N8EtGIejwRVArQHHjDs4z5d6eJfIvtMjklhYG8EC3zvz
         JYNg==
X-Forwarded-Encrypted: i=1; AFNElJ8RRzl6m7WT5d5lF8m71Gfyu3QnQgrwDIfVCcfP0fyHwR6aK0QfOAqX6/qaRKGfeH5lpfd3UK4e35sznZs=@vger.kernel.org
X-Gm-Message-State: AOJu0Yz6cygzLJN4yubXj9/7Wz9kwPHjgo/I3VDpJzN3HAMZ1kZ7aSEy
	efwl5lA3NESYdLzdlGEnxtJFM3ykov6Txvc/zyZw3SeW3rJfoTcBidunpWJ8gg3tfWQRHO6xXSg
	WIYBBVoCCyLm0Dl+w4GHvvwFqHJF1MXI=
X-Gm-Gg: Acq92OFBQ+v6Q+AUlvXOxw2oaYnjjIUzExCyKz4WIwMAdpLfRJqR0Z7Oft3kdnD824+
	NIMF/0LPrCD1f0Jk3uErmtgMUb+VF1cGxb+vf/GZwLvxDmKCJANN/y9b45RyiCG/s66yx7Irjo/
	hN5/Uzor8mNzhm/cs2H3aJJ7UYOdUdJPQEE1aGWtX/WoLywsvabNVa1p2P8ZJK2c03LMRBVSHWw
	rU898PeUdmGyB8egHhuW1u/ben4jHRf0tH9sBLizZZIrAkqVMZdX7nqdM+ISX4AOQt/hfptpoTE
	Kul7OQulogzuBsx39c5Vso3VKPn+IQyDJZVfnRamf5x5HY6RjY7+I0DVrGrstetWz4F33bC9x9O
	NEwTjAEpKqMTBnEqC153AuzoH2RW4H9qdlg==
X-Received: by 2002:a05:7300:1352:b0:304:c73b:79ea with SMTP id
 5a478bee46e88-3077b576885mr1086279eec.3.1780683653180; Fri, 05 Jun 2026
 11:20:53 -0700 (PDT)
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
References: <20260605-impl-flags-additions-v2-0-0d27242f460b@kernel.org> <20260605-impl-flags-additions-v2-2-0d27242f460b@kernel.org>
In-Reply-To: <20260605-impl-flags-additions-v2-2-0d27242f460b@kernel.org>
From: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Date: Fri, 5 Jun 2026 20:20:39 +0200
X-Gm-Features: AVVi8CeIl2vCLCHZZ3Gcx1cA-h_fk7WHGbREsNmGiGSz7tsS2M76m0o-rEiXSuY
Message-ID: <CANiq72ksbJPBtOhB+Oo0bc48g+dYLXPOZz=yQVTE1C5H+jyKzQ@mail.gmail.com>
Subject: Re: [PATCH v2 2/2] rust: impl_flags: add bitwise operations with the
 underlying type
To: Andreas Hindborg <a.hindborg@kernel.org>
Cc: Miguel Ojeda <ojeda@kernel.org>, Gary Guo <gary@garyguo.net>, 
	=?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= <bjorn3_gh@protonmail.com>, 
	Benno Lossin <lossin@kernel.org>, Alice Ryhl <aliceryhl@google.com>, 
	Trevor Gross <tmgross@umich.edu>, Danilo Krummrich <dakr@kernel.org>, Boqun Feng <boqun@kernel.org>, 
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Fri, Jun 5, 2026 at 3:04=E2=80=AFPM Andreas Hindborg <a.hindborg@kernel.=
org> wrote:
>
> Add bitwise or operations between the flag value enum and the underlying
> type. This is useful when manipulating flags from C API without round
> tripping into the Rust flag container type:
>
>   let mut lim: bindings::queue_limits =3D unsafe { core::mem::zeroed() };

Can this use `zeroable` nowadays?

>   if self.write_cache {
>       lim.features |=3D request::Feature::WriteCache;
>   }
>
> The above code would be needlessly verbose without this direct assignment
> option.

v2 looks better overall, but I am wondering about Gary's question in
v1 -- not sure if you saw it:

  https://lore.kernel.org/rust-for-linux/DGPT710WN25X.1B9P21BE6X8P4@garyguo=
.net/

The commit message shows a converted case, but is it that much
verbose? Perhaps you can point to the use case / code that made you
think about adding these `impl`s?

Thanks!

Cheers,
Miguel

From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2EE904071F9;
	Sat,  6 Jun 2026 08:09:39 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1780733381; cv=none; b=BXZSmk8E7X1VFQtwoAG/0M0eVhWeafBODMlV4qrIoJwFckQf/EWsY7HSM8jpGapXiAwCaWYzlevdQ6A6AbNcVnmSELj7cAoGuJwtqTzgrV937u2dpEbhiPIwxbu0lrZPtEz8yGlELDqftX0j8NTkChg5iOirrDyyn/GEWLpi8TU=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1780733381; c=relaxed/simple;
	bh=Ddqaet52rqEDAhbQi3ZIb2FbL4lSrYZZXY408QDcirY=;
	h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID:
	 MIME-Version:Content-Type; b=RVMJpGbRjJ2knzlGP82A9gfmyY2dgZA0p6Hb4Z88vNoLW+3Ieub42aszUfjAoo2ZQZeErfsxDQKGyHKR2Lb8Pa6VaDZIDSk9ixMW3HOQmoSOQiSq6RVscSQGDDebtXvuhAukTgJ1Q9OrmUW9uGVs1gzdd/y8IeJLVoea+tq9kGU=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Lur9stjw; arc=none smtp.client-ip=100.103.45.18
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Lur9stjw"
Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7233F1F00893;
	Sat,  6 Jun 2026 08:09:37 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1780733379;
	bh=cE+0f4YhfxIdvdE/jaRWEABJzl0iFjhEKcegaGb/Gfg=;
	h=From:To:Cc:Subject:In-Reply-To:References:Date;
	b=Lur9stjwC+LWPWxPdFlEXgUaYe9u01mjBCnlNTK/Rnry5S0k4XF+spsmZXsMStFze
	 WB31QcD2H28Z1uPzXY1RuVRNh8mo9FmMU6ZR3YORhICWOrn61+vfLNk0vkjC8Q9GYH
	 0BXAt6betE17iNLkBTC9WM0N5S+OkN0y8H2kOMr3a0Hd4OG3t1bexlIF/x+LzlQdBN
	 GZU1JvYzlthRcXt6OB8Ll5lgSLL2kkAMACdiASaE3udUFOqF2mXnRiPlUtumeZbORh
	 vjLqa3TfD0Lf/qiBLIPcCaT0DZ3qg1lROcuFhfrW1snE5AeCV1TXiVsA0kyXO5rWNg
	 GuobbZypyY/XQ==
From: Andreas Hindborg <a.hindborg@kernel.org>
To: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Cc: Miguel Ojeda <ojeda@kernel.org>, Gary Guo <gary@garyguo.net>,
 =?utf-8?Q?Bj=C3=B6rn?= Roy
 Baron <bjorn3_gh@protonmail.com>, Benno Lossin <lossin@kernel.org>, Alice
 Ryhl <aliceryhl@google.com>, Trevor Gross <tmgross@umich.edu>, Danilo
 Krummrich <dakr@kernel.org>, Boqun Feng <boqun@kernel.org>,
 rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] rust: impl_flags: add bitwise operations with
 the underlying type
In-Reply-To: <CANiq72ksbJPBtOhB+Oo0bc48g+dYLXPOZz=yQVTE1C5H+jyKzQ@mail.gmail.com>
References: <20260605-impl-flags-additions-v2-0-0d27242f460b@kernel.org>
 <20260605-impl-flags-additions-v2-2-0d27242f460b@kernel.org>
 <CANiq72ksbJPBtOhB+Oo0bc48g+dYLXPOZz=yQVTE1C5H+jyKzQ@mail.gmail.com>
Date: Sat, 06 Jun 2026 10:09:31 +0200
Message-ID: <87h5nghyys.fsf@kernel.org>
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> writes:

> On Fri, Jun 5, 2026 at 3:04=E2=80=AFPM Andreas Hindborg <a.hindborg@kerne=
l.org> wrote:
>>
>> Add bitwise or operations between the flag value enum and the underlying
>> type. This is useful when manipulating flags from C API without round
>> tripping into the Rust flag container type:
>>
>>   let mut lim: bindings::queue_limits =3D unsafe { core::mem::zeroed() };
>
> Can this use `zeroable` nowadays?

Yes, probably.

>
>>   if self.write_cache {
>>       lim.features |=3D request::Feature::WriteCache;
>>   }
>>
>> The above code would be needlessly verbose without this direct assignment
>> option.
>
> v2 looks better overall, but I am wondering about Gary's question in
> v1 -- not sure if you saw it:
>
>   https://lore.kernel.org/rust-for-linux/DGPT710WN25X.1B9P21BE6X8P4@garyg=
uo.net/
>
> The commit message shows a converted case, but is it that much
> verbose? Perhaps you can point to the use case / code that made you
> think about adding these `impl`s?

I feel like we already discussed this. I don't understand the objection.
I have a C type integer that is a set of flags. In bindings, I
manipulate the flags (I will send this code within the next few days):

    /// Build a new `GenDisk` and add it to the VFS.
    pub fn build(
        self,
        name: fmt::Arguments<'_>,
        tagset: Arc<TagSet<T>>,
        queue_data: T::QueueData,
    ) -> Result<Arc<GenDisk<T>>> {
        let data =3D queue_data.into_foreign();
        let recover_data =3D ScopeGuard::new(|| {
            // SAFETY: T::QueueData was created by the call to `into_foreig=
n()` above
            drop(unsafe { T::QueueData::from_foreign(data) });
        });

        let mut lim: bindings::queue_limits =3D pin_init::zeroed();

        lim.logical_block_size =3D self.logical_block_size;
        lim.physical_block_size =3D self.physical_block_size;
        lim.max_hw_discard_sectors =3D self.max_hw_discard_sectors;
        lim.max_sectors =3D self.max_sectors;
        lim.virt_boundary_mask =3D self.virt_boundary_mask;
        if self.rotational {
            lim.features =3D Feature::Rotational.into();
        }

        #[cfg(CONFIG_BLK_DEV_ZONED)]
        if self.zoned {
            if !T::HAS_REPORT_ZONES {
                return Err(error::code::EINVAL);
            }

            lim.features |=3D Feature::Zoned;
            lim.chunk_sectors =3D self.zone_size_sectors;
            lim.max_hw_zone_append_sectors =3D self.zone_append_max_sectors;
        }

        if self.write_cache {
            lim.features |=3D Feature::WriteCache;
        }

        if self.forced_unit_access {
            lim.features |=3D Feature::ForcedUnitAccess;
        }

        // SAFETY: `tagset.raw_tag_set()` points to a valid and initialized=
 tag set
        let gendisk =3D from_err_ptr(unsafe {
            bindings::__blk_mq_alloc_disk(
                tagset.raw_tag_set(),
                &mut lim,
                data,
                static_lock_class!().as_ptr(),
            )
        })?;

        ...

I don't understand the rationale for writing these flags into a
temporary to then assigning later.


Best regards,
Andreas Hindborg



From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-dy1-f173.google.com (mail-dy1-f173.google.com [74.125.82.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 3595630C63A
	for <linux-kernel@vger.kernel.org>; Sat,  6 Jun 2026 11:22:11 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=74.125.82.173
ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1780744932; cv=pass; b=odEzmK/VLVDOdLbufTBgeGtDWAAgwzZIMBRS+QWz0j7FHjxirWShJC4eLuSIwvZtpAi2C3beQUZHYA99+OlxlD49pX8goHFm4N3bpQVgsiNt+TdepqwsF34sAxjgmFGSZAgfc53Q3ByG8fR4Es+0KaUwdDId699FTZA4VHjtoBI=
ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1780744932; c=relaxed/simple;
	bh=zjWFIdhkLdOcg6H+FzXTUqPe2VxkrkzrZmnKEbpQkSo=;
	h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject:
	 To:Cc:Content-Type; b=m8/nt21luyW5LORUXans7M2C2dTSv3ZoVP0Dqy4Ibok4vjRqsvWDI4qZfX9jWg+T4T1ugfuWpAAbejUsNc1WUZASKwrEJrv1E1/2qsThapNeTmI+gmTKU+AIz9bNG2xM/Ev5sA3d7BwbCUKsmi+NqQNI+Rt3+v5pDRhrstuqbQE=
ARC-Authentication-Results:i=2; 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=Q2XulmYy; arc=pass smtp.client-ip=74.125.82.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="Q2XulmYy"
Received: by mail-dy1-f173.google.com with SMTP id 5a478bee46e88-304cf9a02f9so168038eec.1
        for <linux-kernel@vger.kernel.org>; Sat, 06 Jun 2026 04:22:11 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1780744930; cv=none;
        d=google.com; s=arc-20240605;
        b=XVcL4T/TBXlfQCtjaNxY5DQ2x8rDuyMV/K7xhD91E5HoMP6BiEtVjvjtv+FmH5Sf6z
         RNzJYZitAKpK0WX+fG6f+flPUVLvqaCfwbIPaCwQyCQl3OG4ijp80wIqZY2Xlp0EQP+t
         zU//xJsyybkSHMWZO6s3jEgsEXh6I5fhiDR+Ay5xTYrA9tIwosR2bu+c01ks0plP5Zi3
         m1AN/7ZyzF9EYUgVTtHVVImY2/700cUVNGE4sHsxihjDsHjkcm40Htq34gHwxOEXyskT
         ZyGEErpu7UoByR+R3OC6SvfvFKlokLai70SUHAlAC9xNhmqm3OVVjrF/jbf+N1M4lg2Y
         WRZg==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605;
        h=content-transfer-encoding:cc:to:subject:message-id:date:from
         :in-reply-to:references:mime-version:dkim-signature;
        bh=zjWFIdhkLdOcg6H+FzXTUqPe2VxkrkzrZmnKEbpQkSo=;
        fh=Ar7P/WUF3DYi+57VdpJh/AVCC/zIC1qEtzu+1zX19bo=;
        b=AuK7w8oKkG7GBYTUpTz3in2mb1YYDXS3j9UraSm+MDdOHGqMFgJvyXpZdpF9M9myxm
         RC2JXkDkrZ0zrfsFOo0HEmIK/bhNBYi8OVJ8jkmQFdWWXCR0DxulV9b6fdtjM19xNRmb
         KGbVzMrn0nXXWlvhRgPcB0yDDQfBZ4U0iMX2YfJAGjeMsdPRB6LSzUU0L3tL/QvgaVOl
         hYajfqPJ2kNxrzexCdwG1RgjFq5xThj1zvtZEAOoVqAqYAoq3hgukWjLp4p81DKbmRov
         qn7TniteL6cxaiXJr8N88M6lGYYP56S0h3TESsF2y3+bFhrH0C4Dj2jcPtTs+8UKtHL/
         +2bA==;
        darn=vger.kernel.org
ARC-Authentication-Results: i=1; mx.google.com; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20251104; t=1780744930; x=1781349730; darn=vger.kernel.org;
        h=content-transfer-encoding:cc:to:subject:message-id:date:from
         :in-reply-to:references:mime-version:from:to:cc:subject:date
         :message-id:reply-to;
        bh=zjWFIdhkLdOcg6H+FzXTUqPe2VxkrkzrZmnKEbpQkSo=;
        b=Q2XulmYy+W7JroFbSjRm3u3mJrCQQM0+lZGyqM/jhHg1nAXYaaLSyjK7T84kqiW669
         9k3Rl/cyRiFAqQU12d/9lbRmdCiwUDpvqy11QnOH55xa+sjY8jpXkZY30coq/ioCSeC6
         tAB8zK4h0NKR/9t7/D/ppzdHqCoYkQPz7LmCD4c1hybuV6MW4fWGudrT+g3mGbH8lcrJ
         lNAxwuLWTzEaXjknldhLZ9Mu0fMmW7+GsXmwwyADu+qD9iXWADO7vchpvuf4/ZAbZgWc
         Z1gF2ecTTEdBEc+GIkYBFy/tLwTJbLHP5nSKFwNh1JymAEmlc4Ic6N+bHcICBIZCReBG
         EC7w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20251104; t=1780744930; x=1781349730;
        h=content-transfer-encoding:cc:to:subject:message-id:date:from
         :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from
         :to:cc:subject:date:message-id:reply-to;
        bh=zjWFIdhkLdOcg6H+FzXTUqPe2VxkrkzrZmnKEbpQkSo=;
        b=MdaDAuv3wLxd+fsGKnwnh95USSqCTv8IWwED63aMBFAmrk3vOyIjWiULDtFLemT6D/
         7yqUYhUsHmbKbXFeXeM577N3JP7DLyrO36Ya1olcATkUrLd1ICxxdSvSInBT0EXpyi2F
         39LWJeiXkQ88uWf2q3qWQH/jPpeW0VHxPc2ylN6RtimF6ZBOXygjHY20VCpvA+Fm1Wji
         1TQWQdkbBC2u+o/J1+56/KTyqPC/Xqr2YS+WszNdVflfxvLg/b8PBLp9jjYkZZYlxZI2
         6jyDLLavey8hfeOSlE40af/hNqI9uBzcVsv5MdXJX5ulFZTKNlAi0ma6pIn1hlk8elBY
         epmg==
X-Forwarded-Encrypted: i=1; AFNElJ8CcDtxwX8mUuvxMQWTbfE4gai6OKHzhn/YZGqGbf4vypnhwAVw8Io8aCWugExabThn9+hNS+T923Hd9/8=@vger.kernel.org
X-Gm-Message-State: AOJu0YwVkoIBBUHdMy0jKhS6Mrg/Ehri0D0B1PzVPHVFPNvSP4wnKTXN
	ce9VqFuXzJBpuny7Lvsq0osAVQZ3RyTHvbalHo8Gy+jS3uPh+uYzbVO4uAFQ9792gCedVw+I2Qh
	gO7banwXsBRAEbWJOPAnGT5z3/baF7UI=
X-Gm-Gg: Acq92OF7Nf++QRUdDkRg7fOGB7Z2Cpz3lVR5/xOMfCYox50Y24pDdh79skJsutnJkJc
	HR3M4JyL/CljVAzV/z3FT/tFH7PkR42AA8IKA7xFPpXum1yk6S+qC6mMC7oN1VK+BZCKFIKxz5g
	KkNbSLzUWvbocoSrMktDe1EEXzqxdKhvFznvbdhRZ8seaslk3xp5GDxnzSIkL8xD1Z/csNhx/bf
	DgmjbpLIztj/7iswgnyQsUafvF8ivw/2R/YTUDDkKNz6j6r2Z+TTAmP3IwTov2P6+IFTm2qwypE
	eW2c74bwZUgGgiGnx9Y2RtaoH6hLzMqFdc/UWB8e0FuzkZbABMIsZIIWU+ARCWnOuc5LBM6BAYQ
	b8MOTGdp27P7SlL4ysbXQeHOu++IrvPD6LA==
X-Received: by 2002:a05:7300:8cac:b0:304:f860:3ae3 with SMTP id
 5a478bee46e88-3077ae67a39mr2208435eec.1.1780744930174; Sat, 06 Jun 2026
 04:22:10 -0700 (PDT)
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
References: <20260605-impl-flags-additions-v2-0-0d27242f460b@kernel.org>
 <20260605-impl-flags-additions-v2-2-0d27242f460b@kernel.org>
 <CANiq72ksbJPBtOhB+Oo0bc48g+dYLXPOZz=yQVTE1C5H+jyKzQ@mail.gmail.com> <87h5nghyys.fsf@kernel.org>
In-Reply-To: <87h5nghyys.fsf@kernel.org>
From: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Date: Sat, 6 Jun 2026 13:21:57 +0200
X-Gm-Features: AVVi8Ces9z95vzzyqj6atvVnxV6Zs1XsS1qupLxQ_RE9HoEku_vDaT1_jAjSJco
Message-ID: <CANiq72nw96aQFqq8qXh0her9ELug39-rovTguqHNddnWSsApGg@mail.gmail.com>
Subject: Re: [PATCH v2 2/2] rust: impl_flags: add bitwise operations with the
 underlying type
To: Andreas Hindborg <a.hindborg@kernel.org>
Cc: Miguel Ojeda <ojeda@kernel.org>, Gary Guo <gary@garyguo.net>, 
	=?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= <bjorn3_gh@protonmail.com>, 
	Benno Lossin <lossin@kernel.org>, Alice Ryhl <aliceryhl@google.com>, 
	Trevor Gross <tmgross@umich.edu>, Danilo Krummrich <dakr@kernel.org>, Boqun Feng <boqun@kernel.org>, 
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Sat, Jun 6, 2026 at 10:09=E2=80=AFAM Andreas Hindborg <a.hindborg@kernel=
.org> wrote:
>
> I feel like we already discussed this. I don't understand the objection.

Now that you mention it, yeah. Hmm... it may be have been a call.

> I have a C type integer that is a set of flags. In bindings, I
> manipulate the flags (I will send this code within the next few days):

Yeah, so what I suggested is that providing the before-and-after
(rather than "after" only below as you do here and in the commit
message) can help to justify it.

That is, what exactly would you need to do before this patch? i.e. do
you really need a temporary? e.g. could you have written `as ...`
(putting aside that we try to avoid casts) or are we missing something
else from your use case? Would a `From` instead be good enough
instead?

My reading of Gary's comment is that, by providing too convenient
operators on the raw type, people may avoid actually using the newtype
when it makes sense to do so (which is a general principle that I
agree with).

In your case, I can see it is reasonable to have the operator there
(to avoid either casts or , and I think we are still in a better spot
than C here (since we only implement it for a particular primitive
type etc.), but yeah, it should have a better justification -- it is a
tradeoff to introduce more convenience, and the patch doesn't really
discuss it or its alternatives.

I hope this clarifies.

Cheers,
Miguel

