[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAH5fLgiHVoOSMDwnXDZ5tH58iTPre_BAu0AE5=0a0_P6B4j_Kg@mail.gmail.com>
Date: Mon, 1 Sep 2025 10:34:12 +0200
From: Alice Ryhl <aliceryhl@...gle.com>
To: Andreas Hindborg <a.hindborg@...nel.org>
Cc: Boqun Feng <boqun.feng@...il.com>, Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <lossin@...nel.org>, Trevor Gross <tmgross@...ch.edu>,
Danilo Krummrich <dakr@...nel.org>, Jens Axboe <axboe@...nel.dk>, Breno Leitao <leitao@...ian.org>,
linux-block@...r.kernel.org, rust-for-linux@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v6 06/18] rust: str: add `bytes_to_bool` helper function
On Fri, Aug 22, 2025 at 2:15 PM Andreas Hindborg <a.hindborg@...nel.org> wrote:
>
> Add a convenience function to convert byte slices to boolean values by
> wrapping them in a null-terminated C string and delegating to the
> existing `kstrtobool` function. Only considers the first two bytes of
> the input slice, following the kernel's boolean parsing semantics.
>
> Signed-off-by: Andreas Hindborg <a.hindborg@...nel.org>
One nit below, but generally looks good.
Reviewed-by: Alice Ryhl <aliceryhl@...gle.com>
> +/// # Safety
> +///
> +/// - `string` must point to a null terminated string that is valid for read.
> +unsafe fn kstrtobool_raw(string: *const u8) -> Result<bool> {
> + let mut result: bool = false;
> +
> + // SAFETY:
> + // - By function safety requirement, `string` is a valid null-terminated string.
> + // - `result` is a valid `bool` that we own.
> + let ret = unsafe { bindings::kstrtobool(string, &mut result) };
> +
> + kernel::error::to_result(ret).map(|()| result)
I think this is easier to read as:
to_result(unsafe { bindings::kstrtobool(string, &mut result) })?;
Ok(result)
Alice
Powered by blists - more mailing lists