mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Shuai Liu <847807867@qq.com>
To: Muchamad Coirul Anwar <muchamadcoirulanwar@gmail.com>
Cc: Shuai Liu <847807867@qq.com>,
	Igor Korotin <igor.korotin@linux.dev>,
	Danilo Krummrich <dakr@kernel.org>,
	Jonathan Cameron <jic23@kernel.org>,
	Miguel Ojeda <ojeda@kernel.org>, Gary Guo <gary@garyguo.net>,
	Alice Ryhl <aliceryhl@google.com>,
	Daniel Almeida <daniel.almeida@collabora.com>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Mark Brown <broonie@kernel.org>,
	Brandon StJohn <branstj@gmail.com>,
	linux-iio@vger.kernel.org, linux-i2c@vger.kernel.org,
	rust-for-linux@vger.kernel.org, driver-core@lists.linux.dev,
	linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH v6 0/4] iio: position: add Rust driver for ams AS5600
Date: Tue,  3 Nov 2026 17:53:22 +0800	[thread overview]
Message-ID: <tencent_173B7731E90B9624F9F82613DC3031B70907@qq.com> (raw)
In-Reply-To: <20261016154819.17936-1-muchamadcoirulanwar@gmail.com>

Hi Coirul,

Thanks for the series. I read through v6, including Igor's registration
rework proposal in this thread. The comments below do not overlap with
that rework and should carry over to v7 unchanged, as far as I can tell.

1. clippy warnings

`make LLVM=1 CLIPPY=1` reports four warnings on this series, which the
Rust CI gates on. Three are `clippy::ptr_as_ptr` in the IIO abstraction
and one is `clippy::useless_conversion` in the driver:

    --- a/rust/kernel/iio.rs
    +++ b/rust/kernel/iio.rs
    @@ -202,1 +202,1 @@
    -    let priv_ptr = unsafe { (*indio_dev).priv_ as *mut T };
    +    let priv_ptr = unsafe { (*indio_dev).priv_.cast::<T>() };

    (the same pattern at lines 334 and 397; line 334 is already inside
    an unsafe block and just needs `.cast::<T>()`)

    --- a/drivers/iio/position/as5600.rs
    +++ b/drivers/iio/position/as5600.rs
    @@ -133,1 +133,1 @@
    -                Ok(IioVal::Int(angle as i32))
    +                Ok(IioVal::Int(i32::from(angle)))

2. ignored doctest in the SMBus word helper

The example on `smbus_read_word_swapped()` (rust/kernel/i2c.rs:841) is
marked "ignore" and references driver-specific facts (the AS5600).
Ignored examples are not compiled or run by rusttest, so the helper
currently ships with no tested usage. A generic, compilable example
works here:

    --- a/rust/kernel/i2c.rs
    +++ b/rust/kernel/i2c.rs
    @@ -841,8 +841,15 @@
     /// ```
    -/// // AS5600 stores the 12-bit raw angle at command byte 0x0C with its
    -/// // high byte first, so the SMBus (low byte first) word result must
    -/// // be swapped.
    -/// let raw = client.smbus_read_word_swapped(0x0C)?;
    -/// # Ok::<(), Error>(())
    +/// use kernel::{i2c::I2cClient, prelude::*};
    +///
    +/// fn read_hi_first_register(client: &I2cClient<kernel::device::Bound>) -> Result<u16> {
    +///     // A device whose 16-bit register selected by command byte 0x0C
    +///     // transmits the high byte first needs the SMBus (low byte first)
    +///     // word swapped.
    +///     client.smbus_read_word_swapped(0x0C)
    +/// }
     /// ```

3. repeated unsafe blocks in the SMBus access helpers

Patch 2 implements the `FallibleIoCapable` impls for `u8`/`u16` with
five near-identical unsafe blocks wrapping `bindings::i2c_smbus_*`
calls plus error conversion. Extracting four small safe helpers would
put the safety argument in one place and turn each call site into a
one-liner:

    fn smbus_read_byte(client: &I2cClient<device::Bound>, reg: u8)
        -> Result<u8>;
    fn smbus_write_byte(client: &I2cClient<device::Bound>, reg: u8, value: u8)
        -> Result;
    fn smbus_read_word_data(client: &I2cClient<device::Bound>, reg: u8)
        -> Result<u16>;
    fn smbus_write_word_data(client: &I2cClient<device::Bound>, reg: u8, value: u16)
        -> Result;

For example, `io_try_write` for `u8` then reduces to
`smbus_write_byte(client, reg, value)`. Happy to send the full diff if
that is useful as a starting point.

With 1 and 2 applied (and 3 sketched on top), `make LLVM=1 CLIPPY=1
drivers/iio/position/as5600.o` builds with no warnings and the rusttest
doctests pass.

Thanks,
Shuai Liu


  parent reply	other threads:[~2026-11-03  9:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-16 15:48 Muchamad Coirul Anwar
2026-10-16 15:48 ` [RFC PATCH v6 1/4] rust: io: add FallibleIoCapable Muchamad Coirul Anwar
2026-10-16 15:48 ` [RFC PATCH v6 2/4] i2c: rust: implement SMBus access via IoBackend Muchamad Coirul Anwar
2026-10-16 15:48 ` [RFC PATCH v6 3/4] rust: add minimal IIO subsystem abstractions Muchamad Coirul Anwar
2026-10-16 15:48 ` [RFC PATCH v6 4/4] iio: position: add Rust driver for ams AS5600 Muchamad Coirul Anwar
2026-10-21 16:59 ` [RFC PATCH v6 0/4] " Igor Korotin
2026-10-22 16:05   ` Muchamad Coirul Anwar
2026-10-24 17:39     ` Igor Korotin
2026-10-27 16:01       ` Muchamad Coirul Anwar
2026-11-03  2:59         ` Muchamad Coirul Anwar
2026-11-03  9:53 ` Shuai Liu [this message]
2026-11-06 15:45   ` Muchamad Coirul Anwar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tencent_173B7731E90B9624F9F82613DC3031B70907@qq.com \
    --to=847807867@qq.com \
    --cc=aliceryhl@google.com \
    --cc=branstj@gmail.com \
    --cc=broonie@kernel.org \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=driver-core@lists.linux.dev \
    --cc=gary@garyguo.net \
    --cc=igor.korotin@linux.dev \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=muchamadcoirulanwar@gmail.com \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®