Re: [PATCH v5 05/18] rust: str: introduce `kstrtobool` function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Alice Ryhl" <aliceryhl@xxxxxxxxxx> 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






[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux