Skip to contentSkip to conversation

I3C character device driver using driver_override

PATCH In review Meagan Lloyd 7 participants 27 messages Sep 11 – Sep 25

Subsystems (11)
lore
Share & tools
lore
#0 lore raw

cover I3C character device driver using driver_override

This is a rework and revival option for Vitor Soares' I3C character device driver patch series from 2020 [1] that I've been exploring for a few months. Recently there was a revival posted to the list [2], so I wanted to share this design option as well.

In [1] and [2], the i3cdev driver automatically attaches and detaches depending whether another driver has attached/not. In [1], Boris was suggesting we explore a more straightforward and traditional binding method aligning with the Linux driver model. At the time, there wasn't a way to auto-bind while keeping manual binding possible as they shared the same match() hook. Now with the new driver_override feature, the auto-binding of i3cdev on boot can be avoided if the i3cdev driver has an empty match ID table. After boot, where specialized drivers would have already bound, user-space can explicitly opt-in by setting the driver_override sysfs file with 'i3cdev' and manually binding via sysfs (or by simply loading the driver if it's loadable). This can also be easily automated with udev rules that run whenever the I3C core exposes a new device.

One downside of the automatic attach/de-attach is that if a different driver is loaded later, the first driver could have altered something on the device, breaking any assumptions of the subsequent driver.

My series builds on [1] through:
0. Addressing code review feedback in [1] from Greg, Boris, and Randy.
1. Using actual_len for accurate read response reporting. The kernel will report actual_len received from the core to user-space via the uapi i3cdev_xfer struct.
2. Placing limits on the number of transfers and bytes in requests to prevent unlimited-sized transfers or kernel memory allocation
3. Checking inputs and descriptive return codes as guard-rails for user-space and to ease use of the i3cdev driver
4. Checking on MWL to ensure that we respect device limits
5. Proper lifetime management of i3cdev_data and underlying device
6. Addressing dangling fops in the event we have an open file descriptor when a device gets unbound.
7. Fast-path locking to ensure transfers complete before a device is unbound.
8. Allowing only one file descriptor per I3C device to avoid bugs around multiple processes interacting with the device and altering the device underneath the other. For example, without this, one process could change the device's page or address pointer register underneath the other process.
9. copy_struct_from_user to ensure struct i3cdev_xfer could be extended in a compatible way. This is to be forward-looking towards potential HDR mode expansion and code reuse.
10. Reserving the IOCTL number formally
11. Updating the Documentation to be a syntax correct example program template.
12. Preserving /dev/bus/i3c/<bus id>-<Provisional ID> naming while allowing sysfs path to be neatly named i3cdev-<minor>. This avoids repeated <bus id>-<Provisional ID> in the sysfs paths which can be confusing/circular-looking.

    e.g. /sys/bus/i3c/devices/0-deadbeef001/i3cdev/0-deadbeef001 ->
         /sys/bus/i3c/devices/0-deadbeef001/i3cdev/i3cdev-0

13. Updating all naming references related to i3c_priv_xfer to align with new i3c_xfer struct
14. Updating the MAINTAINERS file for the new pieces of code

Note that i3c-tools [3] or a fork of it will need small updates:
1. Update include/uapi/linux/i3c/i3cdev.h to match updated uapi structs
2. In i3ctransfer.c, use actual_len for reads

I've added MODULE_VERSION("1.0.0") in the i3cdev driver, so i3c-tools could use that to determine whether to use the old out-of-tree uapi or this one.

[1] https://lore.kernel.org/linux-i3c/[email protected]/
[2] https://lore.kernel.org/linux-i3c/ap_1-gFF7S821xJT@ninjato/T/#m9107c1785a4a16b1b3cb84c3269d17fac35819c8
[3] https://github.com/vitor-soares-snps/i3c-tools

Meagan Lloyd (3):
i3c: master: enable driver_override for I3C
i3c: set i3c_xfer.actual_len in controller drivers
i3c: add i3cdev character device module for user-space access

 Documentation/userspace-api/i3c/i3cdev.rst    | 152 ++++
 .../userspace-api/ioctl/ioctl-number.rst      |   1 +
 MAINTAINERS                                   |   7 +
 drivers/hwmon/lm75.c                          |   7 +-
 drivers/hwmon/tmp108.c                        |   2 +
 drivers/i3c/Kconfig                           |  12 +
 drivers/i3c/Makefile                          |   1 +
 drivers/i3c/i3cdev.c                          | 730 ++++++++++++++++++
 drivers/i3c/master.c                          |   6 +
 drivers/i3c/master/adi-i3c-master.c           |   5 +-
 drivers/i3c/master/dw-i3c-master.c            |   4 +-
 drivers/i3c/master/i3c-master-cdns.c          |   5 +-
 drivers/i3c/master/mipi-i3c-hci/core.c        |   5 +-
 drivers/i3c/master/renesas-i3c.c              |   3 +
 drivers/iio/adc/ad4062.c                      |  10 +-
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c   |   3 +
 include/uapi/linux/i3c/i3cdev.h               |  70 ++
 17 files changed, 1016 insertions(+), 7 deletions(-)
 create mode 100644 Documentation/userspace-api/i3c/i3cdev.rst
 create mode 100644 drivers/i3c/i3cdev.c
 create mode 100644 include/uapi/linux/i3c/i3cdev.h

base-commit: cab40cfc9e116acd4d60f95b4b1264cab78f3803

Signature · 1 line
2.49.0
#1 lore raw

PATCH 1/3 i3c: master: enable driver_override for I3C

Opt-in to driver_override sysfs functionality for I3C subsystem.

Update some I3C drivers that are assuming that if their .probe is invoked that the bus match function already checked the ID table. Go ahead and verify in .probe that i3c_device_match_id() returns a valid match before using the i3c_device_id pointer.

Assisted-by Claude:claude-opus-4.8 copilot
---
 drivers/hwmon/lm75.c                        |  7 ++++++-
 drivers/hwmon/tmp108.c                      |  2 ++
 drivers/i3c/master.c                        |  6 ++++++
 drivers/iio/adc/ad4062.c                    | 10 ++++++++--
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c |  3 +++
 5 files changed, 25 insertions(+), 3 deletions(-)
drivers/hwmon/lm75.c +6 -1
index 104149a03bad..0d3c843d1823 100644
@@ -888,6 +888,7 @@ MODULE_DEVICE_TABLE(i3c, lm75_i3c_ids);
 static int lm75_i3c_probe(struct i3c_device *i3cdev)
 {
 	struct device *dev = i3cdev_to_dev(i3cdev);
+	const struct i3c_device_id *id;
 	const struct lm75_i3c_device *id_data;
 	struct regmap *regmap;
 
@@ -895,7 +896,11 @@ static int lm75_i3c_probe(struct i3c_device *i3cdev)
 	if (IS_ERR(regmap))
 		return PTR_ERR(regmap);
 
-	id_data = i3c_device_match_id(i3cdev, lm75_i3c_ids)->data;
+	id = i3c_device_match_id(i3cdev, lm75_i3c_ids);
+	if (!id)
+		return -ENODEV;
+
+	id_data = id->data;
 
 	return lm75_generic_probe(dev, id_data->name, id_data->type, 0, regmap);
 }
drivers/hwmon/tmp108.c +2 -0
index 1c4a58855e2d..98076ae8dce8 100644
@@ -581,6 +581,8 @@ static int p3t1085_i3c_probe(struct i3c_device *i3cdev)
 				     "Failed to register i3c regmap\n");
 
 	id = i3c_device_match_id(i3cdev, p3t1085_i3c_ids);
+	if (!id)
+		return -ENODEV;
 
 	return tmp108_common_probe(dev, regmap, "p3t1085_i3c", id->data);
 }
drivers/i3c/master.c +6 -0
index afcd7a21a3e6..42bc9a923d81 100644
@@ -340,10 +340,15 @@ static int i3c_device_match(struct device *dev, const struct device_driver *drv)
 	struct i3c_device *i3cdev;
 	const struct i3c_driver *i3cdrv;
 	u8 static_addr_method = 0;
+	int ret;
 
 	if (dev->type != &i3c_device_type)
 		return 0;
 
+	ret = device_match_driver_override(dev, drv);
+	if (ret >= 0)
+		return ret;
+
 	i3cdev = dev_to_i3cdev(dev);
 	i3cdrv = drv_to_i3cdrv(drv);
 
@@ -890,6 +895,7 @@ const struct bus_type i3c_bus_type = {
 	.probe = i3c_device_probe,
 	.remove = i3c_device_remove,
 	.shutdown = i3c_device_shutdown,
+	.driver_override = true,
 };
 EXPORT_SYMBOL_GPL(i3c_bus_type);
 
drivers/iio/adc/ad4062.c +8 -2
index 8e5984055b15..f28b503d16eb 100644
@@ -1482,14 +1482,20 @@ MODULE_DEVICE_TABLE(i3c, ad4062_id_table);
 
 static int ad4062_probe(struct i3c_device *i3cdev)
 {
-	const struct i3c_device_id *id = i3c_device_match_id(i3cdev, ad4062_id_table);
-	const struct ad4062_chip_info *chip = id->data;
+	const struct i3c_device_id *id;
+	const struct ad4062_chip_info *chip;
 	struct device *dev = &i3cdev->dev;
 	struct iio_dev *indio_dev;
 	struct ad4062_state *st;
 	bool ref_sel;
 	int ret;
 
+	id = i3c_device_match_id(i3cdev, ad4062_id_table);
+	if (!id)
+		return -ENODEV;
+
+	chip = id->data;
+
 	indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
 	if (!indio_dev)
 		return -ENOMEM;
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c +3 -0
index cb5c5d7e1f3d..153a03e06801 100644
@@ -32,6 +32,9 @@ static int st_lsm6dsx_i3c_probe(struct i3c_device *i3cdev)
 	struct device *dev = i3cdev_to_dev(i3cdev);
 	struct regmap *regmap;
 
+	if (!id)
+		return -ENODEV;
+
 	regmap = devm_regmap_init_i3c(i3cdev, &st_lsm6dsx_i3c_regmap_config);
 	if (IS_ERR(regmap)) {
 		dev_err(dev, "Failed to register i3c regmap %ld\n", PTR_ERR(regmap));
Signature · 1 line
2.49.0
#9 lore raw

PATCH 2/3 i3c: set i3c_xfer.actual_len in controller drivers

In reply to Meagan Lloyd

Set i3c_xfer.actual_len for reads across the I3C Controller drivers.

actual_len provides a consistent location for device drivers to know the read response bytes without overriding the len field.

---
 drivers/i3c/master/adi-i3c-master.c    | 5 ++++-
 drivers/i3c/master/dw-i3c-master.c     | 4 +++-
 drivers/i3c/master/i3c-master-cdns.c   | 5 ++++-
 drivers/i3c/master/mipi-i3c-hci/core.c | 5 ++++-
 drivers/i3c/master/renesas-i3c.c       | 3 +++
 5 files changed, 18 insertions(+), 4 deletions(-)
drivers/i3c/master/adi-i3c-master.c +4 -1
index b35386260350..d033bfd4ecc2 100644
@@ -412,8 +412,11 @@ static int adi_i3c_master_i3c_xfers(struct i3c_dev_desc *dev,
 
 	ret = xfer->ret;
 
-	for (i = 0; i < nxfers; i++)
+	for (i = 0; i < nxfers; i++) {
 		xfers[i].err = adi_i3c_cmd_get_err(&xfer->cmds[i]);
+		if (xfers[i].rnw)
+			xfers[i].actual_len = xfer->cmds[i].rx_len;
+	}
 
 	return ret;
 }
drivers/i3c/master/dw-i3c-master.c +3 -1
index 4563d8761ba0..54406e31c870 100644
@@ -1028,8 +1028,10 @@ static int dw_i3c_master_i3c_xfers(struct i3c_dev_desc *dev,
 	for (i = 0; i < i3c_nxfers; i++) {
 		struct dw_i3c_cmd *cmd = &xfer->cmds[i];
 
-		if (i3c_xfers[i].rnw)
+		if (i3c_xfers[i].rnw) {
 			i3c_xfers[i].len = cmd->rx_len;
+			i3c_xfers[i].actual_len = cmd->rx_len;
+		}
 	}
 
 	ret = xfer->ret;
drivers/i3c/master/i3c-master-cdns.c +4 -1
index 2d98c1ce9b12..331062c10b31 100644
@@ -795,8 +795,11 @@ static int cdns_i3c_master_i3c_xfers(struct i3c_dev_desc *dev,
 
 	ret = cdns_xfer->ret;
 
-	for (i = 0; i < nxfers; i++)
+	for (i = 0; i < nxfers; i++) {
 		xfers[i].err = cdns_i3c_cmd_get_err(&cdns_xfer->cmds[i]);
+		if (xfers[i].rnw)
+			xfers[i].actual_len = cdns_xfer->cmds[i].rx_len;
+	}
 
 	cdns_i3c_master_free_xfer(cdns_xfer);
 
drivers/i3c/master/mipi-i3c-hci/core.c +4 -1
index dadf049bd4b5..29fa68e29484 100644
@@ -508,8 +508,11 @@ static int i3c_hci_i3c_xfers(struct i3c_dev_desc *dev,
 	if (ret)
 		goto out;
 	for (i = 0; i < nxfers; i++) {
-		if (i3c_xfers[i].rnw)
+		if (i3c_xfers[i].rnw) {
 			i3c_xfers[i].len = RESP_DATA_LENGTH(xfer[i].response);
+			i3c_xfers[i].actual_len = RESP_DATA_LENGTH(xfer[i].response);
+		}
+
 		if (RESP_STATUS(xfer[i].response) != RESP_SUCCESS) {
 			ret = -EIO;
 			goto out;
drivers/i3c/master/renesas-i3c.c +3 -0
index 28c0927a0179..a3dcb4cd9b0e 100644
@@ -918,6 +918,9 @@ static int renesas_i3c_i3c_xfers(struct i3c_dev_desc *dev, struct i3c_xfer *i3c_
 		time_left = renesas_i3c_wait_xfer(i3c, xfer);
 		if (!time_left)
 			xfer_failed = true;
+
+		if (i3c_xfers[i].rnw)
+			i3c_xfers[i].actual_len = cmd->rx_count;
 	}
 
 	if (xfer_failed)
Signature · 1 line
2.49.0
#13 lore raw

PATCH 3/3 i3c: add i3cdev character device module for user-space access

In reply to Meagan Lloyd

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.

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>

Assisted-by Claude:claude-opus-4.8 copilot
---
 Documentation/userspace-api/i3c/i3cdev.rst    | 152 ++++
 .../userspace-api/ioctl/ioctl-number.rst      |   1 +
 MAINTAINERS                                   |   7 +
 drivers/i3c/Kconfig                           |  12 +
 drivers/i3c/Makefile                          |   1 +
 drivers/i3c/i3cdev.c                          | 730 ++++++++++++++++++
 include/uapi/linux/i3c/i3cdev.h               |  70 ++
 7 files changed, 973 insertions(+)
 create mode 100644 Documentation/userspace-api/i3c/i3cdev.rst
 create mode 100644 drivers/i3c/i3cdev.c
 create mode 100644 include/uapi/linux/i3c/i3cdev.h
Documentation/userspace-api/i3c/i3cdev.rst new file +152 -0
new file mode 100644
index 000000000000..ad246bf28919
@@ -0,0 +1,152 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+====================
+I3C Device Interface
+====================
+
+This interface allows access to I3C devices from userspace.
+
+As I3C devices adhere to the I3C protocol, simple transfers can be accomplished
+using a generic driver. Currently, this interface supports private Single Data
+Rate (SDR) read and write transfers.
+
+The i3cdev module will not auto-bind to devices. Userspace needs to explicitly
+bind the device to the driver. This is to avoid interfering with the binding of
+specialized drivers.
+
+Once bound, a character device interface will be created at:
+/dev/bus/i3c/<bus id>-<Provisional ID>.
+
+====================
+Usage
+====================
+
+Any discovered I3C devices by the I3C subsystem will have device folders under /sys/bus/i3c/devices/<bus id>-<Provisional ID>.
+To allow binding of a device with i3cdev driver, set the driver_override:
+
+::
+
+    # echo "i3cdev" > /sys/bus/i3c/devices/<bus id>-<Provisional ID>/driver_override
+
+If the i3cdev driver is not yet loaded, load it and it will cause the driver to bind
+to any devices with the override in place.
+
+If the i3cdev driver is already loaded, go ahead and perform a manual bind:
+
+::
+
+    # echo "<bus id>-<Provisional ID>" > /sys/bus/i3c/drivers/i3cdev/bind
+
+Set driver override
+::
+
+    # echo "i3cdev" > /sys/bus/i3c/devices/0-deadbeef001/driver_override
+    # echo "i3cdev" > /sys/bus/i3c/devices/0-deadbeef002/driver_override
+
+Bind the device to the driver
+::
+
+    # echo "0-deadbeef001" > /sys/bus/i3c/drivers/i3cdev/bind
+    # echo "0-deadbeef002" > /sys/bus/i3c/drivers/i3cdev/bind
+
+Observe the resulting character device files under /dev/bus/i3c/
+::
+
+    # ls -ltr /dev/bus/i3c/
+    crw-------    1 root     root      235,   1 Jun 30 17:49 0-deadbeef002
+    crw-------    1 root     root      235,   0 Jun 30 17:49 0-deadbeef001
+
+BASIC CHARACTER DEVICE API
+===============================
+The API supports private Single Data Rate (SDR) read and write transfers.
+Those transaction can be achieved by the following:
+
+``read(file, buffer, sizeof(buffer))``
+  The standard read() operation will work as a simple transaction of private
+  SDR read data followed a stop.
+  Return the number of bytes read on success, and a negative error otherwise.
+
+``write(file, buffer, sizeof(buffer))``
+  The standard write() operation will work as a simple transaction of private
+  SDR write data followed a stop.
+  Return the number of bytes written on success, and a negative error otherwise.
+
+``ioctl(file, I3CDEV_XFER, struct i3cdev_xfers *xfers)``
+  It combines read/write transactions without a stop in between.
+  Return 0 on success, and a negative error otherwise.
+
+C EXAMPLE (PSEUDO CODE)
+=======================
+You need to open (and get a file descriptor) to /dev/bus/i3c/<bus id>-<Provisional ID>,
+do your operations (read, write, ioctl), and then close it.
+
+The following header files should be included in an I3C program::
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <i3c/i3cdev.h>
+#include <stdint.h>
+
+These additionally are used by this example::
+
+#include <stdlib.h>
+#include <assert.h>
+
+To work with an I3C device, one must call open and get a file descriptor::
+
+	int fd;
+
+	fd = open("/dev/bus/i3c/0-deadbeef001", O_RDWR);
+	if (fd < 0)
+		exit(EXIT_FAILURE);
+
+Now that the file is open, we can do some operations::
+
+	int ret;
+
+	/* Write function */
+	uint8_t  buf[] = {0x00, 0xde, 0xad, 0xbe, 0xef};
+	ret = write(fd, buf, 5);
+	if (ret != 5) {
+		/* ERROR HANDLING: I3C transaction failed */
+	}
+
+	/*  Read function */
+	ret = read(fd, buf, 4);
+	if (ret < 0) {
+		/* ERROR HANDLING: I3C transaction failed */
+	} else {
+		/* Iterate over buf[] to get the read data */
+	}
+
+	/* IOCTL function */
+	struct i3cdev_xfer xfers[2] = {0}; /* Must zero out for compatibility */
+	struct i3cdev_xfers xfers_metadata = { .nxfers = 2,
+					       .xfers = (uintptr_t) xfers,
+					       .xfer_size = sizeof(struct i3cdev_xfer)
+					     };
+
+	uint8_t tx_buf[] = {0x00, 0xde, 0xad, 0xbe, 0xef};
+	uint8_t rx_buf[10];
+
+	xfers[0].data = (uintptr_t) tx_buf;
+	xfers[0].len = 5;
+	xfers[0].rnw = 0;
+	xfers[1].data = (uintptr_t) rx_buf;
+	xfers[1].len = 10;
+	xfers[1].rnw = 1;
+
+	ret = ioctl(fd, I3CDEV_XFER, (uintptr_t) &xfers_metadata);
+	if (ret < 0) {
+		/* ERROR HANDLING: I3C transaction failed */
+	} else {
+		/* For reads, optionally verify that the response matches expectations */
+		assert(xfers[1].len == xfers[1].actual_len);
+
+		/* For reads, iterate through response data using xfers[i].actual_len */
+	}
+
+The device can be closed when the open file descriptor is no longer required::
+
+	close(fd);
\ No newline at end of file
Documentation/userspace-api/ioctl/ioctl-number.rst +1 -0
index 3f0ef1e27eb0..b40f3b3f63a6 100644
@@ -81,6 +81,7 @@ Code  Seq#    Include File                                             Comments
 0x03  all    linux/hdreg.h
 0x04  D2-DC  linux/umsdos_fs.h                                         Dead since 2.6.11, but don't reuse these.
 0x06  all    linux/lp.h
+0x07  00-9E  linux/i3c/i3cdev.h                                        i3cdev driver for I3C subystem
 0x07  9F-D0  linux/vmw_vmci_defs.h, uapi/linux/vm_sockets.h
 0x09  all    linux/raid/md_u.h
 0x10  00-0F  drivers/char/s390/vmcp.h
MAINTAINERS +7 -0
index 81a9a02c919d..5c75a3585d23 100644
@@ -12350,6 +12350,13 @@ S:	Orphan
 F:	Documentation/devicetree/bindings/i3c/snps,dw-i3c-master.yaml
 F:	drivers/i3c/master/dw*
 
+I3C CHARACTER DEVICE DRIVER
+M:	Meagan Lloyd <[email protected]>
+S:	Supported
+F:	Documentation/userspace-api/i3c/i3cdev.rst
+F:	drivers/i3c/i3cdev.c
+F:	include/uapi/linux/i3c/i3cdev.h
+
 I3C SUBSYSTEM
 M:	Alexandre Belloni <[email protected]>
 R:	Frank Li <[email protected]>
drivers/i3c/Kconfig +12 -0
index 626c54b386d5..630dc776c464 100644
@@ -20,6 +20,18 @@ menuconfig I3C
 	  will be called i3c.
 
 if I3C
+
+config I3CDEV
+	tristate "I3C device interface"
+	depends on I3C
+	help
+	  Say Y here to include the i3cdev driver. This allows user-space to
+	  explicitly bind I3C devices to the driver in order to expose a
+	  character device interface for the I3C device under /dev/bus/i3c/.
+
+	  This support is also available as a module. If so, the module will
+	  be called i3cdev.
+
 source "drivers/i3c/master/Kconfig"
 endif # I3C
 
drivers/i3c/Makefile +1 -0
index 11982efbc6d9..606d422841b2 100644
@@ -1,4 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
 i3c-y				:= device.o master.o
 obj-$(CONFIG_I3C)		+= i3c.o
+obj-$(CONFIG_I3CDEV)		+= i3cdev.o
 obj-$(CONFIG_I3C)		+= master/
drivers/i3c/i3cdev.c new file +730 -0

730 lines not on this page · raw message

include/uapi/linux/i3c/i3cdev.h new file +70 -0

70 lines not on this page · raw message

Signature · 1 line
2.49.0
#14 lore raw

Re: [PATCH 3/3] i3c: add i3cdev character device module for user-space access

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [Medium] Max Write Length (MWL) check is bypassed in `i3cdev_write` due to uninitialized length field.…

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [Medium] Max Write Length (MWL) check is bypassed in i3cdev_write due to uninitialized length field.
- [Medium] Mixing goto-based error handling and scoped_guard() declarations in the same function violates the cleanup subsystem guidelines.
- [Medium] Memory and reference count leak on the dev_set_name() error path in i3cdev_probe().
- [Medium] Un-ratelimited kernel logging in print_i3c_err allows unprivileged users to flood dmesg.
--

commit 691a30342eecac1b5bf88181bfab4ade443f2923
Author: Meagan Lloyd <[email protected]>
Subject: i3c: add i3cdev character device module for user-space access

This commit introduces a character device driver for I3C devices. It allows user-space applications to perform basic SDR reads and writes by binding devices manually via sysfs driver_override.

Quoted 5 lines
drivers/i3c/i3cdev.c new file +0 -0
new file mode 100644
index 0000000000000..da0e6910a4f72

[ ... ]

Quoted 3 lines
drivers/i3c/i3cdev.c new file +3 -0
+static ssize_t
+i3cdev_read(struct file *file, char __user *buf, size_t count, loff_t *f_pos)
+{

[ ... ]

drivers/i3c/i3cdev.c line 135

Quoted 11 lines
drivers/i3c/i3cdev.c new file +11 -0
+	scoped_guard(mutex, &i3cdev->lock) {
+		/* .remove was called so don't mess with the device */
+		if (!i3cdev->bound) {
+			ret = -ENXIO;
+			goto out_free_kbuf;
+		}
+
+		ret = i3c_device_do_xfers(i3c, &xfer, 1, I3C_SDR);
+		if (ret)
+			goto out_free_kbuf;
+	}

[Severity: Medium]
Does this mix goto-based error handling with scoped_guard() in the same function?

The VFS/cleanup guidelines indicate that mixing goto-based error labels with scope-based cleanups like scoped_guard() creates confusing ownership semantics and increases the risk of double-free or resource leaks. Since the function uses a goto label for freeing the memory buffer out_free_kbuf, could we either convert the buffer to use a scope-based __free() or use traditional mutex lock/unlock operations?

[ ... ]

Quoted 16 lines
drivers/i3c/i3cdev.c new file +16 -0
+static ssize_t
+i3cdev_write(struct file *file, const char __user *buf, size_t count,
+	     loff_t *f_pos)
+{
+	struct i3cdev_data *i3cdev = file->private_data;
+	struct i3c_device *i3c = i3cdev->i3c;
+	struct i3c_xfer xfer = {
+		.rnw = I3C_WRITE
+	};
+	size_t len;
+	char *tmp;
+	int ret;
+
+	if (!i3cdev->bound)
+		return -ENXIO;
+

drivers/i3c/i3cdev.c line 178

Quoted 10 lines
drivers/i3c/i3cdev.c new file +10 -0
+	/* File system operation of 0 bytes is effectively a valid, no-op */
+	if (!count)
+		return 0;
+
+	if (exceeds_mwl(i3cdev, &xfer))
+		return -ENXIO;
+
+	/* Clamp transfer length within driver limits */
+	len = min(count, MAX_TOTAL_DATA_BYTES);
+	xfer.len = len;

[Severity: Medium]
Is the Max Write Length (MWL) check bypassed here due to an uninitialized length field?

At the point where exceeds_mwl() is called, xfer.len is 0 because only .rnw was initialized in the struct declaration. The actual xfer.len is assigned after the check, meaning the MWL validation will always pass regardless of the requested size. This could allow hardware to receive writes exceeding its supported maximum length. Should the length clamp and assignment happen before the validation check?

[ ... ]

drivers/i3c/i3cdev.c line 135

Quoted 11 lines
drivers/i3c/i3cdev.c new file +11 -0
+	scoped_guard(mutex, &i3cdev->lock) {
+		/* .remove was called so don't mess with the device */
+		if (!i3cdev->bound) {
+			ret = -ENXIO;
+			goto out_free_kbuf;
+		}
+
+		ret = i3c_device_do_xfers(i3c, &xfer, 1, I3C_SDR);
+		if (ret)
+			goto out_free_kbuf;
+	}

[Severity: Medium]
Similar to i3cdev_read(), does this mix goto-based error handling with scoped_guard() in the write path?

[ ... ]

Quoted 4 lines
drivers/i3c/i3cdev.c new file +4 -0
+static void print_i3c_err(struct i3cdev_data *i3cdev,
+			  struct i3cdev_xfers *metadata,
+			  struct i3c_xfer *i3c_xfers)
+{

drivers/i3c/i3cdev.c line 405

Quoted 10 lines
drivers/i3c/i3cdev.c new file +10 -0
+	for (int i = 0; i < metadata->nxfers; i++) {
+		/* Valid errors, e.g. M0 (now called C0) start at 1 */
+		if (i3c_xfers[i].err > 0) {
+			dev_warn(&i3cdev->dev,
+				 "I3C error encountered: C%u\n",
+				 i3c_xfers[i].err - 1);
+			return;
+		}
+	}
+}

[Severity: Medium]
Could this un-ratelimited kernel logging allow unprivileged users to flood the dmesg log?

Since this error is triggered directly by user-supplied transfers via the ioctl interface, a user-space application could repeatedly trigger hardware errors to intentionally spam the kernel logs. Could we use a rate-limited variant like dev_warn_ratelimited() here to prevent a potential local DoS?

[ ... ]

Quoted 4 lines
drivers/i3c/i3cdev.c new file +4 -0
+static int
+i3cdev_ioctl_do_xfers(struct i3cdev_data *i3cdev,
+		      struct i3cdev_xfers __user *uxfers)
+{

[ ... ]

drivers/i3c/i3cdev.c line 502

Quoted 13 lines
drivers/i3c/i3cdev.c new file +13 -0
+	scoped_guard(mutex, &i3cdev->lock) {
+		/* .remove was called so don't mess with the device */
+		if (!i3cdev->bound) {
+			ret = -ENXIO;
+			goto out_free_i3c_xfers;
+		}
+		ret = i3c_device_do_xfers(i3c, i3c_xfers,
+					  metadata.nxfers, I3C_SDR);
+		if (ret) {
+			print_i3c_err(i3cdev, &metadata, i3c_xfers);
+			goto out_free_i3c_xfers;
+		}
+	}

[Severity: Medium]
As in the read/write paths, does this also improperly mix scoped_guard() with goto labels in the ioctl handler?

[ ... ]

Quoted 2 lines
drivers/i3c/i3cdev.c new file +2 -0
+static int i3cdev_probe(struct i3c_device *i3c)
+{

[ ... ]

drivers/i3c/i3cdev.c line 633

Quoted 7 lines
drivers/i3c/i3cdev.c new file +7 -0
+	i3cdev->dev.parent = i3c_device_dev;
+	i3cdev->dev.devt = i3cdev->devt;
+	i3cdev->dev.class = &i3cdev_class;
+	i3cdev->dev.release = free_i3cdev_data;
+	ret = dev_set_name(&i3cdev->dev, SYSFS_FORMAT, MINOR(i3cdev->devt));
+	if (ret)
+		goto error_free_ida;

[Severity: Medium]
Does this error path leak the i3cdev memory structure and leave an unbalanced reference count on the underlying I3C device?

If dev_set_name() fails, execution jumps directly to error_free_ida, skipping the release of i3cdev memory and the device reference acquired earlier in probe. Should this instead call put_device(&i3cdev->dev) so that free_i3cdev_data is executed to handle the cleanup properly?

[ ... ]

drivers/i3c/i3cdev.c line 646

Quoted 7 lines
drivers/i3c/i3cdev.c new file +7 -0
+	scoped_guard(mutex, &i3cdev->lock) {
+		ret = cdev_device_add(&i3cdev->cdev, &i3cdev->dev);
+		if (ret)
+			goto error_cleanup;
+
+		i3cdev->bound = true;
+	}

[Severity: Medium]
Does this sequence mix scoped_guard() with a goto error cleanup label?

As with the other functions in this patch, this mixes scoped cleanup with goto statements, which goes against the VFS/cleanup guidelines.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#10 lore raw

Re: [PATCH 2/3] i3c: set i3c_xfer.actual_len in controller drivers

In reply to Meagan Lloyd
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] The Renesas I3C controller silently ignores all transfer errors and timeouts, always returning success. --

commit e28c1ae3a51db6eef5fcba16ca850acda1a087d2
Author: Meagan Lloyd <[email protected]>
Subject: i3c: set i3c_xfer.actual_len in controller drivers

This commit updates various I3C controller drivers to set actual_len for read transfers. It provides a consistent location for device drivers to know the read response bytes without overriding the length field.

Quoted 13 lines
drivers/i3c/master/renesas-i3c.c +3 -0
@@ -918,6 +918,9 @@ static int renesas_i3c_i3c_xfers(struct i3c_dev_desc *dev, struct i3c_xfer *i3c_
 		time_left = renesas_i3c_wait_xfer(i3c, xfer);
 		if (!time_left)
 			xfer_failed = true;
+
+		if (i3c_xfers[i].rnw)
+			i3c_xfers[i].actual_len = cmd->rx_count;
 	}
 
 	if (xfer_failed)

drivers/i3c/master/renesas-i3c.c

Quoted 4 lines
drivers/i3c/master/renesas-i3c.c +0 -0
 		renesas_i3c_irqs_mask_and_clear(i3c);
 
 	return 0;
 }

[Severity: High]
This isn't a bug introduced by this patch, but is a critical pre-existing issue. Does renesas_i3c_i3c_xfers() silently ignore transfer errors?

If an I3C hardware error occurs during the transfer, the ISR populates xfer->ret with a negative error code like -EIO, but the loop here never checks xfer->ret. Furthermore, if a timeout occurs, xfer_failed is set, but the loop does not break early, and the function unconditionally returns 0 at the end.

Since the controller ignores the error and returns success, callers will proceed as if the data was successfully read or written. Could this lead to I3C device drivers consuming uninitialized memory or encountering silent state machine failures when a hardware NACK, CRC error, or timeout occurs?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#2 lore raw

Re: [PATCH 1/3] i3c: master: enable driver_override for I3C

In reply to Meagan Lloyd
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 8 lines

Opt-in to driver_override sysfs functionality for I3C subsystem.

Update some I3C drivers that are assuming that if their .probe is invoked that the bus match function already checked the ID table. Go ahead and verify in .probe that i3c_device_match_id() returns a valid match before using the i3c_device_id pointer.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#3 lore raw

Re: [PATCH 1/3] i3c: master: enable driver_override for I3C

In reply to Meagan Lloyd
Quoted 7 lines · Meagan Lloyd

Opt-in to driver_override sysfs functionality for I3C subsystem.

Update some I3C drivers that are assuming that if their .probe is invoked that the bus match function already checked the ID table. Go ahead and verify in .probe that i3c_device_match_id() returns a valid match before using the i3c_device_id pointer.

Quoted 5 lines
Assisted-by Claude:claude-opus-4.8 copilot
---
 drivers/hwmon/lm75.c                        |  7 ++++++-
 drivers/hwmon/tmp108.c                      |  2 ++

Separate patches for each hwmon driver, please. Each patch should use the standard prefix used in hwmon drivers.

Thanks,
Guenter

reviewer
#15 lore raw

Re: [PATCH 3/3] i3c: add i3cdev character device module for user-space access

In reply to Meagan Lloyd
Quoted 183 lines · Meagan Lloyd

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.

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>

Assisted-by Claude:claude-opus-4.8 copilot
---
 Documentation/userspace-api/i3c/i3cdev.rst    | 152 ++++
 .../userspace-api/ioctl/ioctl-number.rst      |   1 +
 MAINTAINERS                                   |   7 +
 drivers/i3c/Kconfig                           |  12 +
 drivers/i3c/Makefile                          |   1 +
 drivers/i3c/i3cdev.c                          | 730 ++++++++++++++++++
 include/uapi/linux/i3c/i3cdev.h               |  70 ++
 7 files changed, 973 insertions(+)
 create mode 100644 Documentation/userspace-api/i3c/i3cdev.rst
 create mode 100644 drivers/i3c/i3cdev.c
 create mode 100644 include/uapi/linux/i3c/i3cdev.h
Documentation/userspace-api/i3c/i3cdev.rst new file +143 -0
new file mode 100644
index 000000000000..ad246bf28919
@@ -0,0 +1,152 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+====================
+I3C Device Interface
+====================
+
+This interface allows access to I3C devices from userspace.
+
+As I3C devices adhere to the I3C protocol, simple transfers can be accomplished
+using a generic driver. Currently, this interface supports private Single Data
+Rate (SDR) read and write transfers.
+
+The i3cdev module will not auto-bind to devices. Userspace needs to explicitly
+bind the device to the driver. This is to avoid interfering with the binding of
+specialized drivers.
+
+Once bound, a character device interface will be created at:
+/dev/bus/i3c/<bus id>-<Provisional ID>.
+
+====================
+Usage
+====================
+
+Any discovered I3C devices by the I3C subsystem will have device folders under /sys/bus/i3c/devices/<bus id>-<Provisional ID>.
+To allow binding of a device with i3cdev driver, set the driver_override:
+
+::
+
+    # echo "i3cdev" > /sys/bus/i3c/devices/<bus id>-<Provisional ID>/driver_override
+
+If the i3cdev driver is not yet loaded, load it and it will cause the driver to bind
+to any devices with the override in place.
+
+If the i3cdev driver is already loaded, go ahead and perform a manual bind:
+
+::
+
+    # echo "<bus id>-<Provisional ID>" > /sys/bus/i3c/drivers/i3cdev/bind
+
+Set driver override
+::
+
+    # echo "i3cdev" > /sys/bus/i3c/devices/0-deadbeef001/driver_override
+    # echo "i3cdev" > /sys/bus/i3c/devices/0-deadbeef002/driver_override
+
+Bind the device to the driver
+::
+
+    # echo "0-deadbeef001" > /sys/bus/i3c/drivers/i3cdev/bind
+    # echo "0-deadbeef002" > /sys/bus/i3c/drivers/i3cdev/bind
+
+Observe the resulting character device files under /dev/bus/i3c/
+::
+
+    # ls -ltr /dev/bus/i3c/
+    crw-------    1 root     root      235,   1 Jun 30 17:49 0-deadbeef002
+    crw-------    1 root     root      235,   0 Jun 30 17:49 0-deadbeef001
+
+BASIC CHARACTER DEVICE API
+===============================
+The API supports private Single Data Rate (SDR) read and write transfers.
+Those transaction can be achieved by the following:
+
+``read(file, buffer, sizeof(buffer))``
+  The standard read() operation will work as a simple transaction of private
+  SDR read data followed a stop.
+  Return the number of bytes read on success, and a negative error otherwise.
+
+``write(file, buffer, sizeof(buffer))``
+  The standard write() operation will work as a simple transaction of private
+  SDR write data followed a stop.
+  Return the number of bytes written on success, and a negative error otherwise.
+
+``ioctl(file, I3CDEV_XFER, struct i3cdev_xfers *xfers)``
+  It combines read/write transactions without a stop in between.
+  Return 0 on success, and a negative error otherwise.
+
+C EXAMPLE (PSEUDO CODE)
+=======================
+You need to open (and get a file descriptor) to /dev/bus/i3c/<bus id>-<Provisional ID>,
+do your operations (read, write, ioctl), and then close it.
+
+The following header files should be included in an I3C program::
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <i3c/i3cdev.h>
+#include <stdint.h>
+
+These additionally are used by this example::
+
+#include <stdlib.h>
+#include <assert.h>
+
+To work with an I3C device, one must call open and get a file descriptor::
+
+	int fd;
+
+	fd = open("/dev/bus/i3c/0-deadbeef001", O_RDWR);
+	if (fd < 0)
+		exit(EXIT_FAILURE);
+
+Now that the file is open, we can do some operations::
+
+	int ret;
+
+	/* Write function */
+	uint8_t  buf[] = {0x00, 0xde, 0xad, 0xbe, 0xef};
+	ret = write(fd, buf, 5);
+	if (ret != 5) {
+		/* ERROR HANDLING: I3C transaction failed */
+	}
+
+	/*  Read function */
+	ret = read(fd, buf, 4);
+	if (ret < 0) {
+		/* ERROR HANDLING: I3C transaction failed */
+	} else {
+		/* Iterate over buf[] to get the read data */
+	}
+
+	/* IOCTL function */
+	struct i3cdev_xfer xfers[2] = {0}; /* Must zero out for compatibility */
+	struct i3cdev_xfers xfers_metadata = { .nxfers = 2,
+					       .xfers = (uintptr_t) xfers,
+					       .xfer_size = sizeof(struct i3cdev_xfer)
+					     };
+
+	uint8_t tx_buf[] = {0x00, 0xde, 0xad, 0xbe, 0xef};
+	uint8_t rx_buf[10];
+
+	xfers[0].data = (uintptr_t) tx_buf;
+	xfers[0].len = 5;
+	xfers[0].rnw = 0;
+	xfers[1].data = (uintptr_t) rx_buf;
+	xfers[1].len = 10;
+	xfers[1].rnw = 1;
+
+	ret = ioctl(fd, I3CDEV_XFER, (uintptr_t) &xfers_metadata);
+	if (ret < 0) {
+		/* ERROR HANDLING: I3C transaction failed */
+	} else {

Documentation/userspace-api/i3c/i3cdev.rst line 152

Quoted 10 lines
Documentation/userspace-api/i3c/i3cdev.rst new file +9 -0
+		/* For reads, optionally verify that the response matches expectations */
+		assert(xfers[1].len == xfers[1].actual_len);
+
+		/* For reads, iterate through response data using xfers[i].actual_len */
+	}
+
+The device can be closed when the open file descriptor is no longer required::
+
+	close(fd);
\ No newline at end of file

Fix the warning above, please.
Also:
Documentation/userspace-api/i3c/i3cdev.rst: WARNING: document isn't included in any toctree [toc.not_included]

add that file to the table of contents (somewhere).

thanks.

Signature · 7 lines
~Randy


-- 
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c
#5 lore raw

Re: [PATCH 1/3] i3c: master: enable driver_override for I3C

In reply to Meagan Lloyd
Quoted 9 lines · Meagan Lloyd

Opt-in to driver_override sysfs functionality for I3C subsystem.

Update some I3C drivers that are assuming that if their .probe is invoked that the bus match function already checked the ID table. Go ahead and verify in .probe that i3c_device_match_id() returns a valid match before using the i3c_device_id pointer.

Assisted-by Claude:claude-opus-4.8 copilot
Assisted-by LLM

...

Quoted 5 lines
 drivers/hwmon/lm75.c                        |  7 ++++++-
 drivers/hwmon/tmp108.c                      |  2 ++
 drivers/i3c/master.c                        |  6 ++++++
 drivers/iio/adc/ad4062.c                    | 10 ++++++++--
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c |  3 +++

No, each IIO driver should have its own patch.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#24 lore raw
In reply to Meagan Lloyd
Quoted 11 lines · Meagan Lloyd

This is a rework and revival option for Vitor Soares' I3C character device driver patch series from 2020 [1] that I've been exploring for a few months. Recently there was a revival posted to the list [2], so I wanted to share this design option as well.

In [1] and [2], the i3cdev driver automatically attaches and detaches depending whether another driver has attached/not. In [1], Boris was suggesting we explore a more straightforward and traditional binding method aligning with the Linux driver model. At the time, there wasn't a way to auto-bind while keeping manual binding possible as they shared the same match() hook. Now with the new driver_override feature,

Where is it new? It's quite an old mechanism in the driver core...

Quoted 48 lines

the auto-binding of i3cdev on boot can be avoided if the i3cdev driver has an empty match ID table. After boot, where specialized drivers would have already bound, user-space can explicitly opt-in by setting the driver_override sysfs file with 'i3cdev' and manually binding via sysfs (or by simply loading the driver if it's loadable). This can also be easily automated with udev rules that run whenever the I3C core exposes a new device.

One downside of the automatic attach/de-attach is that if a different driver is loaded later, the first driver could have altered something on the device, breaking any assumptions of the subsequent driver.

My series builds on [1] through:
0. Addressing code review feedback in [1] from Greg, Boris, and Randy.
1. Using actual_len for accurate read response reporting. The kernel will report actual_len received from the core to user-space via the uapi i3cdev_xfer struct.
2. Placing limits on the number of transfers and bytes in requests to prevent unlimited-sized transfers or kernel memory allocation
3. Checking inputs and descriptive return codes as guard-rails for user-space and to ease use of the i3cdev driver
4. Checking on MWL to ensure that we respect device limits
5. Proper lifetime management of i3cdev_data and underlying device
6. Addressing dangling fops in the event we have an open file descriptor when a device gets unbound.
7. Fast-path locking to ensure transfers complete before a device is unbound.
8. Allowing only one file descriptor per I3C device to avoid bugs around multiple processes interacting with the device and altering the device underneath the other. For example, without this, one process could change the device's page or address pointer register underneath the other process.
9. copy_struct_from_user to ensure struct i3cdev_xfer could be extended in a compatible way. This is to be forward-looking towards potential HDR mode expansion and code reuse.
10. Reserving the IOCTL number formally
11. Updating the Documentation to be a syntax correct example program template.
12. Preserving /dev/bus/i3c/<bus id>-<Provisional ID> naming while allowing sysfs path to be neatly named i3cdev-<minor>. This avoids repeated <bus id>-<Provisional ID> in the sysfs paths which can be confusing/circular-looking.

    e.g. /sys/bus/i3c/devices/0-deadbeef001/i3cdev/0-deadbeef001 ->
         /sys/bus/i3c/devices/0-deadbeef001/i3cdev/i3cdev-0

13. Updating all naming references related to i3c_priv_xfer to align with new i3c_xfer struct
14. Updating the MAINTAINERS file for the new pieces of code

Quoted 6 lines

Note that i3c-tools [3] or a fork of it will need small updates:
1. Update include/uapi/linux/i3c/i3cdev.h to match updated uapi structs
2. In i3ctransfer.c, use actual_len for reads

I've added MODULE_VERSION("1.0.0") in the i3cdev driver, so i3c-tools could use that to determine whether to use the old out-of-tree uapi or this one.

Absolutely no. This is legacy macro which has no need since Git era. In Git the module version is the Git SHA hash of the tip of the used tree. Nobody will understand what 1.0.0 means and how it maps to the applied patches (if any of them affects the behaviour of the feature in question).

On top of that, upstream has no clue what and how many possible custom ABIs / UAPIs exists, and we do not care, to be honest.

Quoted 3 lines

[1] https://lore.kernel.org/linux-i3c/[email protected]/
[2] https://lore.kernel.org/linux-i3c/ap_1-gFF7S821xJT@ninjato/T/#m9107c1785a4a16b1b3cb84c3269d17fac35819c8
[3] https://github.com/vitor-soares-snps/i3c-tools

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#17 lore raw

Re: [PATCH 3/3] i3c: add i3cdev character device module for user-space access

In reply to Meagan Lloyd
Quoted 10 lines · Meagan Lloyd

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.

Quoted 7 lines

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>

...

Review

Quoted 2 lines
(quoted diff) +2 -0
+	struct i3c_xfer xfer = {
+		.rnw = I3C_WRITE

In such cases always leave a trailing comma. It will reduce possible churn in the future.

Quoted 1 line
(quoted diff) +1 -0
+	};

...

drivers/i3c/i3cdev.c line 203

Quoted 1 line
drivers/i3c/i3cdev.c new file +1 -0
+	return !ret ? len : ret;

My gosh, wouldn't Elvis just work naturally?

	return ret ?: len;

...

Review

Quoted 1 line
(quoted diff) +1 -0
+	for (int i = 0; i < metadata->nxfers; i++) {

Why is 'i' signed?

Quoted 16 lines
drivers/i3c/i3cdev.c new file +16 -0
+		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 */
+	}

...

drivers/i3c/i3cdev.c line 355

Quoted 4 lines
drivers/i3c/i3cdev.c new file +4 -0
+		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).

...

Quoted 8 lines

+/**
+ * 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?

Quoted 1 line

+ */

...

Please, rely less on AI and more on the common sense and proof-reading.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#7 lore raw

Re: [PATCH 1/3] i3c: master: enable driver_override for I3C

In reply to Meagan Lloyd
Quoted 9 lines · On Fri, 11 Sep 2026 14:09:33 -0700 Meagan Lloyd…

Opt-in to driver_override sysfs functionality for I3C subsystem.

Update some I3C drivers that are assuming that if their .probe is invoked that the bus match function already checked the ID table. Go ahead and verify in .probe that i3c_device_match_id() returns a valid match before using the i3c_device_id pointer.

Assisted-by Claude:claude-opus-4.8 copilot

Along with splitting these up as this is the sort of change that will sometimes need backporting in individual drivers because we are layering something on top, I'd look at adding some helpers to skip the id as that isn't much used and get the specific fields people want.

drivers/hwmon/tmp108.c static int p3t1085_i3c_probe(struct i3c_device *i3cdev) · line 587

Quoted 12 lines
drivers/hwmon/tmp108.c +2 -0
index 1c4a58855e2d..98076ae8dce8 100644
@@ -581,6 +581,8 @@ static int p3t1085_i3c_probe(struct i3c_device *i3cdev)
 				     "Failed to register i3c regmap\n");
 
 	id = i3c_device_match_id(i3cdev, p3t1085_i3c_ids);
+	if (!id)
+		return -ENODEV;
 
 	return tmp108_common_probe(dev, regmap, "p3t1085_i3c", id->data);

Similar to below, jumping directly to an i3c_device_match_data() helper in this series would avoid getting and id that these drivers don't need access to.

Quoted 15 lines
drivers/hwmon/tmp108.c +0 -0
 }
drivers/iio/adc/ad4062.c +2 -2
index 8e5984055b15..f28b503d16eb 100644
@@ -1482,14 +1482,20 @@ MODULE_DEVICE_TABLE(i3c, ad4062_id_table);
 
 static int ad4062_probe(struct i3c_device *i3cdev)
 {
-	const struct i3c_device_id *id = i3c_device_match_id(i3cdev, ad4062_id_table);
-	const struct ad4062_chip_info *chip = id->data;
+	const struct i3c_device_id *id;
+	const struct ad4062_chip_info *chip;
 	struct device *dev = &i3cdev->dev;

drivers/iio/adc/ad4062.c MODULE_DEVICE_TABLE(i3c, ad4062_id_table); · line 1497

Quoted 10 lines
drivers/iio/adc/ad4062.c +5 -0
 	struct iio_dev *indio_dev;
 	struct ad4062_state *st;
 	bool ref_sel;
 	int ret;
 
+	id = i3c_device_match_id(i3cdev, ad4062_id_table);
+	if (!id)
+		return -ENODEV;
+
+	chip = id->data;

This might be a good opportunity to introduce

i3c_device_match_data() as in many drivers we don't actually care about access to the id itself.

drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c static int st_lsm6dsx_i3c_probe(struct i3c_device *i3cdev) · line 34

Quoted 12 lines
drivers/iio/adc/ad4062.c +1 -0
+
 	indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
 	if (!indio_dev)
 		return -ENOMEM;
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c +0 -0
index cb5c5d7e1f3d..153a03e06801 100644
@@ -32,6 +32,9 @@ static int st_lsm6dsx_i3c_probe(struct i3c_device *i3cdev)
 	struct device *dev = i3cdev_to_dev(i3cdev);
 	struct regmap *regmap;
 

Please bring the assignment down to above the check so

	id = i3c_device_match_id(i3cdev,st_lsm6dsx_i3c_ids);

Which is what you did in the previous driver...

Quoted 6 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c +3 -0
+	if (!id)
+		return -ENODEV;
+
 	regmap = devm_regmap_init_i3c(i3cdev, &st_lsm6dsx_i3c_regmap_config);
 	if (IS_ERR(regmap)) {
 		dev_err(dev, "Failed to register i3c regmap %ld\n", PTR_ERR(regmap));
maintainer
#11 lore raw

Re: [PATCH 2/3] i3c: set i3c_xfer.actual_len in controller drivers

In reply to Meagan Lloyd
Quoted 4 lines · On Fri, 11 Sep 2026 14:09:34 -0700 Meagan Lloyd…

Set i3c_xfer.actual_len for reads across the I3C Controller drivers.

actual_len provides a consistent location for device drivers to know the read response bytes without overriding the len field.

Hi Meagan,

Why is that useful in this series? Currently this sounds like an unrelated change.

Jonathan

Quoted 2 lines
#4 lore raw

Re: [PATCH 1/3] i3c: master: enable driver_override for I3C

In reply to Guenter Roeck
Quoted 6 lines

Separate patches for each hwmon driver, please. Each patch should use the standard prefix used in hwmon drivers.

Thanks,
Guenter

Will do, thanks for the feedback.

Best regards,
Meagan

#16 lore raw

Re: [PATCH 3/3] i3c: add i3cdev character device module for user-space access

In reply to Randy Dunlap
Quoted 7 lines

Documentation/userspace-api/i3c/i3cdev.rst line 152

Quoted 2 lines
Documentation/userspace-api/i3c/i3cdev.rst new file +1 -0
+	close(fd);
\ No newline at end of file

Fix the warning above, please.
Also:
Documentation/userspace-api/i3c/i3cdev.rst: WARNING: document isn't included in any toctree [toc.not_included]

Quoted 5 lines

add that file to the table of contents (somewhere).

thanks.

Signature · 1 line
~Randy

Thanks for catching that! I'll add the newline at the end of the file as well as add this page to the table of contents.

Best regards,
Meagan

#6 lore raw

Re: [PATCH 1/3] i3c: master: enable driver_override for I3C

In reply to Andy Shevchenko
Quoted 4 lines
Quoted 2 lines
Assisted-by Claude:claude-opus-4.8 copilot
Assisted-by LLM

Sure, I can update the tag accordingly. Thanks!

Quoted 15 lines

...

Quoted 5 lines
 drivers/hwmon/lm75.c                        |  7 ++++++-
 drivers/hwmon/tmp108.c                      |  2 ++
 drivers/i3c/master.c                        |  6 ++++++
 drivers/iio/adc/ad4062.c                    | 10 ++++++++--
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c |  3 +++

No, each IIO driver should have its own patch.

Signature · 2 lines
With Best Regards,
Andy Shevchenko

Got it. Thanks for the feedback.

Sincerely,
Meagan

#8 lore raw

Re: [PATCH 1/3] i3c: master: enable driver_override for I3C

In reply to Jonathan Cameron
Quoted 7 lines
Quoted 7 lines

Opt-in to driver_override sysfs functionality for I3C subsystem.

Update some I3C drivers that are assuming that if their .probe is invoked that the bus match function already checked the ID table. Go ahead and verify in .probe that i3c_device_match_id() returns a valid match before using the i3c_device_id pointer.

Quoted 8 lines
Quoted 2 lines
Assisted-by Claude:claude-opus-4.8 copilot

Along with splitting these up as this is the sort of change that will sometimes need backporting in individual drivers because we are layering something on top, I'd look at adding some helpers to skip the id as that isn't much used and get the specific fields people want.

Yeah, I'll split these up for each individual driver.

i3c_device_match_data() is a good idea. It would reduce the likelihood that future drivers make the mistake of not checking the id before dereferencing it for data. I'll include it in the next revision.

Best regards,
Meagan

Quoted 12 lines
Quoted 12 lines
drivers/hwmon/tmp108.c +2 -0
index 1c4a58855e2d..98076ae8dce8 100644
@@ -581,6 +581,8 @@ static int p3t1085_i3c_probe(struct i3c_device *i3cdev)
 				     "Failed to register i3c regmap\n");
 
 	id = i3c_device_match_id(i3cdev, p3t1085_i3c_ids);
+	if (!id)
+		return -ENODEV;
 
Quoted 6 lines

drivers/hwmon/tmp108.c static int p3t1085_i3c_probe(struct i3c_device *i3cdev) · line 587

Quoted 1 line
drivers/hwmon/tmp108.c +0 -0
 	return tmp108_common_probe(dev, regmap, "p3t1085_i3c", id->data);

Similar to below, jumping directly to an i3c_device_match_data() helper in this series would avoid getting and id that these drivers don't need access to.

I acknowledge and agree.

Quoted 46 lines
Quoted 15 lines
drivers/hwmon/tmp108.c +0 -0
 }
drivers/iio/adc/ad4062.c +2 -2
index 8e5984055b15..f28b503d16eb 100644
@@ -1482,14 +1482,20 @@ MODULE_DEVICE_TABLE(i3c, ad4062_id_table);
 
 static int ad4062_probe(struct i3c_device *i3cdev)
 {
-	const struct i3c_device_id *id = i3c_device_match_id(i3cdev, ad4062_id_table);
-	const struct ad4062_chip_info *chip = id->data;
+	const struct i3c_device_id *id;
+	const struct ad4062_chip_info *chip;
 	struct device *dev = &i3cdev->dev;

drivers/iio/adc/ad4062.c MODULE_DEVICE_TABLE(i3c, ad4062_id_table); · line 1497

Quoted 10 lines
drivers/iio/adc/ad4062.c +5 -0
 	struct iio_dev *indio_dev;
 	struct ad4062_state *st;
 	bool ref_sel;
 	int ret;
 
+	id = i3c_device_match_id(i3cdev, ad4062_id_table);
+	if (!id)
+		return -ENODEV;
+
+	chip = id->data;

This might be a good opportunity to introduce

i3c_device_match_data() as in many drivers we don't actually care about access to the id itself.

drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c static int st_lsm6dsx_i3c_probe(struct i3c_device *i3cdev) · line 34

Quoted 12 lines
drivers/iio/adc/ad4062.c +1 -0
+
 	indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
 	if (!indio_dev)
 		return -ENOMEM;
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c +0 -0
index cb5c5d7e1f3d..153a03e06801 100644
@@ -32,6 +32,9 @@ static int st_lsm6dsx_i3c_probe(struct i3c_device *i3cdev)
 	struct device *dev = i3cdev_to_dev(i3cdev);
 	struct regmap *regmap;
 

Please bring the assignment down to above the check so

Quoted 3 lines
	id = i3c_device_match_id(i3cdev,st_lsm6dsx_i3c_ids);

Which is what you did in the previous driver...

You're right. It is more readable that way. Thanks!

Quoted 8 lines
Quoted 6 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c +3 -0
+	if (!id)
+		return -ENODEV;
+
 	regmap = devm_regmap_init_i3c(i3cdev, &st_lsm6dsx_i3c_regmap_config);
 	if (IS_ERR(regmap)) {
 		dev_err(dev, "Failed to register i3c regmap %ld\n", PTR_ERR(regmap));
#12 lore raw

Re: [PATCH 2/3] i3c: set i3c_xfer.actual_len in controller drivers

In reply to Jonathan Cameron
Quoted 8 lines · Jonathan Cameron
Quoted 4 lines · On Fri, 11 Sep 2026 14:09:34 -0700 Meagan Lloyd…

Set i3c_xfer.actual_len for reads across the I3C Controller drivers.

actual_len provides a consistent location for device drivers to know the read response bytes without overriding the len field.

Quoted 6 lines

Hi Meagan,

Why is that useful in this series? Currently this sounds like an unrelated change.

Jonathan

Hi Jonathan,

For read operations, user-space allocates and provides a buffer, as well as indicates how many bytes it would like to/can receive in that buffer. actual_len allows us to report to user-space how many bytes were actually received from the device and are thus valid in that buffer.

Thanks,
Meagan

#25 lore raw
In reply to Andy Shevchenko
Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Meagan Lloyd

This is a rework and revival option for Vitor Soares' I3C character device driver patch series from 2020 [1] that I've been exploring for a few months. Recently there was a revival posted to the list [2], so I wanted to share this design option as well.

Quoted 8 lines
Quoted 6 lines

In [1] and [2], the i3cdev driver automatically attaches and detaches depending whether another driver has attached/not. In [1], Boris was suggesting we explore a more straightforward and traditional binding method aligning with the Linux driver model. At the time, there wasn't a way to auto-bind while keeping manual binding possible as they shared the same match() hook. Now with the new driver_override feature,

Where is it new? It's quite an old mechanism in the driver core...

My understanding is that this support was added in March 2026 here:
https://lore.kernel.org/all/[email protected]/

Some busses had their own version of this, but the above series made a general, re-usable solution available.

Quoted 61 lines
Quoted 49 lines

the auto-binding of i3cdev on boot can be avoided if the i3cdev driver has an empty match ID table. After boot, where specialized drivers would have already bound, user-space can explicitly opt-in by setting the driver_override sysfs file with 'i3cdev' and manually binding via sysfs (or by simply loading the driver if it's loadable). This can also be easily automated with udev rules that run whenever the I3C core exposes a new device.

One downside of the automatic attach/de-attach is that if a different driver is loaded later, the first driver could have altered something on the device, breaking any assumptions of the subsequent driver.

My series builds on [1] through:
0. Addressing code review feedback in [1] from Greg, Boris, and Randy.
1. Using actual_len for accurate read response reporting. The kernel will report actual_len received from the core to user-space via the uapi i3cdev_xfer struct.
2. Placing limits on the number of transfers and bytes in requests to prevent unlimited-sized transfers or kernel memory allocation
3. Checking inputs and descriptive return codes as guard-rails for user-space and to ease use of the i3cdev driver
4. Checking on MWL to ensure that we respect device limits
5. Proper lifetime management of i3cdev_data and underlying device
6. Addressing dangling fops in the event we have an open file descriptor when a device gets unbound.
7. Fast-path locking to ensure transfers complete before a device is unbound.
8. Allowing only one file descriptor per I3C device to avoid bugs around multiple processes interacting with the device and altering the device underneath the other. For example, without this, one process could change the device's page or address pointer register underneath the other process.
9. copy_struct_from_user to ensure struct i3cdev_xfer could be extended in a compatible way. This is to be forward-looking towards potential HDR mode expansion and code reuse.
10. Reserving the IOCTL number formally
11. Updating the Documentation to be a syntax correct example program template.
12. Preserving /dev/bus/i3c/<bus id>-<Provisional ID> naming while allowing sysfs path to be neatly named i3cdev-<minor>. This avoids repeated <bus id>-<Provisional ID> in the sysfs paths which can be confusing/circular-looking.

    e.g. /sys/bus/i3c/devices/0-deadbeef001/i3cdev/0-deadbeef001 ->
         /sys/bus/i3c/devices/0-deadbeef001/i3cdev/i3cdev-0

13. Updating all naming references related to i3c_priv_xfer to align with new i3c_xfer struct
14. Updating the MAINTAINERS file for the new pieces of code

Quoted 6 lines

Note that i3c-tools [3] or a fork of it will need small updates:
1. Update include/uapi/linux/i3c/i3cdev.h to match updated uapi structs
2. In i3ctransfer.c, use actual_len for reads

I've added MODULE_VERSION("1.0.0") in the i3cdev driver, so i3c-tools could use that to determine whether to use the old out-of-tree uapi or this one.

Absolutely no. This is legacy macro which has no need since Git era. In Git the module version is the Git SHA hash of the tip of the used tree. Nobody will understand what 1.0.0 means and how it maps to the applied patches (if any of them affects the behaviour of the feature in question).

Quoted 11 lines

On top of that, upstream has no clue what and how many possible custom ABIs / UAPIs exists, and we do not care, to be honest.

Quoted 3 lines

[1] https://lore.kernel.org/linux-i3c/[email protected]/
[2] https://lore.kernel.org/linux-i3c/ap_1-gFF7S821xJT@ninjato/T/#m9107c1785a4a16b1b3cb84c3269d17fac35819c8
[3] https://github.com/vitor-soares-snps/i3c-tools

Signature · 2 lines
With Best Regards,
Andy Shevchenko

My reasoning was that i3c-tools has been around for years now and it may be in-use assuming the UAPI from [1]. Adding MODULE_VERSION was a low effort, compatible, and reliable way to keep using the same i3c-tools repo (and accommodate a changed UAPI).

In any case, in Sam's thread [2], there is talk of moving i3c-tools into the kernel's tools directory. That's the better solution, so I can drop the MODULE_VERSION in future revisions.

Thank you,
Meagan

#18 lore raw

Re: [PATCH 3/3] i3c: add i3cdev character device module for user-space access

In reply to Andy Shevchenko
Quoted 7 lines · Andy Shevchenko
Quoted 6 lines · Meagan Lloyd

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.

Quoted 8 lines
Quoted 4 lines

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.

Quoted 8 lines
Quoted 7 lines

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>

Quoted 7 lines

...

Review

Quoted 1 line
(quoted diff) +1 -0
+	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.

Quoted 10 lines
Quoted 1 line
(quoted diff) +1 -0
+	};

...

drivers/i3c/i3cdev.c line 203

Quoted 1 line
drivers/i3c/i3cdev.c new file +1 -0
+	return !ret ? len : ret;

My gosh, wouldn't Elvis just work naturally?

	return ret ?: len;

You're right, that is much nicer!

Quoted 6 lines

...

Review

Quoted 1 line
(quoted diff) +1 -0
+	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().

Quoted 11 lines
Quoted 8 lines
(quoted diff) +1 -0
+		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 */ + }

...

Quoted 6 lines
Quoted 2 lines
(quoted diff) +1 -0
+		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.

Quoted 8 lines

...

Quoted 5 lines

+/** + * 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

Quoted 4 lines
Quoted 1 line

+ * 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.

Quoted 8 lines
Quoted 1 line

+ */

...

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

Signature · 3 lines
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c
#19 lore raw

Re: [PATCH 3/3] i3c: add i3cdev character device module for user-space access

Quoted 13 lines · Meagan Lloyd
Quoted 12 lines · Andy Shevchenko
Quoted 10 lines · Meagan Lloyd

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.

Quoted 5 lines
Quoted 2 lines

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:

This argument has nothing to do with i³c. Each bus is different on a physical layer, electrical protocols and programming flow. Each of them has own constraints.

Quoted 5 lines

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.

Yes, but I have seen no reason why we should expose i³c bus to the user space. With i²c we already know very well that it was (and still is) a bad idea. Why i³c is better (especially taking into account i²c compatible mode and more complex programming flow)?

Quoted 5 lines

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.

Put a real life example why the exposing i³c devices into user space is absolutely necessary.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

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>

...

Quoted 9 lines
Quoted 3 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	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().

No need to add useless checks.

...

Quoted 10 lines
Quoted 9 lines
Quoted 7 lines

+/** + * 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?

Quoted 7 lines

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.

My point is about kernel-doc. Why do we need the return section for void? Where it comes from?

Quoted 1 line
Quoted 1 line
Quoted 1 line

+ */

...

Quoted 7 lines
Quoted 2 lines

Please, rely less on AI and more on the common sense and proof-reading.

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.

I see, then there is a room to improve the code. But the main question is why do we even need this whole interface to begin with?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#26 lore raw
In reply to Meagan Lloyd
Quoted 14 lines · Meagan Lloyd
Quoted 13 lines · Andy Shevchenko
Quoted 11 lines · Meagan Lloyd

This is a rework and revival option for Vitor Soares' I3C character device driver patch series from 2020 [1] that I've been exploring for a few months. Recently there was a revival posted to the list [2], so I wanted to share this design option as well.

In [1] and [2], the i3cdev driver automatically attaches and detaches depending whether another driver has attached/not. In [1], Boris was suggesting we explore a more straightforward and traditional binding method aligning with the Linux driver model. At the time, there wasn't a way to auto-bind while keeping manual binding possible as they shared the same match() hook. Now with the new driver_override feature,

Quoted 7 lines
Quoted 1 line

Where is it new? It's quite an old mechanism in the driver core...

My understanding is that this support was added in March 2026 here:
https://lore.kernel.org/all/[email protected]/

Some busses had their own version of this, but the above series made a general, re-usable solution available.

Nope, the series fixes the bug and at the same time refactored to provide a generalised solution. The driver_override as a concept exists for ages.

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

the auto-binding of i3cdev on boot can be avoided if the i3cdev driver has an empty match ID table. After boot, where specialized drivers would have already bound, user-space can explicitly opt-in by setting the driver_override sysfs file with 'i3cdev' and manually binding via sysfs (or by simply loading the driver if it's loadable). This can also be easily automated with udev rules that run whenever the I3C core exposes a new device.

One downside of the automatic attach/de-attach is that if a different driver is loaded later, the first driver could have altered something on the device, breaking any assumptions of the subsequent driver.

...

Quoted 19 lines
Quoted 7 lines
Quoted 6 lines

Note that i3c-tools [3] or a fork of it will need small updates:
1. Update include/uapi/linux/i3c/i3cdev.h to match updated uapi structs
2. In i3ctransfer.c, use actual_len for reads

I've added MODULE_VERSION("1.0.0") in the i3cdev driver, so i3c-tools could use that to determine whether to use the old out-of-tree uapi or this one.

Quoted 11 lines

Absolutely no. This is legacy macro which has no need since Git era. In Git the module version is the Git SHA hash of the tip of the used tree. Nobody will understand what 1.0.0 means and how it maps to the applied patches (if any of them affects the behaviour of the feature in question).

On top of that, upstream has no clue what and how many possible custom ABIs / UAPIs exists, and we do not care, to be honest.

Quoted 3 lines

[1] https://lore.kernel.org/linux-i3c/[email protected]/
[2] https://lore.kernel.org/linux-i3c/ap_1-gFF7S821xJT@ninjato/T/#m9107c1785a4a16b1b3cb84c3269d17fac35819c8
[3] https://github.com/vitor-soares-snps/i3c-tools

Quoted 5 lines

My reasoning was that i3c-tools has been around for years now and it may be in-use assuming the UAPI from [1]. Adding MODULE_VERSION was a low effort, compatible, and

reliable way

Nope, you are mistaken. As I explained the opaque 1.0.0 means nothing. The Git SHA *is* the version of the code in question.

Quoted 6 lines

to keep using the same i3c-tools
repo (and accommodate a changed UAPI).

In any case, in Sam's thread [2], there is talk of moving i3c-tools into the kernel's tools directory. That's the better solution, so I can drop the MODULE_VERSION in future revisions.

This is really orthogonal. But yes, keeping tools at the kernel source tree makes sense for a better maintenance.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#20 lore raw

Re: [PATCH 3/3] i3c: add i3cdev character device module for user-space access

In reply to Andy Shevchenko

Am 17.09.26 um 07:49 schrieb Andy Shevchenko:

Quoted 25 lines · Meagan Lloyd
Quoted 7 lines · Andy Shevchenko
Quoted 6 lines · Meagan Lloyd
Quoted 5 lines

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.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

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:

This argument has nothing to do with i³c. Each bus is different on a physical layer, electrical protocols and programming flow. Each of them has own constraints.

Quoted 5 lines

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.

Quoted 4 lines

Yes, but I have seen no reason why we should expose i³c bus to the user space. With i²c we already know very well that it was (and still is) a bad idea. Why i³c is better (especially taking into account i²c compatible mode and more complex programming flow)?

Hi,

in my experience sometimes during driver development you want to access the device directly to test things, but of course this is incredibly unsafe.

I think we should taint the kernel as soon as userspace applications perform raw i3c accesses, but the idea itself is fine from my point of view.

Thanks,
Armin Wolf

Quoted 57 lines
Quoted 5 lines

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.

Put a real life example why the exposing i³c devices into user space is absolutely necessary.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

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>

...

Quoted 7 lines
Quoted 2 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	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().

No need to add useless checks.

...

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

+/** + * 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

Quoted 8 lines
Quoted 1 line

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.

My point is about kernel-doc. Why do we need the return section for void? Where it comes from?

Quoted 1 line
Quoted 1 line
Quoted 1 line

+ */

...

Quoted 6 lines
Quoted 2 lines

Please, rely less on AI and more on the common sense and proof-reading.

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.

I see, then there is a room to improve the code. But the main question is why do we even need this whole interface to begin with?

Signature · 3 lines
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c
#22 lore raw

Re: [PATCH 3/3] i3c: add i3cdev character device module for user-space access

In reply to Andy Shevchenko
Quoted 17 lines · Andy Shevchenko
Quoted 16 lines · Meagan Lloyd
Quoted 14 lines · Andy Shevchenko
Quoted 10 lines · Meagan Lloyd

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.

Quoted 6 lines
Quoted 2 lines

I can't see a reason that it'd be unsafe. To give additional confidence, it's already in-use in many bus_types:

This argument has nothing to do with i³c. Each bus is different on a physical layer, electrical protocols and programming flow. Each of them has own constraints.

My take is that if you're using the i3cdev module, it's up to the programmer to review schematics/datasheets to know how to program the hardware devices and bus (in the case of hubs) correctly.

Note, this thread's driver_override approach was not favored by the i3c subsystem reviewers, so please continue any further discussion in the prevailing approach's thread:
https://lore.kernel.org/linux-i3c/[email protected]/T/#mb42d9b2785f8508d39eaf782b3d29189226b8029

Quoted 7 lines
Quoted 6 lines

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.

Quoted 5 lines

Yes, but I have seen no reason why we should expose i³c bus to the user space. With i²c we already know very well that it was (and still is) a bad idea. Why i³c is better (especially taking into account i²c compatible mode and more complex programming flow)?

cc'ing Andy Shyti from I2C subsystem for context.

Andy, we're considering an I3C character device driver interface. If you have any feedback from your experience with I2C, can you please share it in:
https://lore.kernel.org/linux-i3c/[email protected]/T/#mb42d9b2785f8508d39eaf782b3d29189226b8029

Quoted 8 lines
Quoted 5 lines

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.

Put a real life example why the exposing i³c devices into user space is absolutely necessary.

I'm supporting a kernel running on accelerator cards that plug into various server SKUs where hubs/devices along the bus are not physically on the card & may differ across SKUs. So, I'm looking to program hubs flexibly and dynamically from userspace to setup bus hardware paths.

The hub drivers being posted to i3c subsystem require hard-coding in the devicetree to setup the ports physically according to intended bus/hardware design. As mentioned, these cards will not know what SKU it will be plugged into, so the devicetree hard-coding cannot reasonably be determined ahead of time. Theoretically, you may be able to add some bootloader support to go query SKU information from other server components and then populate the devicetree for the kernel, but that will require heavy lifting and plumbing between other server firmware components and the bootloader.

Further replies and discussion can be routed here:
https://lore.kernel.org/linux-i3c/[email protected]/T/#mb42d9b2785f8508d39eaf782b3d29189226b8029

Thank you,
Meagan

Quoted 71 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

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>

...

Quoted 9 lines
Quoted 3 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	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().

No need to add useless checks.

...

Quoted 10 lines
Quoted 9 lines
Quoted 7 lines

+/** + * 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?

Quoted 7 lines

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.

My point is about kernel-doc. Why do we need the return section for void? Where it comes from?

Quoted 1 line
Quoted 1 line
Quoted 1 line

+ */

...

Quoted 7 lines
Quoted 2 lines

Please, rely less on AI and more on the common sense and proof-reading.

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.

I see, then there is a room to improve the code. But the main question is why do we even need this whole interface to begin with?

Signature · 9 lines
With Best Regards,
Andy Shevchenko



-- 
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c
#23 lore raw

Re: [PATCH 3/3] i3c: add i3cdev character device module for user-space access

In reply to Andy Shevchenko
Quoted 17 lines · Andy Shevchenko
Quoted 16 lines · Meagan Lloyd
Quoted 14 lines · Andy Shevchenko
Quoted 10 lines · Meagan Lloyd

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.

Quoted 7 lines
Quoted 2 lines

I can't see a reason that it'd be unsafe. To give additional confidence, it's already in-use in many bus_types:

This argument has nothing to do with i³c. Each bus is different on a physical layer, electrical protocols and programming flow. Each of them has own constraints.

(resending as my previous reply hit a snag and is probably marked as spam for most people)

My take is that if you're using the i3cdev module, it's up to the programmer to review schematics/datasheets to know how to program the hardware devices and bus (in the case of hubs) correctly.

Note, this thread's driver_override approach was not favored by the i3c subsystem reviewers, so please continue any further discussion in the prevailing approach's thread:
https://lore.kernel.org/linux-i3c/[email protected]/T/#mb42d9b2785f8508d39eaf782b3d29189226b8029

Quoted 11 lines
Quoted 5 lines

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.

Yes, but I have seen no reason why we should expose i³c bus to the user space. With i²c we already know very well that it was (and still is) a bad idea. Why i³c is better (especially taking into account i²c compatible mode and more complex programming flow)?

cc'ing Andi Shyti from I2C subsystem for context.

Andi, we're considering an I3C character device driver interface. If you have any feedback from your experience with I2C, can you please share it in:
https://lore.kernel.org/linux-i3c/[email protected]/T/#mb42d9b2785f8508d39eaf782b3d29189226b8029

Quoted 9 lines
Quoted 5 lines

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.

Put a real life example why the exposing i³c devices into user space is absolutely necessary.

I'm supporting a kernel running on accelerator cards that plug into various server SKUs where hubs/devices along the bus are not physically on the card & may differ across SKUs. So, I'm looking to program hubs flexibly and dynamically from userspace to setup bus hardware paths.

The hub drivers being posted to i3c subsystem require hard-coding in the devicetree to setup the ports physically according to intended bus/hardware design. As mentioned, these cards will not know what SKU it will be plugged into, so the devicetree hard-coding cannot reasonably be determined ahead of time. Theoretically, you may be able to add some bootloader support to go query SKU information from other server components and then populate the devicetree for the kernel, but that will require heavy lifting and plumbing between other server firmware components and the bootloader.

Further replies and discussion can be routed here:
https://lore.kernel.org/linux-i3c/[email protected]/T/#mb42d9b2785f8508d39eaf782b3d29189226b8029

Thank you,
Meagan

Quoted 70 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

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>

...

Quoted 9 lines
Quoted 3 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	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().

No need to add useless checks.

...

Quoted 10 lines
Quoted 9 lines
Quoted 7 lines

+/** + * 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?

Quoted 7 lines

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.

My point is about kernel-doc. Why do we need the return section for void? Where it comes from?

Quoted 1 line
Quoted 1 line
Quoted 1 line

+ */

...

Quoted 7 lines
Quoted 2 lines

Please, rely less on AI and more on the common sense and proof-reading.

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.

I see, then there is a room to improve the code. But the main question is why do we even need this whole interface to begin with?

Signature · 9 lines
With Best Regards,
Andy Shevchenko



-- 
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c
#21 lore raw

Re: [PATCH 3/3] i3c: add i3cdev character device module for user-space access

In reply to Armin Wolf
Quoted 25 lines · Armin Wolf

Am 17.09.26 um 07:49 schrieb Andy Shevchenko:

Quoted 24 lines
Quoted 7 lines · Andy Shevchenko
Quoted 6 lines · Meagan Lloyd
Quoted 5 lines

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.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

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:

This argument has nothing to do with i³c. Each bus is different on a physical layer, electrical protocols and programming flow. Each of them has own constraints.

Quoted 5 lines

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.

Quoted 7 lines
Quoted 4 lines

Yes, but I have seen no reason why we should expose i³c bus to the user space. With i²c we already know very well that it was (and still is) a bad idea. Why i³c is better (especially taking into account i²c compatible mode and more complex programming flow)?

in my experience sometimes during driver development you want to access the device directly to test things, but of course this is incredibly unsafe.

Exactly, and not only unsafe, it's also quite dangerous to the HW. The users must *not* see or have this feature.

Quoted 2 lines

I think we should taint the kernel as soon as userspace applications perform raw i3c accesses, but the idea itself is fine from my point of view.

Not only this, but guard it in the first place.
However my personal opinion is an bsolute NAK to this idea. If you want do something, do the proper driver in the kernel.

Quoted 57 lines
Quoted 57 lines
Quoted 5 lines

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.

Put a real life example why the exposing i³c devices into user space is absolutely necessary.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

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>

...

Quoted 7 lines
Quoted 2 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	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().

No need to add useless checks.

...

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

+/** + * 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

Quoted 8 lines
Quoted 1 line

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.

My point is about kernel-doc. Why do we need the return section for void? Where it comes from?

Quoted 1 line
Quoted 1 line
Quoted 1 line

+ */

...

Quoted 6 lines
Quoted 2 lines

Please, rely less on AI and more on the common sense and proof-reading.

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.

I see, then there is a room to improve the code. But the main question is why do we even need this whole interface to begin with?

Signature · 2 lines
With Best Regards,
Andy Shevchenko