From: Jonathan Cameron <jic23@kernel.org>
To: Muchamad Coirul Anwar <muchamadcoirulanwar@gmail.com>
Cc: lars@metafoo.de, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org,
rust-for-linux@vger.kernel.org, andi.shyti@kernel.org,
wsa+renesas@sang-engineering.com, ojeda@kernel.org,
dakr@kernel.org, igor.korotin@linux.dev, branstj@gmail.com,
brucer42@gmail.com
Subject: Re: [RFC PATCH v5 2/3] rust: add minimal IIO subsystem abstractions
Date: Tue, 1 Sep 2026 02:14:20 +0100 [thread overview]
Message-ID: <20260901021420.144a64d3@jic23-huawei> (raw)
In-Reply-To: <CAO26r3RLnX4HXrKDF6akmG722Q2CvDU-uJ40Yfuu_wwJdGgA9g@mail.gmail.com>
On Fri, 28 Aug 2026 13:53:11 +0700
Muchamad Coirul Anwar <muchamadcoirulanwar@gmail.com> wrote:
> Hi Jonathan,
>
> On Mon, 24 Aug 2026 at 07:07, Jonathan Cameron <jic23@kernel.org> wrote:
> > This looks fine to me subject to a few little things - see inline.
> >
> > However I didn't take the time to decode every line of rust today so there were bits
> > I simply didn't understand yet. So for this to be able to move forward I'm going
> > to need reviews from rust experts!
>
> Thanks for the review. I'll add an explicit review request to Danilo
> and Igor in the v6 cover
> letter.
>
> Brandon Saint-John has been CC'd since v2 and reviewed the series at
> v3. If he has time to look at it again, a Reviewed-by from him on the
> Rust abstractions would be welcome.
Sounds good.
> > > +
> > > +/// C-compatible trampoline for the `iio_info.read_raw` callback.
> > > +///
> > > +/// # Safety
> > > +///
> > > +/// This function is only called by the IIO core via the `read_raw` function
> > > +/// pointer in `iio_info`. The IIO core guarantees:
> > > +/// - `indio_dev` is a valid `iio_dev` allocated by `iio_device_alloc`.
> > > +/// - `chan` points to a valid channel spec from the device's channel array.
> > > +/// - `val` is a valid non-null pointer to a writable `int`.
> > > +/// - `val2` is a valid non-null pointer to a writable `int`. The IIO core
> > > +/// always passes stack-allocated storage for both, regardless of whether
> > > +/// the driver uses `val2` (e.g. `IIO_VAL_INT` only writes `val`; `val2`
> >
> > That val2 is always a valid pointer smells a bit like the c interface leaking
> > into the rust. I'm not necessarily against that being a constraint we take
> > on but I'm not sure how we document that. Probably add something to the C docs.
> > Any C driver relying on this today is probably buggy for other reasons.
>
> As you suggested, I'll add a note to the C-side iio_info.read_raw
> documentation in include/linux/iio/iio.h. The IIO core always passes
> stack-allocated storage for both val and val2 regardless of which
> IIO_VAL_* type the driver returns, so the assumption holds, it just
> isn't written down anywhere. I'll also note it in the SAFETY block of
> read_raw_callback.
Perfect. Thanks. There are a lot of little things like this that we
don't document well on the C side of things. Big advantage of your
work is it'll help us clean some of that up.
>
>
> > > + Ok(IioVal::Fractional(v, v2)) => {
> > > + // SAFETY: both `val` and `val2` are valid per the Safety contract.
> > > + unsafe {
> > > + *val = v;
> > > + *val2 = v2.get();
> >
> > Why get in some places and not others? May well be a gap in my really limited
> > rust knowledge.
>
> This came up in v3 and I answered it then but forgot to add the comment
> as I said I would. IioVal::Fractional holds a NonZeroI32 denominator to
> prevent division-by-zero in iio_format_value(). NonZeroI32 is a newtype
> wrapper over i32, so .get() is needed to extract the inner i32. The
> other variants hold plain i32 and don't need it. I'll add an inline
> comment in v6.
Ah. This is my lack of rust knowledge (and forgetfulness). I'd avoid
putting too many comments in for the benefit of folk like me who are
still failing to find the time to learn rust :(
Jonathan
next prev parent reply other threads:[~2026-09-01 1:14 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-22 6:26 [RFC PATCH v5 0/3] iio: position: add Rust driver for ams AS5600 Muchamad Coirul Anwar
2026-08-22 6:26 ` [RFC PATCH v5 1/3] i2c: rust: implement SMBus access via IoBackend and FallibleIoCapable Muchamad Coirul Anwar
2026-08-23 23:41 ` Jonathan Cameron
2026-08-28 6:10 ` Muchamad Coirul Anwar
2026-09-01 1:10 ` Jonathan Cameron
2026-08-22 6:26 ` [RFC PATCH v5 2/3] rust: add minimal IIO subsystem abstractions Muchamad Coirul Anwar
2026-08-24 0:07 ` Jonathan Cameron
2026-08-28 6:53 ` Muchamad Coirul Anwar
2026-09-01 1:14 ` Jonathan Cameron [this message]
2026-08-22 6:26 ` [RFC PATCH v5 3/3] iio: position: add Rust driver for ams AS5600 Muchamad Coirul Anwar
2026-08-24 0:17 ` Jonathan Cameron
2026-08-28 7:01 ` 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=20260901021420.144a64d3@jic23-huawei \
--to=jic23@kernel.org \
--cc=andi.shyti@kernel.org \
--cc=branstj@gmail.com \
--cc=brucer42@gmail.com \
--cc=dakr@kernel.org \
--cc=igor.korotin@linux.dev \
--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 \
--cc=wsa+renesas@sang-engineering.com \
/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