mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 00/13] drm/tyr: reduce the number of `as` casts
@ 2026-11-25 22:46 Daniel Almeida
  2026-11-25 22:46 ` [PATCH 01/13] drm/tyr: convert SeatInfo::slot from u8 to usize Daniel Almeida
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: Daniel Almeida @ 2026-11-25 22:46 UTC (permalink / raw)
  To: Daniel Almeida, Alice Ryhl, Danilo Krummrich, David Airlie,
	Simona Vetter, Benno Lossin, Gary Guo, Miguel Ojeda, Boqun Feng,
	Björn Roy Baron, Andreas Hindborg, Trevor Gross,
	Tamir Duberstein, Alexandre Courbot, Onur Özkan
  Cc: dri-devel, rust-for-linux, linux-kernel

An `as` cast silently drops the bits that do not fit the target type,
and nothing at the cast shows whether that can happen. Tyr has 86 of
them, as counted by `clippy::as_conversions`. This series removes 62.

Patches 1 to 4 change the type a value is kept in, so that it needs no
cast. Patches 5 to 8 use what the kernel already provides:
`SizeConstants`, `From`, `FromSafeCast`, `cv!` and the `all_bits()` of
`impl_flags!`. Patches 10 and 11 move repeated casts into one place.

The 24 casts that remain are each justified in a `// CAST:` comment and
marked with `#[expect(clippy::as_conversions)]`. 19 of them convert an
enum to its integer value. I intend to follow up with an RFC that
generates these conversions with nova-core's `bounded_enum!`.

The last patch denies `clippy::as_conversions` in the driver, so that
Clippy rejects a new cast unless it is marked.

---
Daniel Almeida (13):
      drm/tyr: convert SeatInfo::slot from u8 to usize
      drm/tyr: convert VmAsData::va_bits from u8 to u32
      drm/tyr: convert the lock region exponents from u8 to u32
      drm/tyr: convert EntryHeader to `bitfield!`
      drm/tyr: use SizeConstants for the u32 and u64 size constants
      drm/tyr: replace lossless `as` casts with From and FromSafeCast
      drm/tyr: use `cv!` for constant conversions
      drm/tyr: use VmMapFlags::all_bits() to validate map flags
      drm/tyr: justify the casts of enums to their integer value
      drm/tyr: add split_u64() for the 64-bit register values
      drm/tyr: return usize from get_pgsize()
      drm/tyr: justify the physical address cast in pt_map()
      drm/tyr: deny `clippy::as_conversions`

 drivers/gpu/drm/tyr/file.rs              |  2 +-
 drivers/gpu/drm/tyr/fw.rs                | 11 +++--
 drivers/gpu/drm/tyr/fw/parser.rs         | 62 ++++++++++++-------------
 drivers/gpu/drm/tyr/mmu/address_space.rs | 54 ++++++++++------------
 drivers/gpu/drm/tyr/regs.rs              | 56 +++++++++++++++++++++--
 drivers/gpu/drm/tyr/slot.rs              | 23 ++++------
 drivers/gpu/drm/tyr/tyr.rs               |  5 ++
 drivers/gpu/drm/tyr/vm.rs                | 78 ++++++++++++++++----------------
 8 files changed, 167 insertions(+), 124 deletions(-)
---
base-commit: 7402dd230f4497954b465145a22cff7a5a488629
change-id: 20261125-b4-tyr-as-casts-0fdbbfca4157

Best regards,
--  
Daniel Almeida <daniel.almeida@collabora.com>


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

end of thread, other threads:[~2026-11-26 10:02 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 22:46 [PATCH 00/13] drm/tyr: reduce the number of `as` casts Daniel Almeida
2026-11-25 22:46 ` [PATCH 01/13] drm/tyr: convert SeatInfo::slot from u8 to usize Daniel Almeida
2026-11-25 22:46 ` [PATCH 02/13] drm/tyr: convert VmAsData::va_bits from u8 to u32 Daniel Almeida
2026-11-25 22:46 ` [PATCH 03/13] drm/tyr: convert the lock region exponents " Daniel Almeida
2026-11-25 22:46 ` [PATCH 04/13] drm/tyr: convert EntryHeader to `bitfield!` Daniel Almeida
2026-11-25 22:46 ` [PATCH 05/13] drm/tyr: use SizeConstants for the u32 and u64 size constants Daniel Almeida
2026-11-25 22:46 ` [PATCH 06/13] drm/tyr: replace lossless `as` casts with From and FromSafeCast Daniel Almeida
2026-11-25 22:46 ` [PATCH 07/13] drm/tyr: use `cv!` for constant conversions Daniel Almeida
2026-11-25 22:46 ` [PATCH 08/13] drm/tyr: use VmMapFlags::all_bits() to validate map flags Daniel Almeida
2026-11-25 22:47 ` [PATCH 09/13] drm/tyr: justify the casts of enums to their integer value Daniel Almeida
2026-11-25 22:47 ` [PATCH 10/13] drm/tyr: add split_u64() for the 64-bit register values Daniel Almeida
2026-11-25 22:47 ` [PATCH 11/13] drm/tyr: return usize from get_pgsize() Daniel Almeida
2026-11-25 22:47 ` [PATCH 12/13] drm/tyr: justify the physical address cast in pt_map() Daniel Almeida
2026-11-25 22:47 ` [PATCH 13/13] drm/tyr: deny `clippy::as_conversions` Daniel Almeida
2026-11-26 10:02 ` [PATCH 00/13] drm/tyr: reduce the number of `as` casts Alice Ryhl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®