[PATCH v5 4/4] rust: Add warn_on macro
FUJITA Tomonori
fujita.tomonori at gmail.com
Thu Apr 10 05:34:02 PDT 2025
On Thu, 10 Apr 2025 07:39:48 +0000
Alice Ryhl <aliceryhl at google.com> wrote:
>> diff --git a/rust/kernel/bug.rs b/rust/kernel/bug.rs
>> new file mode 100644
>> index 000000000000..761f0c49ae04
>> --- /dev/null
>> +++ b/rust/kernel/bug.rs
>> @@ -0,0 +1,114 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +
>> +// Copyright (C) 2024, 2025 FUJITA Tomonori <fujita.tomonori at gmail.com>
>> +
>> +//! Support for BUG and WARN functionality.
>> +//!
>> +//! C header: [`include/asm-generic/bug.h`](srctree/include/asm-generic/bug.h)
>> +
>> +#[macro_export]
>> +#[doc(hidden)]
>> +#[cfg(all(CONFIG_BUG, not(CONFIG_UML), not(CONFIG_LOONGARCH), not(CONFIG_ARM)))]
>> +#[cfg(CONFIG_DEBUG_BUGVERBOSE)]
>> +macro_rules! warn_flags {
>> + ($flags:expr) => {
>> + const FLAGS: u32 = $crate::bindings::BUGFLAG_WARNING | $flags;
>> + const _FILE: &[u8] = file!().as_bytes();
>> + // Plus one for null-terminator.
>> + static FILE: [u8; _FILE.len() + 1] = {
>> + let mut bytes = [0; _FILE.len() + 1];
>> + let mut i = 0;
>> + while i < _FILE.len() {
>> + bytes[i] = _FILE[i];
>> + i += 1;
>> + }
>> + bytes
>> + };
>> + // SAFETY: Just an FFI call.
>
> Safety comments could be improved. This being an FFI call is not the
> reason why it's okay. Furthermore, it's not an FFI call.
>
> Otherwise, this series LGTM.
SAFETY: It's always safe to embed metadata such as the source file
name, line number, and flags into the .bug_table ELF section.
Looks good?
More information about the linux-riscv
mailing list