]> git.ipfire.org Git - thirdparty/linux.git/commit
rust: Introduce file_from_location()
authorBoqun Feng <boqun.feng@gmail.com>
Sun, 15 Jun 2025 22:14:00 +0000 (15:14 -0700)
committerBoqun Feng <boqun.feng@gmail.com>
Tue, 24 Jun 2025 22:53:46 +0000 (15:53 -0700)
commit0aa2b78ce5a9eac8f3332192ea77755d63a831cd
treedf506edc55b3eb6c2f43564b58f301b23c6f43c1
parent0a41f5af19391ce55cae1f0d7a562e8694bf1fd5
rust: Introduce file_from_location()

Most of kernel debugging facilities take a nul-terminated string for
file names for a callsite (generated from __FILE__), however the Rust
courterpart, Location, would return a Rust string (not nul-terminated)
from method .file(). And such a string cannot be passed to C debugging
function directly.

There is ongoing work to support a Location::file_with_nul() [1], which
returns a nul-terminated string from a Location. Since it's still
working in progress, and it will take some time before the feature
finally gets stabilized and the kernel's minimal rustc version might
also take a while to bump to a version that at least has that feature,
introduce a file_from_location() function, which returns a warning
string if Location::file_with_nul() is not available.

This should work in most cases because as for now the known usage of
Location::file_with_nul() is only in debugging code (e.g. might_sleep())
and there might be other information reported by the debugging code that
could help locate the problematic function, so missing the file name is
fine at the moment.

Link: https://github.com/rust-lang/rust/issues/141727
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20250619151007.61767-2-boqun.feng@gmail.com
init/Kconfig
rust/kernel/lib.rs