[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87sei3795e.fsf@kernel.org>
Date: Thu, 07 Aug 2025 11:50:37 +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>, linux-block@...r.kernel.org,
rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v3 12/16] rnull: enable configuration via `configfs`
"Alice Ryhl" <aliceryhl@...gle.com> writes:
> On Fri, Jul 11, 2025 at 01:43:13PM +0200, Andreas Hindborg wrote:
..
>> +#[vtable]
>> +impl configfs::AttributeOperations<0> for DeviceConfig {
>> + type Data = DeviceConfig;
>> +
>> + fn show(this: &DeviceConfig, page: &mut [u8; PAGE_SIZE]) -> Result<usize> {
>> + let mut writer = kernel::str::Formatter::new(page);
>> +
>> + if this.data.lock().powered {
>> + writer.write_fmt(fmt!("1\n"))?;
>> + } else {
>> + writer.write_fmt(fmt!("0\n"))?;
>
> I think these can just be
> writer.write_str("1\n")?;
Cool 👍
>
>> + }
>> +
>> + Ok(writer.bytes_written())
>> + }
>> +
>> + fn store(this: &DeviceConfig, page: &[u8]) -> Result {
>> + let power_op: bool = core::str::from_utf8(page)?
>> + .trim()
>> + .parse::<u8>()
>> + .map_err(|_| kernel::error::code::EINVAL)?
>> + != 0;
>
> So if I write 27, that's treated as true, but if I write 300, that's an
> EINVAL?
Yea. Let's do this instead:
let power_op_str = core::str::from_utf8(page)?.trim();
let power_op = match power_op_str {
"0" => Ok(false),
"1" => Ok(true),
_ => Err(EINVAL),
}?;
It is closer to `kstrtobool`.
Best regards,
Andreas Hindborg
Powered by blists - more mailing lists