From: Meagan Lloyd <meaganlloyd@linux.microsoft.com>
To: Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: Meagan Lloyd <meaganlloyd@linux.microsoft.com>,
linux-i3c@lists.infradead.org, alexandre.belloni@bootlin.com,
vitor.soares@toradex.com, samagazaryan@google.com,
gregkh@linuxfoundation.org, arnd@arndb.de,
boris.brezillon@collabora.com,
oleksandr.shulzhenko.viktorovych@intel.com,
tgopinath@linux.microsoft.com, corbet@lwn.net,
skhan@linuxfoundation.org, linux@roeck-us.net, Frank.Li@nxp.com,
jorge.marques@analog.com, pgaj@cadence.com,
wsa+renesas@sang-engineering.com,
tommaso.merciai.xr@bp.renesas.com, nuno.sa@analog.com,
Michael.Hennerich@analog.com, jic23@kernel.org,
dlechner@baylibre.com, andy@kernel.org, lorenzo@kernel.org,
enelsonmoore@gmail.com, rppt@kernel.org, pratyush@kernel.org,
giovanni.cabiddu@intel.com, gabewhigham@gmail.com,
haren@linux.ibm.com, pasha.tatashin@soleen.com,
jirislaby@kernel.org, adrian.ho.yin.ng@altera.com,
ustc.gu@gmail.com, jszhang@kernel.org, adrian.hunter@intel.com,
akhilrajeev@nvidia.com, tze.yee.ng@altera.com,
manikanta.guntupalli@amd.com, shubhrajyoti.datta@amd.com,
jarkko.nikula@linux.intel.com, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org,
linux@analog.com, linux-iio@vger.kernel.org
Subject: Re: [PATCH 3/3] i3c: add i3cdev character device module for user-space access
Date: Wed, 16 Sep 2026 15:57:10 -0700 [thread overview]
Message-ID: <20260916-454d66ca84cc91479b195aa5@linux.microsoft.com> (raw)
In-Reply-To: <aqVUyYkpKT8iX4Jz@ashevche-desk.local>
On Sat, Sep 12, 2026 at 04:34:01PM +0300, Andy Shevchenko wrote:
> On Fri, Sep 11, 2026 at 02:09:35PM -0700, Meagan Lloyd wrote:
> > The i3cdev driver is a character device driver that allows user-space
> > to control and interact with I3C devices.
>
> > Currently, it has the ability to perform Single Data Rate (SDR)
> > transfers - basic reads/writes.
> >
> > With the addition of sysfs driver_override, there is now a
> > straightforward and direct way to match the i3cdev driver to any i3c
> > device without stepping on the toes of more specialized drivers that are
> > loaded automatically.
>
> Is it safe? Why on the earth do we need this? The commit message has not enough
> information.
>
I can't see a reason that it'd be unsafe. To give additional confidence,
it's already in-use in many bus_types:
drivers/platform/wmi/core.c: .driver_override = true,
drivers/hv/vmbus_drv.c: .driver_override = true,
drivers/base/platform.c: .driver_override = true,
drivers/cdx/cdx.c: .driver_override = true,
drivers/s390/cio/css.c: .driver_override = true,
drivers/vdpa/vdpa.c: .driver_override = true,
drivers/bus/fsl-mc/fsl-mc-bus.c: .driver_override = true,
drivers/pci/pci-driver.c: .driver_override = true,
drivers/rpmsg/rpmsg_core.c: .driver_override = true,
drivers/amba/bus.c: .driver_override = true,
To answer why we need it:
If we want to write i3cdev as a standard device driver, it can't
actually match anything by default. This is because, some devices on the
system may need specific drivers and i3cdev is generic and should
technically match every device.
Since the driver_override is default NULL and is set via sysfs, this
allows any specific drivers on boot to be loaded up and would allow
explicit control on what device i3cdev gets bound to.
This was my rational. I will refine the commit message with more details.
> > This is accomplished by the i3cdev driver not having any entries in
> > the i3c_device_id table. After boot, simply set the driver_override
> > to "i3cdev" and bind the device manually via the sysfs bind knob.
> > This can also be automated with udev rules as well.
> >
> > The character device interface will be exposed at: /dev/bus/i3c/<bus
> > id>-<Provisional ID>
>
> ...
>
> > + struct i3c_xfer xfer = { + .rnw = I3C_WRITE
>
> In such cases always leave a trailing comma. It will reduce possible
> churn in the future.
>
Good point, I'll fix that.
> > + };
>
> ...
>
> > + return !ret ? len : ret;
>
> My gosh, wouldn't Elvis just work naturally?
>
> return ret ?: len;
>
You're right, that is much nicer!
> ...
>
> > + for (int i = 0; i < metadata->nxfers; i++) {
>
> Why is 'i' signed?
>
Mostly for readability and to make sure the line length on loop headers
is kept below 80 chars. As a precaution, to make sure that 'i' can
represent any metadata->nxfers value without overflow during loops, I
check that metadata->nxfers is less than/equal to INT_MAX in
get_metadata().
> > + ret = copy_struct_from_user(k_uxfer, +
> > sizeof(*k_uxfers), + uxfer, + metadata->xfer_size); + if (ret) +
> > goto out_free_k_uxfers; + + /* Enforce that padding must be
> > zero */ + if (memchr_inv(k_uxfer->pad, 0,
> > sizeof(k_uxfer->pad))) { + ret = -EINVAL; + goto
> > out_free_k_uxfers; + } + + uxfer +=
> > metadata->xfer_size; /* u8 pointer so use xfer_size */ + k_uxfer++;
> > /* struct i3cdev_xfer pointer */ + }
>
> ...
>
> > + if (!ret) + total_bytes +=
> > i3c_xfers[i].len; + else + return ret;
>
> Yeah, you really need to reconsider patterns you use in the code. Here
> 'else' is redundant. Homework to understand how (#easy).
>
Thanks for pointing this out. It would read better if I removed the else
block, opting to bail out early if ret is non-zero.
> ...
>
> > +/** + * print_i3c_err() - Prints the I3C error encountered during
> > the prior + * call to the core's transfer function. + * @i3cdev:
> > i3cdev_data object + * @metadata: Kernel's copy of i3cdev_xfers
> > (ioctl I3CDEV_XFER input) + * @i3c_xfers: i3c_xfer array that was
> > sent to the I3C core
>
> > + * Returns: void
>
> Huh?! Where is this coming from?
>
In i3cdev_ioctl_do_xfers, if i3c_device_do_xfers failed, I wanted to
print out the first I3C controller error encountered. The controller
drivers can set this in the i3c_xfer.err field. Hence this function.
It's to aid debugging and provide useful error information.
I can certainly refine the wording on the print_i3c_err documentation
header to make this more clear.
> > + */
>
> ...
>
> Please, rely less on AI and more on the common sense and
> proof-reading.
>
> -- With Best Regards, Andy Shevchenko
I think I gave you the wrong impression. The new contributions in this
series were written and developed by me. I used AI for quality assurance
and cross-referencing. Since I incorporated some AI-flagged suggestions,
I tried to acknowledge that with the Assisted-by tag.
Thank you,
Meagan
next prev parent reply other threads:[~2026-09-16 22:58 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-11 21:09 [PATCH 0/3] I3C character device driver using driver_override Meagan Lloyd
2026-09-11 21:09 ` [PATCH 1/3] i3c: master: enable driver_override for I3C Meagan Lloyd
2026-09-11 21:36 ` Guenter Roeck
2026-09-16 18:29 ` Meagan Lloyd
2026-09-12 13:22 ` Andy Shevchenko
2026-09-16 18:39 ` Meagan Lloyd
2026-09-13 0:24 ` Jonathan Cameron
2026-09-16 18:53 ` Meagan Lloyd
2026-09-11 21:09 ` [PATCH 2/3] i3c: set i3c_xfer.actual_len in controller drivers Meagan Lloyd
2026-09-13 0:26 ` Jonathan Cameron
2026-09-16 19:11 ` Meagan Lloyd
2026-09-11 21:09 ` [PATCH 3/3] i3c: add i3cdev character device module for user-space access Meagan Lloyd
2026-09-11 23:29 ` Randy Dunlap
2026-09-16 18:37 ` Meagan Lloyd
2026-09-12 13:34 ` Andy Shevchenko
2026-09-16 22:57 ` Meagan Lloyd [this message]
2026-09-17 5:49 ` Andy Shevchenko
2026-09-12 13:26 ` [PATCH 0/3] I3C character device driver using driver_override Andy Shevchenko
2026-09-16 19:28 ` Meagan Lloyd
2026-09-17 6:23 ` Andy Shevchenko
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=20260916-454d66ca84cc91479b195aa5@linux.microsoft.com \
--to=meaganlloyd@linux.microsoft.com \
--cc=Frank.Li@nxp.com \
--cc=Michael.Hennerich@analog.com \
--cc=adrian.ho.yin.ng@altera.com \
--cc=adrian.hunter@intel.com \
--cc=akhilrajeev@nvidia.com \
--cc=alexandre.belloni@bootlin.com \
--cc=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=arnd@arndb.de \
--cc=boris.brezillon@collabora.com \
--cc=corbet@lwn.net \
--cc=dlechner@baylibre.com \
--cc=enelsonmoore@gmail.com \
--cc=gabewhigham@gmail.com \
--cc=giovanni.cabiddu@intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=haren@linux.ibm.com \
--cc=jarkko.nikula@linux.intel.com \
--cc=jic23@kernel.org \
--cc=jirislaby@kernel.org \
--cc=jorge.marques@analog.com \
--cc=jszhang@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-i3c@lists.infradead.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@analog.com \
--cc=linux@roeck-us.net \
--cc=lorenzo@kernel.org \
--cc=manikanta.guntupalli@amd.com \
--cc=nuno.sa@analog.com \
--cc=oleksandr.shulzhenko.viktorovych@intel.com \
--cc=pasha.tatashin@soleen.com \
--cc=pgaj@cadence.com \
--cc=pratyush@kernel.org \
--cc=rppt@kernel.org \
--cc=samagazaryan@google.com \
--cc=shubhrajyoti.datta@amd.com \
--cc=skhan@linuxfoundation.org \
--cc=tgopinath@linux.microsoft.com \
--cc=tommaso.merciai.xr@bp.renesas.com \
--cc=tze.yee.ng@altera.com \
--cc=ustc.gu@gmail.com \
--cc=vitor.soares@toradex.com \
--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
all inboxes | Powered by JetHome®