rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/2] rust: `overflow_assert!` macro
@ 2025-06-29  2:43 Antonio Hickey
  2025-06-29  2:43 ` [PATCH v4 1/2] rust: kernel: create " Antonio Hickey
  2025-06-29  2:43 ` [PATCH v4 2/2] rust: uaccess: refactor to use `overflow_assert!` Antonio Hickey
  0 siblings, 2 replies; 9+ messages in thread
From: Antonio Hickey @ 2025-06-29  2:43 UTC (permalink / raw)
  To: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, Danilo Krummrich
  Cc: Antonio Hickey, Daniel Cote, Tamir Duberstein, rust-for-linux

This patch set introduces a macro for overflow assertions, the use of
this macro will avoid local `#ifdef`s by encapsulating the conditional
behavior to the macro. In addition this macro also allows us to document
the intent of the assertion more clearly.

This patch set requires Alice's `strncpy_from_user` patch[1] linked below, 
because I use it as an example usecase for the `overflow_assert!` macro.

Dependent Patch [1]: https://lore.kernel.org/rust-for-linux/20250616-strncpy-from-user-v5-0-2d3fb0e1f5af@google.com/

Changes in v4:
- Added the ability for callers to supply a custom message to the
  overflow assertion.
- Small change to verbage in documentation. 
- Link to v3: https://lore.kernel.org/all/20250621230231.100181-1-contact@antoniohickey.com/

Changes in v3:
- Made the `overflow_assert!` macro take in expressions instead of
  values.
- Fixed path in macro to fully qualify.
- Refactor macro to make the conditional compilation as local as
  possible.
- Refactor macro to utilize the `cfg!` macro like the standard library
  does to reduce boilerplate.
- Added an example use case of the `overflow_assert!` macro
- Link to v2: https://lore.kernel.org/rust-for-linux/20250504165612.86459-1-contact@antoniohickey.com/

Changes in v2:
- Fixed example doc comment so it doesn't panic.
- Link to v1: https://lore.kernel.org/rust-for-linux/20250504164349.84149-1-contact@antoniohickey.com/

Co-developed-by: Daniel Cote <danielstonecote@gmail.com>
Signed-off-by: Daniel Cote <danielstonecote@gmail.com>
Signed-off-by: Antonio Hickey <contact@antoniohickey.com>
Link: https://github.com/Rust-for-Linux/linux/issues/1159
Suggested-by: Miguel Ojeda <ojeda@kernel.org>
Cc: Tamir Duberstein <tamird@gmail.com>

Antonio Hickey (2):
  rust: kernel: create `overflow_assert!` macro
  rust: uaccess: refactor to use `overflow_assert!`

 rust/kernel/lib.rs             |  1 +
 rust/kernel/overflow_assert.rs | 32 ++++++++++++++++++++++++++++++++
 rust/kernel/uaccess.rs         |  4 ++--
 3 files changed, 35 insertions(+), 2 deletions(-)
 create mode 100644 rust/kernel/overflow_assert.rs

-- 
2.50.0



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

end of thread, other threads:[~2025-07-21 11:28 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-29  2:43 [PATCH v4 0/2] rust: `overflow_assert!` macro Antonio Hickey
2025-06-29  2:43 ` [PATCH v4 1/2] rust: kernel: create " Antonio Hickey
2025-06-29 16:04   ` Tamir Duberstein
2025-07-20 16:17     ` Antonio Hickey
2025-07-20 16:23       ` Tamir Duberstein
2025-07-20 16:58   ` Miguel Ojeda
2025-06-29  2:43 ` [PATCH v4 2/2] rust: uaccess: refactor to use `overflow_assert!` Antonio Hickey
2025-06-29 19:01   ` Tamir Duberstein
2025-07-21 11:28   ` Alice Ryhl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).