linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v10 0/5] rust: replace kernel::str::CStr w/ core::ffi::CStr
@ 2025-05-24 20:33 Tamir Duberstein
  2025-05-24 20:33 ` [PATCH v10 1/5] rust: retitle "Example" section as "Examples" Tamir Duberstein
                   ` (5 more replies)
  0 siblings, 6 replies; 34+ messages in thread
From: Tamir Duberstein @ 2025-05-24 20:33 UTC (permalink / raw)
  To: Michal Rostecki, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Brendan Higgins, David Gow, Rae Moar, Danilo Krummrich,
	Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
	Simona Vetter, Greg Kroah-Hartman, Rafael J. Wysocki,
	Luis Chamberlain, Russ Weight, FUJITA Tomonori, Rob Herring,
	Saravana Kannan, Peter Zijlstra, Ingo Molnar, Will Deacon,
	Waiman Long, Nathan Chancellor, Nick Desaulniers, Bill Wendling,
	Justin Stitt, Andrew Lunn, Heiner Kallweit, Russell King,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Bjorn Helgaas, Arnd Bergmann, Jens Axboe, Benno Lossin,
	Krzysztof Wilczyński, Benno Lossin
  Cc: rust-for-linux, linux-kernel, linux-kselftest, kunit-dev,
	dri-devel, netdev, devicetree, llvm, linux-pci, nouveau,
	linux-block, Tamir Duberstein

This picks up from Michal Rostecki's work[0]. Per Michal's guidance I
have omitted Co-authored tags, as the end result is quite different.

Link: https://lore.kernel.org/rust-for-linux/20240819153656.28807-2-vadorovsky@protonmail.com/t/#u [0]
Closes: https://github.com/Rust-for-Linux/linux/issues/1075

Signed-off-by: Tamir Duberstein <tamird@gmail.com>
---
Changes in v10:
- Rebase on cbeaa41dfe26b72639141e87183cb23e00d4b0dd.
- Implement Alice's suggestion to use a proc macro to work around orphan
  rules otherwise preventing `core::ffi::CStr` to be directly printed
  with `{}`.
- Link to v9: https://lore.kernel.org/r/20250317-cstr-core-v9-0-51d6cc522f62@gmail.com

Changes in v9:
- Rebase on rust-next.
- Restore `impl Display for BStr` which exists upstream[1].
- Link: https://doc.rust-lang.org/nightly/std/bstr/struct.ByteStr.html#impl-Display-for-ByteStr [1]
- Link to v8: https://lore.kernel.org/r/20250203-cstr-core-v8-0-cb3f26e78686@gmail.com

Changes in v8:
- Move `{from,as}_char_ptr` back to `CStrExt`. This reduces the diff
  some.
- Restore `from_bytes_with_nul_unchecked_mut`, `to_cstring`.
- Link to v7: https://lore.kernel.org/r/20250202-cstr-core-v7-0-da1802520438@gmail.com

Changes in v7:
- Rebased on mainline.
- Restore functionality added in commit a321f3ad0a5d ("rust: str: add
  {make,to}_{upper,lower}case() to CString").
- Used `diff.algorithm patience` to improve diff readability.
- Link to v6: https://lore.kernel.org/r/20250202-cstr-core-v6-0-8469cd6d29fd@gmail.com

Changes in v6:
- Split the work into several commits for ease of review.
- Restore `{from,as}_char_ptr` to allow building on ARM (see commit
  message).
- Add `CStrExt` to `kernel::prelude`. (Alice Ryhl)
- Remove `CStrExt::from_bytes_with_nul_unchecked_mut` and restore
  `DerefMut for CString`. (Alice Ryhl)
- Rename and hide `kernel::c_str!` to encourage use of C-String
  literals.
- Drop implementation and invocation changes in kunit.rs. (Trevor Gross)
- Drop docs on `Display` impl. (Trevor Gross)
- Rewrite docs in the style of the standard library.
- Restore the `test_cstr_debug` unit tests to demonstrate that the
  implementation has changed.

Changes in v5:
- Keep the `test_cstr_display*` unit tests.

Changes in v4:
- Provide the `CStrExt` trait with `display()` method, which returns a
   `CStrDisplay` wrapper with `Display` implementation. This addresses
   the lack of `Display` implementation for `core::ffi::CStr`.
- Provide `from_bytes_with_nul_unchecked_mut()` method in `CStrExt`,
   which might be useful and is going to prevent manual, unsafe casts.
- Fix a typo (s/preffered/prefered/).

Changes in v3:
- Fix the commit message.
- Remove redundant braces in `use`, when only one item is imported.

Changes in v2:
- Do not remove `c_str` macro. While it's preferred to use C-string
   literals, there are two cases where `c_str` is helpful:
   - When working with macros, which already return a Rust string literal
     (e.g. `stringify!`).
   - When building macros, where we want to take a Rust string literal as an
     argument (for caller's convenience), but still use it as a C-string
     internally.
- Use Rust literals as arguments in macros (`new_mutex`, `new_condvar`,
   `new_mutex`). Use the `c_str` macro to convert these literals to C-string
   literals.
- Use `c_str` in kunit.rs for converting the output of `stringify!` to a
   `CStr`.
- Remove `DerefMut` implementation for `CString`.

---
Tamir Duberstein (5):
      rust: retitle "Example" section as "Examples"
      rust: support formatting of foreign types
      rust: replace `CStr` with `core::ffi::CStr`
      rust: replace `kernel::c_str!` with C-Strings
      rust: remove core::ffi::CStr reexport

 drivers/block/rnull.rs               |   2 +-
 drivers/gpu/drm/drm_panic_qr.rs      |   5 +-
 drivers/gpu/nova-core/driver.rs      |   2 +-
 drivers/gpu/nova-core/firmware.rs    |   2 +-
 drivers/net/phy/ax88796b_rust.rs     |   8 +-
 drivers/net/phy/qt2025.rs            |   6 +-
 rust/kernel/block/mq.rs              |   2 +-
 rust/kernel/device.rs                |   9 +-
 rust/kernel/devres.rs                |   2 +-
 rust/kernel/driver.rs                |   4 +-
 rust/kernel/error.rs                 |  10 +-
 rust/kernel/faux.rs                  |   5 +-
 rust/kernel/firmware.rs              |  16 +-
 rust/kernel/fmt.rs                   |  77 +++++++
 rust/kernel/kunit.rs                 |  21 +-
 rust/kernel/lib.rs                   |   3 +-
 rust/kernel/miscdevice.rs            |   5 +-
 rust/kernel/net/phy.rs               |  12 +-
 rust/kernel/of.rs                    |   5 +-
 rust/kernel/pci.rs                   |   2 +-
 rust/kernel/platform.rs              |   6 +-
 rust/kernel/prelude.rs               |   5 +-
 rust/kernel/print.rs                 |   4 +-
 rust/kernel/seq_file.rs              |   6 +-
 rust/kernel/str.rs                   | 415 ++++++++++-------------------------
 rust/kernel/sync.rs                  |   7 +-
 rust/kernel/sync/condvar.rs          |   4 +-
 rust/kernel/sync/lock.rs             |   4 +-
 rust/kernel/sync/lock/global.rs      |   6 +-
 rust/kernel/sync/poll.rs             |   1 +
 rust/kernel/workqueue.rs             |   1 +
 rust/macros/fmt.rs                   | 118 ++++++++++
 rust/macros/kunit.rs                 |   6 +-
 rust/macros/lib.rs                   |  21 +-
 rust/macros/module.rs                |   2 +-
 samples/rust/rust_driver_faux.rs     |   4 +-
 samples/rust/rust_driver_pci.rs      |   4 +-
 samples/rust/rust_driver_platform.rs |   4 +-
 samples/rust/rust_misc_device.rs     |   3 +-
 scripts/rustdoc_test_gen.rs          |   2 +-
 40 files changed, 426 insertions(+), 395 deletions(-)
---
base-commit: cbeaa41dfe26b72639141e87183cb23e00d4b0dd
change-id: 20250201-cstr-core-d4b9b69120cf

Best regards,
-- 
Tamir Duberstein <tamird@gmail.com>


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

end of thread, other threads:[~2025-05-29 22:28 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-24 20:33 [PATCH v10 0/5] rust: replace kernel::str::CStr w/ core::ffi::CStr Tamir Duberstein
2025-05-24 20:33 ` [PATCH v10 1/5] rust: retitle "Example" section as "Examples" Tamir Duberstein
2025-05-26 11:28   ` Benno Lossin
2025-05-26 16:15   ` Miguel Ojeda
2025-05-26 20:41     ` Tamir Duberstein
2025-05-24 20:33 ` [PATCH v10 2/5] rust: support formatting of foreign types Tamir Duberstein
2025-05-26 14:48   ` Benno Lossin
2025-05-26 22:17     ` Tamir Duberstein
2025-05-26 23:01       ` Benno Lossin
2025-05-27 15:02         ` Tamir Duberstein
2025-05-27 20:49           ` Benno Lossin
2025-05-29 22:07             ` Tamir Duberstein
2025-05-27 12:44       ` Alice Ryhl
2025-05-27 14:57         ` Tamir Duberstein
2025-05-24 20:33 ` [PATCH v10 3/5] rust: replace `CStr` with `core::ffi::CStr` Tamir Duberstein
2025-05-26 14:56   ` Benno Lossin
2025-05-26 22:24     ` Tamir Duberstein
2025-05-26 23:03       ` Benno Lossin
2025-05-27 15:31         ` Tamir Duberstein
2025-05-24 20:33 ` [PATCH v10 4/5] rust: replace `kernel::c_str!` with C-Strings Tamir Duberstein
2025-05-26 15:04   ` Benno Lossin
2025-05-26 22:29     ` Tamir Duberstein
2025-05-26 23:06       ` Benno Lossin
2025-05-27 15:31         ` Tamir Duberstein
2025-05-28 10:36       ` Alice Ryhl
2025-05-28 15:34         ` Benno Lossin
2025-05-29 22:21           ` Tamir Duberstein
2025-05-29 22:28             ` Benno Lossin
2025-05-24 20:33 ` [PATCH v10 5/5] rust: remove core::ffi::CStr reexport Tamir Duberstein
2025-05-26 15:05   ` Benno Lossin
2025-05-26 22:30     ` Tamir Duberstein
2025-05-26 23:17       ` Benno Lossin
2025-05-28 10:38 ` [PATCH v10 0/5] rust: replace kernel::str::CStr w/ core::ffi::CStr Alice Ryhl
2025-05-28 14:10   ` Tamir Duberstein

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).