Thank you for your contribution! Sashiko AI review found 1 potential issue(s) 
to consider:
- [Low] The `$dev` expression in `selftest_assert!` is conditionally evaluated 
only when the assertion fails, which can lead to inconsistent side effects.
--

--- Patch [11]: [PATCH v2 11/12] gpu: nova-core: Add self-test assertion macros 
and config option ---
commit 205e1404103e41ca5c6fd34482ac0f24c1d05216
Author: Eliot Courtney <[email protected]>

gpu: nova-core: Add self-test assertion macros and config option

The existing assert! and assert_eq! macros cause a panic. For self tests
in nova-core, it's inconvenient to cause a panic since these need to be
run on actual hardware. Instead, define similar macros that log an error
then return an Err.

> diff --git a/drivers/gpu/nova-core/selftest.rs 
> b/drivers/gpu/nova-core/selftest.rs
> new file mode 100644
> index 0000000000000..f5b5965b7e6ad
> --- /dev/null
> +++ b/drivers/gpu/nova-core/selftest.rs

[ ... ]

> @@ -0,0 +1,64 @@
> +// SPDX-License-Identifier: GPL-2.0
> +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & 
> AFFILIATES. All rights reserved.

[ ... ]

> +#[macro_export]
> +macro_rules! selftest_assert {
> +    ($dev:expr, $cond:expr $(,)?) => {
> +        $crate::selftest_assert!($dev, $cond, "assertion failed: {}", 
> ::core::stringify!($cond))
> +    };
> +    ($dev:expr, $cond:expr, $($arg:tt)+) => {{
> +        if !$cond {
> +            ::kernel::dev_err!(
> +                $dev,

[Severity: Low]
Could this lead to inconsistent side effects if the $dev expression contains
them?

Since $dev is only evaluated inside the if !$cond block, any side effects in
the expression passed as $dev will only occur on the error path when the
assertion fails. They will be skipped on the happy path.

Would it be safer to evaluate $dev outside the condition, for instance by
binding it to a local variable like let dev = $dev; before the check?

> +                "Selftest: {}:{}: {}\n",
> +                ::core::file!(),
> +                ::core::line!(),
> +                ::kernel::prelude::fmt!($($arg)+)
> +            );
> +            return Err(::kernel::error::code::EIO);
> +        }
> +    }};
> +}

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=11

Reply via email to