public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Igor Korotin <igor.korotin@linux.dev>
To: Muchamad Coirul Anwar <muchamadcoirulanwar@gmail.com>,
	jic23@kernel.org, linux-iio@vger.kernel.org,
	rust-for-linux@vger.kernel.org, devicetree@vger.kernel.org
Cc: branstj@gmail.com, lars@metafoo.de, ojeda@kernel.org,
	robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org,
	igor.korotin.linux@gmail.com, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH v2 1/4] i2c: rust: add smbus_read_byte_data and smbus_read_word_data
Date: Mon, 4 May 2026 11:29:05 +0100	[thread overview]
Message-ID: <5f126a59-9f03-44e3-b4cd-27f70bd9840b@linux.dev> (raw)
In-Reply-To: <20260429132234.30514-2-muchamadcoirulanwar@gmail.com>

Hello Muchamad

On 4/29/2026 2:22 PM, Muchamad Coirul Anwar wrote:
> Signed-off-by: Muchamad Coirul Anwar <muchamadcoirulanwar@gmail.com>
> ---
>   rust/kernel/i2c.rs | 24 ++++++++++++++++++++++++
>   1 file changed, 24 insertions(+)
> 
> diff --git a/rust/kernel/i2c.rs b/rust/kernel/i2c.rs
> index 7b908f0c5a58..6eaea1158fda 100644
> --- a/rust/kernel/i2c.rs
> +++ b/rust/kernel/i2c.rs
> @@ -477,6 +477,30 @@ impl<Ctx: device::DeviceContext> I2cClient<Ctx> {
>       fn as_raw(&self) -> *mut bindings::i2c_client {
>           self.0.get()
>       }
> +
> +    /// Reads a single byte from a register via SMBus.
> +    pub fn smbus_read_byte_data(&self, reg: u8) -> Result<u8> {
> +        // SAFETY: `self.as_raw()` is a valid pointer to a `struct i2c_client`
> +        // by the type invariant of `I2cClient`.
> +        let ret = unsafe { bindings::i2c_smbus_read_byte_data(self.as_raw(), reg) };
> +        if ret < 0 {
> +            Err(Error::from_errno(ret))
> +        } else {
> +            Ok(ret as u8)
> +        }
> +    }
> +
> +    /// Reads a 16-bit word from a register via SMBus.
> +    pub fn smbus_read_word_data(&self, reg: u8) -> Result<u16> {
> +        // SAFETY: `self.as_raw()` is a valid pointer to a `struct i2c_client`
> +        // by the type invariant of `I2cClient`.
> +        let ret = unsafe { bindings::i2c_smbus_read_word_data(self.as_raw(), reg) };
> +        if ret < 0 {
> +            Err(Error::from_errno(ret))
> +        } else {
> +            Ok(ret as u16)
> +        }
> +    }
>   }
>   
>   // SAFETY: `I2cClient` is a transparent wrapper of `struct i2c_client`.

Thanks for the patch. However, we've previously agreed [1] that 
I2cClient should implement the IO trait [2] rather than adding 
standalone methods like these. This patch would need to be reworked in 
that direction.

If you'd like to take that on, feel free to submit a patch series 
implementing the IO trait instead.

Cheers
Igor

[1] 
https://lore.kernel.org/rust-for-linux/20260131-i2c-adapter-v1-4-5a436e34cd1a@gmail.com/

[2] 
https://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git/commit/?h=driver-core-testing&id=121d87b28e1d9061d3aaa156c43a627d3cb5e620

  reply	other threads:[~2026-05-04 10:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-29 13:22 [RFC PATCH v2 0/4] iio: position: add Rust driver for ams AS5600 Muchamad Coirul Anwar
2026-04-29 13:22 ` [RFC PATCH v2 1/4] i2c: rust: add smbus_read_byte_data and smbus_read_word_data Muchamad Coirul Anwar
2026-05-04 10:29   ` Igor Korotin [this message]
2026-04-29 13:22 ` [RFC PATCH v2 2/4] rust: add minimal IIO subsystem abstractions Muchamad Coirul Anwar
2026-04-29 13:22 ` [RFC PATCH v2 3/4] dt-bindings: iio: position: add ams,as5600 Muchamad Coirul Anwar
2026-04-29 13:46   ` Krzysztof Kozlowski
2026-04-29 13:22 ` [RFC PATCH v2 4/4] iio: position: add Rust driver for ams AS5600 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=5f126a59-9f03-44e3-b4cd-27f70bd9840b@linux.dev \
    --to=igor.korotin@linux.dev \
    --cc=branstj@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=igor.korotin.linux@gmail.com \
    --cc=jic23@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=muchamadcoirulanwar@gmail.com \
    --cc=ojeda@kernel.org \
    --cc=robh@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