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