[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87o6shdmg7.fsf@t14s.mail-host-address-is-not-set>
Date: Fri, 15 Aug 2025 10:21:44 +0200
From: Andreas Hindborg <a.hindborg@...nel.org>
To: Alice Ryhl <aliceryhl@...gle.com>
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 v5 05/18] rust: str: introduce `kstrtobool` function
"Alice Ryhl" <aliceryhl@...gle.com> writes:
> On Fri, Aug 15, 2025 at 09:30:40AM +0200, Andreas Hindborg wrote:
<cut>
>> +pub fn kstrtobool(string: &CStr) -> Result<bool> {
>> + let mut result: bool = false;
>> +
>> + // SAFETY: `string` is a valid null-terminated C string, and `result` is a valid
>> + // pointer to a bool that we own.
>> + let ret =
>> + unsafe { bindings::kstrtobool(string.as_char_ptr(), core::ptr::from_mut(&mut result)) };
>
> Using ptr::from_mut here seesm excessive IMO. I think that function
> makes sense when it replaces an explicit `as` cast, but now when it can
> be done by a coercion. This is perfectly readable:
>
> let ret = unsafe { bindings::kstrtobool(string.as_char_ptr(), &mut result) };
>
> Or if you insist, you could directly create a raw pointer:
>
> let ret = unsafe { bindings::kstrtobool(string.as_char_ptr(), &raw mut result) };
Oh, I'll do the implicit coercion then.
I was using `&mut result as *mut bool` but clippy told me to do the `from_mut`
instead.
Best regards,
Andreas Hindborg
Powered by blists - more mailing lists