Alexandre Courbot
2025-Oct-22 10:50 UTC
[PATCH 0/3] gpu: nova-core: various bitfield fixes
These trivial patches fix a few issues reported by Edwin in [1].
[1] https://lore.kernel.org/rust-for-linux/F3853912-2C1C-4F9B-89B0-3168689F35B3
at nvidia.com/
To: Danilo Krummrich <dakr at kernel.org>
To: Alice Ryhl <aliceryhl at google.com>
To: Edwin Peer <epeer at nvidia.com>
Cc: John Hubbard <jhubbard at nvidia.com>
Cc: Alistair Popple <apopple at nvidia.com>
Cc: Joel Fernandes <joelagnelf at nvidia.com>
Cc: Timur Tabi <ttabi at nvidia.com>
Cc: nouveau at lists.freedesktop.org
Cc: dri-devel at lists.freedesktop.org
Cc: linux-kernel at vger.kernel.org
Cc: rust-for-linux at vger.kernel.org
Signed-off-by: Alexandre Courbot <acourbot at nvidia.com>
---
Alexandre Courbot (3):
gpu: nova-core: bitfield: simplify condition
gpu: nova-core: bitfield: simplify expression
gpu: nova-core: bitfield: remove BitOr implementation
drivers/gpu/nova-core/bitfield.rs | 14 +++-----------
1 file changed, 3 insertions(+), 11 deletions(-)
---
base-commit: 5ae65bdcb867555540169ef57876658262a67d87
change-id: 20251022-nova-bitfield-2846201b6544
Best regards,
--
Alexandre Courbot <acourbot at nvidia.com>
Alexandre Courbot
2025-Oct-22 10:50 UTC
[PATCH 1/3] gpu: nova-core: bitfield: simplify condition
This condition was uselessly convoluted.
Reported-by: Edwin Peer <epeer at nvidia.com>
Link:
https://lore.kernel.org/rust-for-linux/F3853912-2C1C-4F9B-89B0-3168689F35B3 at
nvidia.com/
Signed-off-by: Alexandre Courbot <acourbot at nvidia.com>
---
drivers/gpu/nova-core/bitfield.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/nova-core/bitfield.rs
b/drivers/gpu/nova-core/bitfield.rs
index 25579b4c328f..136de7289162 100644
--- a/drivers/gpu/nova-core/bitfield.rs
+++ b/drivers/gpu/nova-core/bitfield.rs
@@ -203,7 +203,7 @@ impl $name {
) => {
bitfield!(
@leaf_accessor $vis $name $storage, $hi:$lo $field
- { |f| <$into_type>::from(if f != 0 { true } else { false }) }
+ { |f| <$into_type>::from(f != 0) }
bool $into_type => $into_type $(, $comment)?;
);
};
--
2.51.0
Alexandre Courbot
2025-Oct-22 10:50 UTC
[PATCH 2/3] gpu: nova-core: bitfield: simplify expression
The shift is more easily expressed by the index of the lowest bit of the
field.
Reported-by: Edwin Peer <epeer at nvidia.com>
Link:
https://lore.kernel.org/rust-for-linux/F3853912-2C1C-4F9B-89B0-3168689F35B3 at
nvidia.com/
Signed-off-by: Alexandre Courbot <acourbot at nvidia.com>
---
drivers/gpu/nova-core/bitfield.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/nova-core/bitfield.rs
b/drivers/gpu/nova-core/bitfield.rs
index 136de7289162..f113439c6501 100644
--- a/drivers/gpu/nova-core/bitfield.rs
+++ b/drivers/gpu/nova-core/bitfield.rs
@@ -268,7 +268,7 @@ impl $name {
_ => ::kernel::build_error!("Unsupported storage type
size")
}
};
- const [<$field:upper _SHIFT>]: u32 = Self::[<$field:upper
_MASK>].trailing_zeros();
+ const [<$field:upper _SHIFT>]: u32 = $lo;
);
$(
--
2.51.0
Alexandre Courbot
2025-Oct-22 10:50 UTC
[PATCH 3/3] gpu: nova-core: bitfield: remove BitOr implementation
Using this operand can produce invalid values. It also doesn't bring
any benefit as one can use the builder pattern to assemble a new value.
Reported-by: Edwin Peer <epeer at nvidia.com>
Link:
https://lore.kernel.org/rust-for-linux/F3853912-2C1C-4F9B-89B0-3168689F35B3 at
nvidia.com/
Signed-off-by: Alexandre Courbot <acourbot at nvidia.com>
---
drivers/gpu/nova-core/bitfield.rs | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/drivers/gpu/nova-core/bitfield.rs
b/drivers/gpu/nova-core/bitfield.rs
index f113439c6501..16e143658c51 100644
--- a/drivers/gpu/nova-core/bitfield.rs
+++ b/drivers/gpu/nova-core/bitfield.rs
@@ -94,7 +94,7 @@ macro_rules! bitfield {
// All rules below are helpers.
// Defines the wrapper `$name` type, as well as its relevant
implementations (`Debug`,
- // `Default`, `BitOr`, and conversion to the value type) and field accessor
methods.
+ // `Default`, and conversion to the value type) and field accessor methods.
(@core $vis:vis $name:ident $storage:ty $(, $comment:literal)? {
$($fields:tt)* }) => {
$(
#[doc=$comment]
@@ -103,14 +103,6 @@ macro_rules! bitfield {
#[derive(Clone, Copy)]
$vis struct $name($storage);
- impl ::core::ops::BitOr for $name {
- type Output = Self;
-
- fn bitor(self, rhs: Self) -> Self::Output {
- Self(self.0 | rhs.0)
- }
- }
-
impl ::core::convert::From<$name> for $storage {
fn from(val: $name) -> $storage {
val.0
--
2.51.0
On 10/22/25 12:50 PM, Alexandre Courbot wrote:> These trivial patches fix a few issues reported by Edwin in [1]. > > [1] https://lore.kernel.org/rust-for-linux/F3853912-2C1C-4F9B-89B0-3168689F35B3 at nvidia.com/ > > To: Danilo Krummrich <dakr at kernel.org> > To: Alice Ryhl <aliceryhl at google.com> > To: Edwin Peer <epeer at nvidia.com> > Cc: John Hubbard <jhubbard at nvidia.com> > Cc: Alistair Popple <apopple at nvidia.com> > Cc: Joel Fernandes <joelagnelf at nvidia.com> > Cc: Timur Tabi <ttabi at nvidia.com> > Cc: nouveau at lists.freedesktop.org > Cc: dri-devel at lists.freedesktop.org > Cc: linux-kernel at vger.kernel.org > Cc: rust-for-linux at vger.kernel.org > > Signed-off-by: Alexandre Courbot <acourbot at nvidia.com>Reviewed-by: Danilo Krummrich <dakr at kernel.org>