public inbox for linux-i3c@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH v2 0/5] Fix paths unexpectedly returning Mx error codes
@ 2026-03-12 16:38 Jorge Marques
  2026-03-12 16:38 ` [PATCH v2 1/5] i3c: master: Move rstdaa error suppression Jorge Marques
                   ` (4 more replies)
  0 siblings, 5 replies; 18+ messages in thread
From: Jorge Marques @ 2026-03-12 16:38 UTC (permalink / raw)
  To: Alexandre Belloni, Frank Li, Przemysław Gaj
  Cc: linux-i3c, linux-kernel, Dan Carpenter, Jonathan Cameron,
	Jorge Marques

A smatch warning on the iio/adc/ad4062.c driver raised that many i3c
methods that documented returning "0 on success or negative error code"
but actually propagate positive Mx error codes (I3C_ERROR_M0=1, M1=2,
M2=3) from i3c_master_send_ccc_cmd_locked().

Close paths returning positive Mx error codes when 0 for success or
negative error code otherwise are explicitly stated, ambiguous or
expected.

If any Mx error code is present, for each controller:
- adi: returns -EIO
- cdns: returns -EIO
- dw:
  - RESPONSE_ERROR_IBA_NACK -> I3C_ERROR_M2 : returns -EIO
  - RESPONSE_ERROR_ADDRESS_NACK : returns -EINVAL
- renesas :
  - NRSPQP_ERROR_IBA_NACK : returns -EIO
  - NRSPQP_ERROR_ADDRESS_NACK : returns -EINVAL
- svc : Unclear ret value, but cmd->err = I3C_ERROR_M2 for any ret

Each i3c_master_send_ccc_cmd_locked caller handles cmd->err directly.
There are three exceptions all related to the bus initialization:
* RSTDAA -> i3c_master_rstdaa_locked
* ENTDAA -> i3c_master_entdaa_locked
* DISEC (broadcast address only) -> i3c_master_enec_disec_locked

For direct enable ibi, disable ibi to a target, error code M2 should not
be suppressed, the device must acknowledge it.

The patch series start with moving the error check suppressions, then
does the actual change in i3c_master_send_ccc_cmd_locked to return
0 on success or negative error code otherwise (drops the positive Mx
error codes). Then ends with returning the xfer->err at
adi_i3c_master_end_xfer_locked.

The series was tested with adi-i3c-master.c and iio/adc/ad4062.c.

Link: https://lore.kernel.org/linux-iio/aYXvT5FW0hXQwhm_@stanley.mountain/

Signed-off-by: Jorge Marques <jorge.marques@analog.com>
---
Changes in v2:
- Restore rstret to continue to do_daa on any RSTDAA error.
  Note 1:
    This patch also solves
    mipi-i3c-hci/code.c@i3c_hci_resume_common returning positive error
    code at dev_err, since the Mx error codes are not propagated to ret.
  Note 2:
    It is safe to do the DAA again on devices that lost power
    (hibernation, ...) but already had the driver probed, since the PID
    is unique and i3c_master_search_i3c_dev_duplicate() searches and
    recovers the previous instance.
- Update the commit messages to explain the commits that prepare for the
  actual fix commit.
- Move premature method return documentation change to fix commit.
- Link to v1: https://lore.kernel.org/r/20260308-ad4062-positive-error-fix-v1-0-72d3c5290b4a@analog.com

---
Jorge Marques (5):
      i3c: master: Move rstdaa error suppression
      i3c: master: Move entdaa error suppression
      i3c: master: Move bus_init error suppression
      i3c: master: Fix error codes at send_ccc_cmd
      i3c: master: adi: Fix error propagation for CCCs

 drivers/i3c/master.c                 | 67 ++++++++++++++++++++----------------
 drivers/i3c/master/adi-i3c-master.c  |  5 ++-
 drivers/i3c/master/i3c-master-cdns.c |  2 +-
 3 files changed, 40 insertions(+), 34 deletions(-)
---
base-commit: abaa7682a784a0ba4ddebb08a46ed8b76859d1e6
change-id: 20260305-ad4062-positive-error-fix-dc833cd2f088

Best regards,
-- 
Jorge Marques <jorge.marques@analog.com>


-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v2 1/5] i3c: master: Move rstdaa error suppression
  2026-03-12 16:38 [PATCH v2 0/5] Fix paths unexpectedly returning Mx error codes Jorge Marques
@ 2026-03-12 16:38 ` Jorge Marques
  2026-03-13 18:43   ` Adrian Hunter
  2026-03-18 14:16   ` Frank Li
  2026-03-12 16:38 ` [PATCH v2 2/5] i3c: master: Move entdaa " Jorge Marques
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 18+ messages in thread
From: Jorge Marques @ 2026-03-12 16:38 UTC (permalink / raw)
  To: Alexandre Belloni, Frank Li, Przemysław Gaj
  Cc: linux-i3c, linux-kernel, Dan Carpenter, Jonathan Cameron,
	Jorge Marques

Prepares to fix improper Mx positive error propagation in later
commits by handling Mx error codes where the i3c_ccc_cmd command
is allocated. Two of the four i3c_master_rstdaa_locked() are error
paths that already suppressed the return value, the remaining two
are changed to handle the I3C_ERROR_M2 Mx error code inside
i3c_master_rstdaa_locked(), checking cmd->err directly.

Signed-off-by: Jorge Marques <jorge.marques@analog.com>
---
 drivers/i3c/master.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index 9e6be49bebb2c..c66f2655eb404 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -1016,6 +1016,10 @@ static int i3c_master_rstdaa_locked(struct i3c_master_controller *master,
 	ret = i3c_master_send_ccc_cmd_locked(master, &cmd);
 	i3c_ccc_cmd_dest_cleanup(&dest);
 
+	/* No active devices on the bus. */
+	if (ret && cmd.err == I3C_ERROR_M2)
+		ret = 0;
+
 	return ret;
 }
 
@@ -1796,8 +1800,6 @@ int i3c_master_do_daa_ext(struct i3c_master_controller *master, bool rstdaa)
 
 	if (rstdaa) {
 		rstret = i3c_master_rstdaa_locked(master, I3C_BROADCAST_ADDR);
-		if (rstret == I3C_ERROR_M2)
-			rstret = 0;
 	}
 
 	ret = master->ops->do_daa(master);
@@ -2093,7 +2095,7 @@ static int i3c_master_bus_init(struct i3c_master_controller *master)
 	 * (assigned by the bootloader for example).
 	 */
 	ret = i3c_master_rstdaa_locked(master, I3C_BROADCAST_ADDR);
-	if (ret && ret != I3C_ERROR_M2)
+	if (ret)
 		goto err_bus_cleanup;
 
 	if (master->ops->set_speed) {

-- 
2.51.1


-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 2/5] i3c: master: Move entdaa error suppression
  2026-03-12 16:38 [PATCH v2 0/5] Fix paths unexpectedly returning Mx error codes Jorge Marques
  2026-03-12 16:38 ` [PATCH v2 1/5] i3c: master: Move rstdaa error suppression Jorge Marques
@ 2026-03-12 16:38 ` Jorge Marques
  2026-03-13 18:43   ` Adrian Hunter
  2026-03-18 14:17   ` Frank Li
  2026-03-12 16:38 ` [PATCH v2 3/5] i3c: master: Move bus_init " Jorge Marques
                   ` (2 subsequent siblings)
  4 siblings, 2 replies; 18+ messages in thread
From: Jorge Marques @ 2026-03-12 16:38 UTC (permalink / raw)
  To: Alexandre Belloni, Frank Li, Przemysław Gaj
  Cc: linux-i3c, linux-kernel, Dan Carpenter, Jonathan Cameron,
	Jorge Marques

Prepares to fix improper Mx positive error propagation in later commits
by handling Mx error codes where the i3c_ccc_cmd command is allocated.
The CCC ENTDAA is invoked with i3c_master_entdaa_locked() and yields
error I3C_ERROR_M2 if there are no devices active on the bus. Some
controllers may also yield if there are no more devices need an dynamic
address, since the sequence do always end in a NACK. Handle inside
i3c_master_entdaa_locked(), checking cmd->err directly. Both call sites
are updated, adi_i3c_master_do_daa() and cdns_i3c_master_do_daa().

Signed-off-by: Jorge Marques <jorge.marques@analog.com>
---
 drivers/i3c/master.c                 | 4 ++++
 drivers/i3c/master/adi-i3c-master.c  | 3 +--
 drivers/i3c/master/i3c-master-cdns.c | 2 +-
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index c66f2655eb404..d4f9e7df4adc5 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -1050,6 +1050,10 @@ int i3c_master_entdaa_locked(struct i3c_master_controller *master)
 	ret = i3c_master_send_ccc_cmd_locked(master, &cmd);
 	i3c_ccc_cmd_dest_cleanup(&dest);
 
+	/* No active devices need an address. */
+	if (ret && cmd.err == I3C_ERROR_M2)
+		ret = 0;
+
 	return ret;
 }
 EXPORT_SYMBOL_GPL(i3c_master_entdaa_locked);
diff --git a/drivers/i3c/master/adi-i3c-master.c b/drivers/i3c/master/adi-i3c-master.c
index 6616f751075ae..fb9a488304469 100644
--- a/drivers/i3c/master/adi-i3c-master.c
+++ b/drivers/i3c/master/adi-i3c-master.c
@@ -655,8 +655,7 @@ static int adi_i3c_master_do_daa(struct i3c_master_controller *m)
 
 	writel(irq_mask, master->regs + REG_IRQ_MASK);
 
-	/* DAA always finishes with CE2_ERROR or NACK_RESP */
-	if (ret && ret != I3C_ERROR_M2)
+	if (ret)
 		return ret;
 
 	/* Add I3C devices discovered */
diff --git a/drivers/i3c/master/i3c-master-cdns.c b/drivers/i3c/master/i3c-master-cdns.c
index b78aebf6b2ca4..5cfec6761494d 100644
--- a/drivers/i3c/master/i3c-master-cdns.c
+++ b/drivers/i3c/master/i3c-master-cdns.c
@@ -1143,7 +1143,7 @@ static int cdns_i3c_master_do_daa(struct i3c_master_controller *m)
 	}
 
 	ret = i3c_master_entdaa_locked(&master->base);
-	if (ret && ret != I3C_ERROR_M2)
+	if (ret)
 		return ret;
 
 	newdevs = readl(master->regs + DEVS_CTRL) & DEVS_CTRL_DEVS_ACTIVE_MASK;

-- 
2.51.1


-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 3/5] i3c: master: Move bus_init error suppression
  2026-03-12 16:38 [PATCH v2 0/5] Fix paths unexpectedly returning Mx error codes Jorge Marques
  2026-03-12 16:38 ` [PATCH v2 1/5] i3c: master: Move rstdaa error suppression Jorge Marques
  2026-03-12 16:38 ` [PATCH v2 2/5] i3c: master: Move entdaa " Jorge Marques
@ 2026-03-12 16:38 ` Jorge Marques
  2026-03-13 18:45   ` Adrian Hunter
  2026-03-18 14:18   ` Frank Li
  2026-03-12 16:38 ` [PATCH v2 4/5] i3c: master: Fix error codes at send_ccc_cmd Jorge Marques
  2026-03-12 16:38 ` [PATCH v2 5/5] i3c: master: adi: Fix error propagation for CCCs Jorge Marques
  4 siblings, 2 replies; 18+ messages in thread
From: Jorge Marques @ 2026-03-12 16:38 UTC (permalink / raw)
  To: Alexandre Belloni, Frank Li, Przemysław Gaj
  Cc: linux-i3c, linux-kernel, Dan Carpenter, Jonathan Cameron,
	Jorge Marques

Prepares to fix improper Mx positive error propagation in later commits
by handling Mx error codes where the i3c_ccc_cmd command is allocated.
The CCC DISEC to broadcast address is invoked with
i3c_master_enec_disec_locked() and yields error I3C_ERROR_M2 if there
are no devices active on the bus. This is expected at the bus
initialization stage, where it is not known yet that there are no active
devices on the bus. Add bool suppress_m2 argument to
i3c_master_enec_disec_locked() and update the call site at
i3c_master_bus_init() with the exact corner case to not require
propagating positive Mx error codes. Other call site should not suppress
the error code, for example, if a driver requests to peripheral to
disable events and the transfer is not acknowledged, this is an error
and should not proceed.

Signed-off-by: Jorge Marques <jorge.marques@analog.com>
---
 drivers/i3c/master.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index d4f9e7df4adc5..bc1189afaed81 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -1059,7 +1059,8 @@ int i3c_master_entdaa_locked(struct i3c_master_controller *master)
 EXPORT_SYMBOL_GPL(i3c_master_entdaa_locked);
 
 static int i3c_master_enec_disec_locked(struct i3c_master_controller *master,
-					u8 addr, bool enable, u8 evts)
+					u8 addr, bool enable, u8 evts,
+					bool suppress_m2)
 {
 	struct i3c_ccc_events *events;
 	struct i3c_ccc_cmd_dest dest;
@@ -1079,6 +1080,9 @@ static int i3c_master_enec_disec_locked(struct i3c_master_controller *master,
 	ret = i3c_master_send_ccc_cmd_locked(master, &cmd);
 	i3c_ccc_cmd_dest_cleanup(&dest);
 
+	if (suppress_m2 && ret && cmd.err == I3C_ERROR_M2)
+		ret = 0;
+
 	return ret;
 }
 
@@ -1099,7 +1103,7 @@ static int i3c_master_enec_disec_locked(struct i3c_master_controller *master,
 int i3c_master_disec_locked(struct i3c_master_controller *master, u8 addr,
 			    u8 evts)
 {
-	return i3c_master_enec_disec_locked(master, addr, false, evts);
+	return i3c_master_enec_disec_locked(master, addr, false, evts, false);
 }
 EXPORT_SYMBOL_GPL(i3c_master_disec_locked);
 
@@ -1120,7 +1124,7 @@ EXPORT_SYMBOL_GPL(i3c_master_disec_locked);
 int i3c_master_enec_locked(struct i3c_master_controller *master, u8 addr,
 			   u8 evts)
 {
-	return i3c_master_enec_disec_locked(master, addr, true, evts);
+	return i3c_master_enec_disec_locked(master, addr, true, evts, false);
 }
 EXPORT_SYMBOL_GPL(i3c_master_enec_locked);
 
@@ -2108,11 +2112,14 @@ static int i3c_master_bus_init(struct i3c_master_controller *master)
 			goto err_bus_cleanup;
 	}
 
-	/* Disable all slave events before starting DAA. */
-	ret = i3c_master_disec_locked(master, I3C_BROADCAST_ADDR,
-				      I3C_CCC_EVENT_SIR | I3C_CCC_EVENT_MR |
-				      I3C_CCC_EVENT_HJ);
-	if (ret && ret != I3C_ERROR_M2)
+	/*
+	 * Disable all slave events before starting DAA. When no active device
+	 * is on the bus, returns Mx error code M2, this error is ignored.
+	 */
+	ret = i3c_master_enec_disec_locked(master, I3C_BROADCAST_ADDR, false,
+					   I3C_CCC_EVENT_SIR | I3C_CCC_EVENT_MR |
+					   I3C_CCC_EVENT_HJ, true);
+	if (ret)
 		goto err_bus_cleanup;
 
 	/*

-- 
2.51.1


-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 4/5] i3c: master: Fix error codes at send_ccc_cmd
  2026-03-12 16:38 [PATCH v2 0/5] Fix paths unexpectedly returning Mx error codes Jorge Marques
                   ` (2 preceding siblings ...)
  2026-03-12 16:38 ` [PATCH v2 3/5] i3c: master: Move bus_init " Jorge Marques
@ 2026-03-12 16:38 ` Jorge Marques
  2026-03-13 18:45   ` Adrian Hunter
  2026-03-18 14:27   ` Frank Li
  2026-03-12 16:38 ` [PATCH v2 5/5] i3c: master: adi: Fix error propagation for CCCs Jorge Marques
  4 siblings, 2 replies; 18+ messages in thread
From: Jorge Marques @ 2026-03-12 16:38 UTC (permalink / raw)
  To: Alexandre Belloni, Frank Li, Przemysław Gaj
  Cc: linux-i3c, linux-kernel, Dan Carpenter, Jonathan Cameron,
	Jorge Marques

i3c_master_send_ccc_cmd_locked would propagate cmd->err (positive,
Mx codes) to the ret variable, cascading down multiple methods until
reaching methods that explicitly stated they would return 0 on success
or negative error code. For example, the call chain:

  i3c_device_enable_ibi <- i3c_dev_enable_ibi_locked <-
  master->ops.enable_ibi <- i3c_master_enec_locked <-
  i3c_master_enec_disec_locked <- i3c_master_send_ccc_cmd_locked

Fix this by returning the ret value, callers can
still read the cmd->err value if ret is negative.

All corner cases where the Mx codes do need to be handled individually,
are resolved in previous commits. Those corner cases are all scenarios
when I3C_ERROR_M2 is expected and acceptable.

Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/linux-iio/aYXvT5FW0hXQwhm_@stanley.mountain/
Fixes: 3a379bbcea0a ("i3c: Add core I3C infrastructure")
Signed-off-by: Jorge Marques <jorge.marques@analog.com>
---
 drivers/i3c/master.c | 32 +++++++++++++-------------------
 1 file changed, 13 insertions(+), 19 deletions(-)

diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index bc1189afaed81..0752af5eb79b0 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -898,11 +898,17 @@ static void i3c_ccc_cmd_init(struct i3c_ccc_cmd *cmd, bool rnw, u8 id,
 	cmd->err = I3C_ERROR_UNKNOWN;
 }
 
+/**
+ * i3c_master_send_ccc_cmd_locked() - send a CCC (Common Command Codes)
+ * @master: master used to send frames on the bus
+ * @cmd: command to send
+ *
+ * Return: 0 in case of success, or a negative error code otherwise.
+ *         I3C Mx error codes are stored in cmd->err.
+ */
 static int i3c_master_send_ccc_cmd_locked(struct i3c_master_controller *master,
 					  struct i3c_ccc_cmd *cmd)
 {
-	int ret;
-
 	if (!cmd || !master)
 		return -EINVAL;
 
@@ -920,15 +926,7 @@ static int i3c_master_send_ccc_cmd_locked(struct i3c_master_controller *master,
 	    !master->ops->supports_ccc_cmd(master, cmd))
 		return -EOPNOTSUPP;
 
-	ret = master->ops->send_ccc_cmd(master, cmd);
-	if (ret) {
-		if (cmd->err != I3C_ERROR_UNKNOWN)
-			return cmd->err;
-
-		return ret;
-	}
-
-	return 0;
+	return master->ops->send_ccc_cmd(master, cmd);
 }
 
 static struct i2c_dev_desc *
@@ -1036,8 +1034,7 @@ static int i3c_master_rstdaa_locked(struct i3c_master_controller *master,
  *
  * This function must be called with the bus lock held in write mode.
  *
- * Return: 0 in case of success, a positive I3C error code if the error is
- * one of the official Mx error codes, and a negative error code otherwise.
+ * Return: 0 in case of success, or a negative error code otherwise.
  */
 int i3c_master_entdaa_locked(struct i3c_master_controller *master)
 {
@@ -1097,8 +1094,7 @@ static int i3c_master_enec_disec_locked(struct i3c_master_controller *master,
  *
  * This function must be called with the bus lock held in write mode.
  *
- * Return: 0 in case of success, a positive I3C error code if the error is
- * one of the official Mx error codes, and a negative error code otherwise.
+ * Return: 0 in case of success, or a negative error code otherwise.
  */
 int i3c_master_disec_locked(struct i3c_master_controller *master, u8 addr,
 			    u8 evts)
@@ -1118,8 +1114,7 @@ EXPORT_SYMBOL_GPL(i3c_master_disec_locked);
  *
  * This function must be called with the bus lock held in write mode.
  *
- * Return: 0 in case of success, a positive I3C error code if the error is
- * one of the official Mx error codes, and a negative error code otherwise.
+ * Return: 0 in case of success, or a negative error code otherwise.
  */
 int i3c_master_enec_locked(struct i3c_master_controller *master, u8 addr,
 			   u8 evts)
@@ -1144,8 +1139,7 @@ EXPORT_SYMBOL_GPL(i3c_master_enec_locked);
  *
  * This function must be called with the bus lock held in write mode.
  *
- * Return: 0 in case of success, a positive I3C error code if the error is
- * one of the official Mx error codes, and a negative error code otherwise.
+ * Return: 0 in case of success, or a negative error code otherwise.
  */
 int i3c_master_defslvs_locked(struct i3c_master_controller *master)
 {

-- 
2.51.1


-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 5/5] i3c: master: adi: Fix error propagation for CCCs
  2026-03-12 16:38 [PATCH v2 0/5] Fix paths unexpectedly returning Mx error codes Jorge Marques
                   ` (3 preceding siblings ...)
  2026-03-12 16:38 ` [PATCH v2 4/5] i3c: master: Fix error codes at send_ccc_cmd Jorge Marques
@ 2026-03-12 16:38 ` Jorge Marques
  2026-03-12 19:58   ` Frank Li
  2026-03-13 18:46   ` Adrian Hunter
  4 siblings, 2 replies; 18+ messages in thread
From: Jorge Marques @ 2026-03-12 16:38 UTC (permalink / raw)
  To: Alexandre Belloni, Frank Li, Przemysław Gaj
  Cc: linux-i3c, linux-kernel, Dan Carpenter, Jonathan Cameron,
	Jorge Marques

adi_i3c_master_send_ccc_cmd() always returned 0, ignoring the transfer
result populated in the completion path. As a consequence, CCC command
errors were silently dropped, including the default -ETIMEDOUT and
later overwritten by adi_i3c_master_end_xfer_locked().

Fix this by returning xfer->ret so that callers correctly receive any
transfer error codes.

Fixes: a79ac2cdc91d ("i3c: master: Add driver for Analog Devices I3C Controller IP")
Signed-off-by: Jorge Marques <jorge.marques@analog.com>
---
 drivers/i3c/master/adi-i3c-master.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/i3c/master/adi-i3c-master.c b/drivers/i3c/master/adi-i3c-master.c
index fb9a488304469..047081c9f0643 100644
--- a/drivers/i3c/master/adi-i3c-master.c
+++ b/drivers/i3c/master/adi-i3c-master.c
@@ -361,7 +361,7 @@ static int adi_i3c_master_send_ccc_cmd(struct i3c_master_controller *m,
 
 	cmd->err = adi_i3c_cmd_get_err(&xfer->cmds[0]);
 
-	return 0;
+	return xfer->ret;
 }
 
 static int adi_i3c_master_i3c_xfers(struct i3c_dev_desc *dev,

-- 
2.51.1


-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 5/5] i3c: master: adi: Fix error propagation for CCCs
  2026-03-12 16:38 ` [PATCH v2 5/5] i3c: master: adi: Fix error propagation for CCCs Jorge Marques
@ 2026-03-12 19:58   ` Frank Li
  2026-03-13 18:46   ` Adrian Hunter
  1 sibling, 0 replies; 18+ messages in thread
From: Frank Li @ 2026-03-12 19:58 UTC (permalink / raw)
  To: Jorge Marques
  Cc: Alexandre Belloni, Przemysław Gaj, linux-i3c, linux-kernel,
	Dan Carpenter, Jonathan Cameron

On Thu, Mar 12, 2026 at 05:38:08PM +0100, Jorge Marques wrote:
> adi_i3c_master_send_ccc_cmd() always returned 0, ignoring the transfer
> result populated in the completion path. As a consequence, CCC command
> errors were silently dropped, including the default -ETIMEDOUT and
> later overwritten by adi_i3c_master_end_xfer_locked().
>
> Fix this by returning xfer->ret so that callers correctly receive any
> transfer error codes.
>
> Fixes: a79ac2cdc91d ("i3c: master: Add driver for Analog Devices I3C Controller IP")
> Signed-off-by: Jorge Marques <jorge.marques@analog.com>
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>

>  drivers/i3c/master/adi-i3c-master.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/i3c/master/adi-i3c-master.c b/drivers/i3c/master/adi-i3c-master.c
> index fb9a488304469..047081c9f0643 100644
> --- a/drivers/i3c/master/adi-i3c-master.c
> +++ b/drivers/i3c/master/adi-i3c-master.c
> @@ -361,7 +361,7 @@ static int adi_i3c_master_send_ccc_cmd(struct i3c_master_controller *m,
>
>  	cmd->err = adi_i3c_cmd_get_err(&xfer->cmds[0]);
>
> -	return 0;
> +	return xfer->ret;
>  }
>
>  static int adi_i3c_master_i3c_xfers(struct i3c_dev_desc *dev,
>
> --
> 2.51.1
>

-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 1/5] i3c: master: Move rstdaa error suppression
  2026-03-12 16:38 ` [PATCH v2 1/5] i3c: master: Move rstdaa error suppression Jorge Marques
@ 2026-03-13 18:43   ` Adrian Hunter
  2026-03-18 14:16   ` Frank Li
  1 sibling, 0 replies; 18+ messages in thread
From: Adrian Hunter @ 2026-03-13 18:43 UTC (permalink / raw)
  To: Jorge Marques, Alexandre Belloni, Frank Li, Przemysław Gaj
  Cc: linux-i3c, linux-kernel, Dan Carpenter, Jonathan Cameron

On 12/03/2026 18:38, Jorge Marques wrote:
> Prepares to fix improper Mx positive error propagation in later

Prepares -> Prepare

> commits by handling Mx error codes where the i3c_ccc_cmd command
> is allocated. Two of the four i3c_master_rstdaa_locked() are error
> paths that already suppressed the return value, the remaining two
> are changed to handle the I3C_ERROR_M2 Mx error code inside
> i3c_master_rstdaa_locked(), checking cmd->err directly.
> 
> Signed-off-by: Jorge Marques <jorge.marques@analog.com>

Minor cosmetic issue below.

Otherwise:

Reviewed-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
>  drivers/i3c/master.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> index 9e6be49bebb2c..c66f2655eb404 100644
> --- a/drivers/i3c/master.c
> +++ b/drivers/i3c/master.c
> @@ -1016,6 +1016,10 @@ static int i3c_master_rstdaa_locked(struct i3c_master_controller *master,
>  	ret = i3c_master_send_ccc_cmd_locked(master, &cmd);
>  	i3c_ccc_cmd_dest_cleanup(&dest);
>  
> +	/* No active devices on the bus. */
> +	if (ret && cmd.err == I3C_ERROR_M2)
> +		ret = 0;
> +
>  	return ret;
>  }
>  
> @@ -1796,8 +1800,6 @@ int i3c_master_do_daa_ext(struct i3c_master_controller *master, bool rstdaa)
>  
>  	if (rstdaa) {
>  		rstret = i3c_master_rstdaa_locked(master, I3C_BROADCAST_ADDR);
> -		if (rstret == I3C_ERROR_M2)
> -			rstret = 0;
>  	}

{} no longer needed

>  
>  	ret = master->ops->do_daa(master);
> @@ -2093,7 +2095,7 @@ static int i3c_master_bus_init(struct i3c_master_controller *master)
>  	 * (assigned by the bootloader for example).
>  	 */
>  	ret = i3c_master_rstdaa_locked(master, I3C_BROADCAST_ADDR);
> -	if (ret && ret != I3C_ERROR_M2)
> +	if (ret)
>  		goto err_bus_cleanup;
>  
>  	if (master->ops->set_speed) {
> 


-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 2/5] i3c: master: Move entdaa error suppression
  2026-03-12 16:38 ` [PATCH v2 2/5] i3c: master: Move entdaa " Jorge Marques
@ 2026-03-13 18:43   ` Adrian Hunter
  2026-03-18 14:17   ` Frank Li
  1 sibling, 0 replies; 18+ messages in thread
From: Adrian Hunter @ 2026-03-13 18:43 UTC (permalink / raw)
  To: Jorge Marques, Alexandre Belloni, Frank Li, Przemysław Gaj
  Cc: linux-i3c, linux-kernel, Dan Carpenter, Jonathan Cameron

On 12/03/2026 18:38, Jorge Marques wrote:
> Prepares to fix improper Mx positive error propagation in later commits

Prepares -> Prepare

> by handling Mx error codes where the i3c_ccc_cmd command is allocated.
> The CCC ENTDAA is invoked with i3c_master_entdaa_locked() and yields
> error I3C_ERROR_M2 if there are no devices active on the bus. Some
> controllers may also yield if there are no more devices need an dynamic
> address, since the sequence do always end in a NACK. Handle inside
> i3c_master_entdaa_locked(), checking cmd->err directly. Both call sites
> are updated, adi_i3c_master_do_daa() and cdns_i3c_master_do_daa().
> 
> Signed-off-by: Jorge Marques <jorge.marques@analog.com>

Reviewed-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
>  drivers/i3c/master.c                 | 4 ++++
>  drivers/i3c/master/adi-i3c-master.c  | 3 +--
>  drivers/i3c/master/i3c-master-cdns.c | 2 +-
>  3 files changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> index c66f2655eb404..d4f9e7df4adc5 100644
> --- a/drivers/i3c/master.c
> +++ b/drivers/i3c/master.c
> @@ -1050,6 +1050,10 @@ int i3c_master_entdaa_locked(struct i3c_master_controller *master)
>  	ret = i3c_master_send_ccc_cmd_locked(master, &cmd);
>  	i3c_ccc_cmd_dest_cleanup(&dest);
>  
> +	/* No active devices need an address. */
> +	if (ret && cmd.err == I3C_ERROR_M2)
> +		ret = 0;
> +
>  	return ret;
>  }
>  EXPORT_SYMBOL_GPL(i3c_master_entdaa_locked);
> diff --git a/drivers/i3c/master/adi-i3c-master.c b/drivers/i3c/master/adi-i3c-master.c
> index 6616f751075ae..fb9a488304469 100644
> --- a/drivers/i3c/master/adi-i3c-master.c
> +++ b/drivers/i3c/master/adi-i3c-master.c
> @@ -655,8 +655,7 @@ static int adi_i3c_master_do_daa(struct i3c_master_controller *m)
>  
>  	writel(irq_mask, master->regs + REG_IRQ_MASK);
>  
> -	/* DAA always finishes with CE2_ERROR or NACK_RESP */
> -	if (ret && ret != I3C_ERROR_M2)
> +	if (ret)
>  		return ret;
>  
>  	/* Add I3C devices discovered */
> diff --git a/drivers/i3c/master/i3c-master-cdns.c b/drivers/i3c/master/i3c-master-cdns.c
> index b78aebf6b2ca4..5cfec6761494d 100644
> --- a/drivers/i3c/master/i3c-master-cdns.c
> +++ b/drivers/i3c/master/i3c-master-cdns.c
> @@ -1143,7 +1143,7 @@ static int cdns_i3c_master_do_daa(struct i3c_master_controller *m)
>  	}
>  
>  	ret = i3c_master_entdaa_locked(&master->base);
> -	if (ret && ret != I3C_ERROR_M2)
> +	if (ret)
>  		return ret;
>  
>  	newdevs = readl(master->regs + DEVS_CTRL) & DEVS_CTRL_DEVS_ACTIVE_MASK;
> 


-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 3/5] i3c: master: Move bus_init error suppression
  2026-03-12 16:38 ` [PATCH v2 3/5] i3c: master: Move bus_init " Jorge Marques
@ 2026-03-13 18:45   ` Adrian Hunter
  2026-03-18 14:18   ` Frank Li
  1 sibling, 0 replies; 18+ messages in thread
From: Adrian Hunter @ 2026-03-13 18:45 UTC (permalink / raw)
  To: Jorge Marques, Alexandre Belloni, Frank Li, Przemysław Gaj
  Cc: linux-i3c, linux-kernel, Dan Carpenter, Jonathan Cameron

On 12/03/2026 18:38, Jorge Marques wrote:
> Prepares to fix improper Mx positive error propagation in later commits

Prepares -> Prepare

> by handling Mx error codes where the i3c_ccc_cmd command is allocated.
> The CCC DISEC to broadcast address is invoked with
> i3c_master_enec_disec_locked() and yields error I3C_ERROR_M2 if there
> are no devices active on the bus. This is expected at the bus
> initialization stage, where it is not known yet that there are no active
> devices on the bus. Add bool suppress_m2 argument to
> i3c_master_enec_disec_locked() and update the call site at
> i3c_master_bus_init() with the exact corner case to not require
> propagating positive Mx error codes. Other call site should not suppress
> the error code, for example, if a driver requests to peripheral to
> disable events and the transfer is not acknowledged, this is an error
> and should not proceed.
> 
> Signed-off-by: Jorge Marques <jorge.marques@analog.com>

Reviewed-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
>  drivers/i3c/master.c | 23 +++++++++++++++--------
>  1 file changed, 15 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> index d4f9e7df4adc5..bc1189afaed81 100644
> --- a/drivers/i3c/master.c
> +++ b/drivers/i3c/master.c
> @@ -1059,7 +1059,8 @@ int i3c_master_entdaa_locked(struct i3c_master_controller *master)
>  EXPORT_SYMBOL_GPL(i3c_master_entdaa_locked);
>  
>  static int i3c_master_enec_disec_locked(struct i3c_master_controller *master,
> -					u8 addr, bool enable, u8 evts)
> +					u8 addr, bool enable, u8 evts,
> +					bool suppress_m2)
>  {
>  	struct i3c_ccc_events *events;
>  	struct i3c_ccc_cmd_dest dest;
> @@ -1079,6 +1080,9 @@ static int i3c_master_enec_disec_locked(struct i3c_master_controller *master,
>  	ret = i3c_master_send_ccc_cmd_locked(master, &cmd);
>  	i3c_ccc_cmd_dest_cleanup(&dest);
>  
> +	if (suppress_m2 && ret && cmd.err == I3C_ERROR_M2)
> +		ret = 0;
> +
>  	return ret;
>  }
>  
> @@ -1099,7 +1103,7 @@ static int i3c_master_enec_disec_locked(struct i3c_master_controller *master,
>  int i3c_master_disec_locked(struct i3c_master_controller *master, u8 addr,
>  			    u8 evts)
>  {
> -	return i3c_master_enec_disec_locked(master, addr, false, evts);
> +	return i3c_master_enec_disec_locked(master, addr, false, evts, false);
>  }
>  EXPORT_SYMBOL_GPL(i3c_master_disec_locked);
>  
> @@ -1120,7 +1124,7 @@ EXPORT_SYMBOL_GPL(i3c_master_disec_locked);
>  int i3c_master_enec_locked(struct i3c_master_controller *master, u8 addr,
>  			   u8 evts)
>  {
> -	return i3c_master_enec_disec_locked(master, addr, true, evts);
> +	return i3c_master_enec_disec_locked(master, addr, true, evts, false);
>  }
>  EXPORT_SYMBOL_GPL(i3c_master_enec_locked);
>  
> @@ -2108,11 +2112,14 @@ static int i3c_master_bus_init(struct i3c_master_controller *master)
>  			goto err_bus_cleanup;
>  	}
>  
> -	/* Disable all slave events before starting DAA. */
> -	ret = i3c_master_disec_locked(master, I3C_BROADCAST_ADDR,
> -				      I3C_CCC_EVENT_SIR | I3C_CCC_EVENT_MR |
> -				      I3C_CCC_EVENT_HJ);
> -	if (ret && ret != I3C_ERROR_M2)
> +	/*
> +	 * Disable all slave events before starting DAA. When no active device
> +	 * is on the bus, returns Mx error code M2, this error is ignored.
> +	 */
> +	ret = i3c_master_enec_disec_locked(master, I3C_BROADCAST_ADDR, false,
> +					   I3C_CCC_EVENT_SIR | I3C_CCC_EVENT_MR |
> +					   I3C_CCC_EVENT_HJ, true);
> +	if (ret)
>  		goto err_bus_cleanup;
>  
>  	/*
> 


-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 4/5] i3c: master: Fix error codes at send_ccc_cmd
  2026-03-12 16:38 ` [PATCH v2 4/5] i3c: master: Fix error codes at send_ccc_cmd Jorge Marques
@ 2026-03-13 18:45   ` Adrian Hunter
  2026-03-23 16:04     ` Jorge Marques
  2026-03-18 14:27   ` Frank Li
  1 sibling, 1 reply; 18+ messages in thread
From: Adrian Hunter @ 2026-03-13 18:45 UTC (permalink / raw)
  To: Jorge Marques, Alexandre Belloni, Frank Li, Przemysław Gaj
  Cc: linux-i3c, linux-kernel, Dan Carpenter, Jonathan Cameron

On 12/03/2026 18:38, Jorge Marques wrote:
> i3c_master_send_ccc_cmd_locked would propagate cmd->err (positive,
> Mx codes) to the ret variable, cascading down multiple methods until
> reaching methods that explicitly stated they would return 0 on success
> or negative error code. For example, the call chain:
> 
>   i3c_device_enable_ibi <- i3c_dev_enable_ibi_locked <-
>   master->ops.enable_ibi <- i3c_master_enec_locked <-
>   i3c_master_enec_disec_locked <- i3c_master_send_ccc_cmd_locked
> 
> Fix this by returning the ret value, callers can
> still read the cmd->err value if ret is negative.
> 
> All corner cases where the Mx codes do need to be handled individually,
> are resolved in previous commits. Those corner cases are all scenarios
> when I3C_ERROR_M2 is expected and acceptable.

There needs to be a simple way to ensure the essential
prerequisite patches would be back ported also, if this
patch is back ported.  Could at least list their titles
here e.g.

The essential prerequisite patches for the fix are:
	i3c: master: Move rstdaa error suppression
	i3c: master: Move entdaa error suppression
	i3c: master: Move bus_init error suppression

> 
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Closes: https://lore.kernel.org/linux-iio/aYXvT5FW0hXQwhm_@stanley.mountain/
> Fixes: 3a379bbcea0a ("i3c: Add core I3C infrastructure")
> Signed-off-by: Jorge Marques <jorge.marques@analog.com>

Otherwise:

Reviewed-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
>  drivers/i3c/master.c | 32 +++++++++++++-------------------
>  1 file changed, 13 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> index bc1189afaed81..0752af5eb79b0 100644
> --- a/drivers/i3c/master.c
> +++ b/drivers/i3c/master.c
> @@ -898,11 +898,17 @@ static void i3c_ccc_cmd_init(struct i3c_ccc_cmd *cmd, bool rnw, u8 id,
>  	cmd->err = I3C_ERROR_UNKNOWN;
>  }
>  
> +/**
> + * i3c_master_send_ccc_cmd_locked() - send a CCC (Common Command Codes)
> + * @master: master used to send frames on the bus
> + * @cmd: command to send
> + *
> + * Return: 0 in case of success, or a negative error code otherwise.
> + *         I3C Mx error codes are stored in cmd->err.
> + */
>  static int i3c_master_send_ccc_cmd_locked(struct i3c_master_controller *master,
>  					  struct i3c_ccc_cmd *cmd)
>  {
> -	int ret;
> -
>  	if (!cmd || !master)
>  		return -EINVAL;
>  
> @@ -920,15 +926,7 @@ static int i3c_master_send_ccc_cmd_locked(struct i3c_master_controller *master,
>  	    !master->ops->supports_ccc_cmd(master, cmd))
>  		return -EOPNOTSUPP;
>  
> -	ret = master->ops->send_ccc_cmd(master, cmd);
> -	if (ret) {
> -		if (cmd->err != I3C_ERROR_UNKNOWN)
> -			return cmd->err;
> -
> -		return ret;
> -	}
> -
> -	return 0;
> +	return master->ops->send_ccc_cmd(master, cmd);
>  }
>  
>  static struct i2c_dev_desc *
> @@ -1036,8 +1034,7 @@ static int i3c_master_rstdaa_locked(struct i3c_master_controller *master,
>   *
>   * This function must be called with the bus lock held in write mode.
>   *
> - * Return: 0 in case of success, a positive I3C error code if the error is
> - * one of the official Mx error codes, and a negative error code otherwise.
> + * Return: 0 in case of success, or a negative error code otherwise.
>   */
>  int i3c_master_entdaa_locked(struct i3c_master_controller *master)
>  {
> @@ -1097,8 +1094,7 @@ static int i3c_master_enec_disec_locked(struct i3c_master_controller *master,
>   *
>   * This function must be called with the bus lock held in write mode.
>   *
> - * Return: 0 in case of success, a positive I3C error code if the error is
> - * one of the official Mx error codes, and a negative error code otherwise.
> + * Return: 0 in case of success, or a negative error code otherwise.
>   */
>  int i3c_master_disec_locked(struct i3c_master_controller *master, u8 addr,
>  			    u8 evts)
> @@ -1118,8 +1114,7 @@ EXPORT_SYMBOL_GPL(i3c_master_disec_locked);
>   *
>   * This function must be called with the bus lock held in write mode.
>   *
> - * Return: 0 in case of success, a positive I3C error code if the error is
> - * one of the official Mx error codes, and a negative error code otherwise.
> + * Return: 0 in case of success, or a negative error code otherwise.
>   */
>  int i3c_master_enec_locked(struct i3c_master_controller *master, u8 addr,
>  			   u8 evts)
> @@ -1144,8 +1139,7 @@ EXPORT_SYMBOL_GPL(i3c_master_enec_locked);
>   *
>   * This function must be called with the bus lock held in write mode.
>   *
> - * Return: 0 in case of success, a positive I3C error code if the error is
> - * one of the official Mx error codes, and a negative error code otherwise.
> + * Return: 0 in case of success, or a negative error code otherwise.
>   */
>  int i3c_master_defslvs_locked(struct i3c_master_controller *master)
>  {
> 


-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 5/5] i3c: master: adi: Fix error propagation for CCCs
  2026-03-12 16:38 ` [PATCH v2 5/5] i3c: master: adi: Fix error propagation for CCCs Jorge Marques
  2026-03-12 19:58   ` Frank Li
@ 2026-03-13 18:46   ` Adrian Hunter
  1 sibling, 0 replies; 18+ messages in thread
From: Adrian Hunter @ 2026-03-13 18:46 UTC (permalink / raw)
  To: Jorge Marques, Alexandre Belloni, Frank Li, Przemysław Gaj
  Cc: linux-i3c, linux-kernel, Dan Carpenter, Jonathan Cameron

On 12/03/2026 18:38, Jorge Marques wrote:
> adi_i3c_master_send_ccc_cmd() always returned 0, ignoring the transfer
> result populated in the completion path. As a consequence, CCC command
> errors were silently dropped, including the default -ETIMEDOUT and
> later overwritten by adi_i3c_master_end_xfer_locked().
> 
> Fix this by returning xfer->ret so that callers correctly receive any
> transfer error codes.
> 
> Fixes: a79ac2cdc91d ("i3c: master: Add driver for Analog Devices I3C Controller IP")
> Signed-off-by: Jorge Marques <jorge.marques@analog.com>

Reviewed-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
>  drivers/i3c/master/adi-i3c-master.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/i3c/master/adi-i3c-master.c b/drivers/i3c/master/adi-i3c-master.c
> index fb9a488304469..047081c9f0643 100644
> --- a/drivers/i3c/master/adi-i3c-master.c
> +++ b/drivers/i3c/master/adi-i3c-master.c
> @@ -361,7 +361,7 @@ static int adi_i3c_master_send_ccc_cmd(struct i3c_master_controller *m,
>  
>  	cmd->err = adi_i3c_cmd_get_err(&xfer->cmds[0]);
>  
> -	return 0;
> +	return xfer->ret;
>  }
>  
>  static int adi_i3c_master_i3c_xfers(struct i3c_dev_desc *dev,
> 


-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 1/5] i3c: master: Move rstdaa error suppression
  2026-03-12 16:38 ` [PATCH v2 1/5] i3c: master: Move rstdaa error suppression Jorge Marques
  2026-03-13 18:43   ` Adrian Hunter
@ 2026-03-18 14:16   ` Frank Li
  1 sibling, 0 replies; 18+ messages in thread
From: Frank Li @ 2026-03-18 14:16 UTC (permalink / raw)
  To: Jorge Marques
  Cc: Alexandre Belloni, Przemysław Gaj, linux-i3c, linux-kernel,
	Dan Carpenter, Jonathan Cameron

On Thu, Mar 12, 2026 at 05:38:04PM +0100, Jorge Marques wrote:
> Prepares to fix improper Mx positive error propagation in later
> commits by handling Mx error codes where the i3c_ccc_cmd command
> is allocated. Two of the four i3c_master_rstdaa_locked() are error
> paths that already suppressed the return value, the remaining two
> are changed to handle the I3C_ERROR_M2 Mx error code inside
> i3c_master_rstdaa_locked(), checking cmd->err directly.
>
> Signed-off-by: Jorge Marques <jorge.marques@analog.com>
> ---
Reviewed-by: Frank Li <Frank.Li@nxp.com>
>  drivers/i3c/master.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> index 9e6be49bebb2c..c66f2655eb404 100644
> --- a/drivers/i3c/master.c
> +++ b/drivers/i3c/master.c
> @@ -1016,6 +1016,10 @@ static int i3c_master_rstdaa_locked(struct i3c_master_controller *master,
>  	ret = i3c_master_send_ccc_cmd_locked(master, &cmd);
>  	i3c_ccc_cmd_dest_cleanup(&dest);
>
> +	/* No active devices on the bus. */
> +	if (ret && cmd.err == I3C_ERROR_M2)
> +		ret = 0;
> +
>  	return ret;
>  }
>
> @@ -1796,8 +1800,6 @@ int i3c_master_do_daa_ext(struct i3c_master_controller *master, bool rstdaa)
>
>  	if (rstdaa) {
>  		rstret = i3c_master_rstdaa_locked(master, I3C_BROADCAST_ADDR);
> -		if (rstret == I3C_ERROR_M2)
> -			rstret = 0;
>  	}
>
>  	ret = master->ops->do_daa(master);
> @@ -2093,7 +2095,7 @@ static int i3c_master_bus_init(struct i3c_master_controller *master)
>  	 * (assigned by the bootloader for example).
>  	 */
>  	ret = i3c_master_rstdaa_locked(master, I3C_BROADCAST_ADDR);
> -	if (ret && ret != I3C_ERROR_M2)
> +	if (ret)
>  		goto err_bus_cleanup;
>
>  	if (master->ops->set_speed) {
>
> --
> 2.51.1
>

-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 2/5] i3c: master: Move entdaa error suppression
  2026-03-12 16:38 ` [PATCH v2 2/5] i3c: master: Move entdaa " Jorge Marques
  2026-03-13 18:43   ` Adrian Hunter
@ 2026-03-18 14:17   ` Frank Li
  1 sibling, 0 replies; 18+ messages in thread
From: Frank Li @ 2026-03-18 14:17 UTC (permalink / raw)
  To: Jorge Marques
  Cc: Alexandre Belloni, Przemysław Gaj, linux-i3c, linux-kernel,
	Dan Carpenter, Jonathan Cameron

On Thu, Mar 12, 2026 at 05:38:05PM +0100, Jorge Marques wrote:
> Prepares to fix improper Mx positive error propagation in later commits
> by handling Mx error codes where the i3c_ccc_cmd command is allocated.
> The CCC ENTDAA is invoked with i3c_master_entdaa_locked() and yields
> error I3C_ERROR_M2 if there are no devices active on the bus. Some
> controllers may also yield if there are no more devices need an dynamic
> address, since the sequence do always end in a NACK. Handle inside
> i3c_master_entdaa_locked(), checking cmd->err directly. Both call sites
> are updated, adi_i3c_master_do_daa() and cdns_i3c_master_do_daa().
>
> Signed-off-by: Jorge Marques <jorge.marques@analog.com>
> ---
Reviewed-by: Frank Li <Frank.Li@nxp.com>
>  drivers/i3c/master.c                 | 4 ++++
>  drivers/i3c/master/adi-i3c-master.c  | 3 +--
>  drivers/i3c/master/i3c-master-cdns.c | 2 +-
>  3 files changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> index c66f2655eb404..d4f9e7df4adc5 100644
> --- a/drivers/i3c/master.c
> +++ b/drivers/i3c/master.c
> @@ -1050,6 +1050,10 @@ int i3c_master_entdaa_locked(struct i3c_master_controller *master)
>  	ret = i3c_master_send_ccc_cmd_locked(master, &cmd);
>  	i3c_ccc_cmd_dest_cleanup(&dest);
>
> +	/* No active devices need an address. */
> +	if (ret && cmd.err == I3C_ERROR_M2)
> +		ret = 0;
> +
>  	return ret;
>  }
>  EXPORT_SYMBOL_GPL(i3c_master_entdaa_locked);
> diff --git a/drivers/i3c/master/adi-i3c-master.c b/drivers/i3c/master/adi-i3c-master.c
> index 6616f751075ae..fb9a488304469 100644
> --- a/drivers/i3c/master/adi-i3c-master.c
> +++ b/drivers/i3c/master/adi-i3c-master.c
> @@ -655,8 +655,7 @@ static int adi_i3c_master_do_daa(struct i3c_master_controller *m)
>
>  	writel(irq_mask, master->regs + REG_IRQ_MASK);
>
> -	/* DAA always finishes with CE2_ERROR or NACK_RESP */
> -	if (ret && ret != I3C_ERROR_M2)
> +	if (ret)
>  		return ret;
>
>  	/* Add I3C devices discovered */
> diff --git a/drivers/i3c/master/i3c-master-cdns.c b/drivers/i3c/master/i3c-master-cdns.c
> index b78aebf6b2ca4..5cfec6761494d 100644
> --- a/drivers/i3c/master/i3c-master-cdns.c
> +++ b/drivers/i3c/master/i3c-master-cdns.c
> @@ -1143,7 +1143,7 @@ static int cdns_i3c_master_do_daa(struct i3c_master_controller *m)
>  	}
>
>  	ret = i3c_master_entdaa_locked(&master->base);
> -	if (ret && ret != I3C_ERROR_M2)
> +	if (ret)
>  		return ret;
>
>  	newdevs = readl(master->regs + DEVS_CTRL) & DEVS_CTRL_DEVS_ACTIVE_MASK;
>
> --
> 2.51.1
>

-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 3/5] i3c: master: Move bus_init error suppression
  2026-03-12 16:38 ` [PATCH v2 3/5] i3c: master: Move bus_init " Jorge Marques
  2026-03-13 18:45   ` Adrian Hunter
@ 2026-03-18 14:18   ` Frank Li
  1 sibling, 0 replies; 18+ messages in thread
From: Frank Li @ 2026-03-18 14:18 UTC (permalink / raw)
  To: Jorge Marques
  Cc: Alexandre Belloni, Przemysław Gaj, linux-i3c, linux-kernel,
	Dan Carpenter, Jonathan Cameron

On Thu, Mar 12, 2026 at 05:38:06PM +0100, Jorge Marques wrote:
> Prepares to fix improper Mx positive error propagation in later commits
> by handling Mx error codes where the i3c_ccc_cmd command is allocated.
> The CCC DISEC to broadcast address is invoked with
> i3c_master_enec_disec_locked() and yields error I3C_ERROR_M2 if there
> are no devices active on the bus. This is expected at the bus
> initialization stage, where it is not known yet that there are no active
> devices on the bus. Add bool suppress_m2 argument to
> i3c_master_enec_disec_locked() and update the call site at
> i3c_master_bus_init() with the exact corner case to not require
> propagating positive Mx error codes. Other call site should not suppress
> the error code, for example, if a driver requests to peripheral to
> disable events and the transfer is not acknowledged, this is an error
> and should not proceed.
>
> Signed-off-by: Jorge Marques <jorge.marques@analog.com>
> ---
Reviewed-by: Frank Li <Frank.Li@nxp.com>
>  drivers/i3c/master.c | 23 +++++++++++++++--------
>  1 file changed, 15 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> index d4f9e7df4adc5..bc1189afaed81 100644
> --- a/drivers/i3c/master.c
> +++ b/drivers/i3c/master.c
> @@ -1059,7 +1059,8 @@ int i3c_master_entdaa_locked(struct i3c_master_controller *master)
>  EXPORT_SYMBOL_GPL(i3c_master_entdaa_locked);
>
>  static int i3c_master_enec_disec_locked(struct i3c_master_controller *master,
> -					u8 addr, bool enable, u8 evts)
> +					u8 addr, bool enable, u8 evts,
> +					bool suppress_m2)
>  {
>  	struct i3c_ccc_events *events;
>  	struct i3c_ccc_cmd_dest dest;
> @@ -1079,6 +1080,9 @@ static int i3c_master_enec_disec_locked(struct i3c_master_controller *master,
>  	ret = i3c_master_send_ccc_cmd_locked(master, &cmd);
>  	i3c_ccc_cmd_dest_cleanup(&dest);
>
> +	if (suppress_m2 && ret && cmd.err == I3C_ERROR_M2)
> +		ret = 0;
> +
>  	return ret;
>  }
>
> @@ -1099,7 +1103,7 @@ static int i3c_master_enec_disec_locked(struct i3c_master_controller *master,
>  int i3c_master_disec_locked(struct i3c_master_controller *master, u8 addr,
>  			    u8 evts)
>  {
> -	return i3c_master_enec_disec_locked(master, addr, false, evts);
> +	return i3c_master_enec_disec_locked(master, addr, false, evts, false);
>  }
>  EXPORT_SYMBOL_GPL(i3c_master_disec_locked);
>
> @@ -1120,7 +1124,7 @@ EXPORT_SYMBOL_GPL(i3c_master_disec_locked);
>  int i3c_master_enec_locked(struct i3c_master_controller *master, u8 addr,
>  			   u8 evts)
>  {
> -	return i3c_master_enec_disec_locked(master, addr, true, evts);
> +	return i3c_master_enec_disec_locked(master, addr, true, evts, false);
>  }
>  EXPORT_SYMBOL_GPL(i3c_master_enec_locked);
>
> @@ -2108,11 +2112,14 @@ static int i3c_master_bus_init(struct i3c_master_controller *master)
>  			goto err_bus_cleanup;
>  	}
>
> -	/* Disable all slave events before starting DAA. */
> -	ret = i3c_master_disec_locked(master, I3C_BROADCAST_ADDR,
> -				      I3C_CCC_EVENT_SIR | I3C_CCC_EVENT_MR |
> -				      I3C_CCC_EVENT_HJ);
> -	if (ret && ret != I3C_ERROR_M2)
> +	/*
> +	 * Disable all slave events before starting DAA. When no active device
> +	 * is on the bus, returns Mx error code M2, this error is ignored.
> +	 */
> +	ret = i3c_master_enec_disec_locked(master, I3C_BROADCAST_ADDR, false,
> +					   I3C_CCC_EVENT_SIR | I3C_CCC_EVENT_MR |
> +					   I3C_CCC_EVENT_HJ, true);
> +	if (ret)
>  		goto err_bus_cleanup;
>
>  	/*
>
> --
> 2.51.1
>

-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 4/5] i3c: master: Fix error codes at send_ccc_cmd
  2026-03-12 16:38 ` [PATCH v2 4/5] i3c: master: Fix error codes at send_ccc_cmd Jorge Marques
  2026-03-13 18:45   ` Adrian Hunter
@ 2026-03-18 14:27   ` Frank Li
  2026-03-23 16:04     ` Jorge Marques
  1 sibling, 1 reply; 18+ messages in thread
From: Frank Li @ 2026-03-18 14:27 UTC (permalink / raw)
  To: Jorge Marques
  Cc: Alexandre Belloni, Przemysław Gaj, linux-i3c, linux-kernel,
	Dan Carpenter, Jonathan Cameron

On Thu, Mar 12, 2026 at 05:38:07PM +0100, Jorge Marques wrote:
> i3c_master_send_ccc_cmd_locked would propagate cmd->err (positive,

function name need (), i3c_dev_enable_ibi_locked(), check others.

> Mx codes) to the ret variable, cascading down multiple methods until
> reaching methods that explicitly stated they would return 0 on success
> or negative error code. For example, the call chain:
>
>   i3c_device_enable_ibi <- i3c_dev_enable_ibi_locked <-
>   master->ops.enable_ibi <- i3c_master_enec_locked <-
>   i3c_master_enec_disec_locked <- i3c_master_send_ccc_cmd_locked

why "<-" , look like should be "->" Or

	i3c_device_enable_ibi()
	i3c_dev_enable_ibi_locked()

function need (), i3c_dev_enable_ibi_locked(),

>
> Fix this by returning the ret value, callers can
> still read the cmd->err value if ret is negative.

Can you wrap at 75 char.
Fix this by returning the ret value, callers can still read the cmd->err
value if ret is negative.

Frank
>
> All corner cases where the Mx codes do need to be handled individually,
> are resolved in previous commits. Those corner cases are all scenarios
> when I3C_ERROR_M2 is expected and acceptable.
>
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Closes: https://lore.kernel.org/linux-iio/aYXvT5FW0hXQwhm_@stanley.mountain/
> Fixes: 3a379bbcea0a ("i3c: Add core I3C infrastructure")
> Signed-off-by: Jorge Marques <jorge.marques@analog.com>
> ---
>  drivers/i3c/master.c | 32 +++++++++++++-------------------
>  1 file changed, 13 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> index bc1189afaed81..0752af5eb79b0 100644
> --- a/drivers/i3c/master.c
> +++ b/drivers/i3c/master.c
> @@ -898,11 +898,17 @@ static void i3c_ccc_cmd_init(struct i3c_ccc_cmd *cmd, bool rnw, u8 id,
>  	cmd->err = I3C_ERROR_UNKNOWN;
>  }
>
> +/**
> + * i3c_master_send_ccc_cmd_locked() - send a CCC (Common Command Codes)
> + * @master: master used to send frames on the bus
> + * @cmd: command to send
> + *
> + * Return: 0 in case of success, or a negative error code otherwise.
> + *         I3C Mx error codes are stored in cmd->err.
> + */
>  static int i3c_master_send_ccc_cmd_locked(struct i3c_master_controller *master,
>  					  struct i3c_ccc_cmd *cmd)
>  {
> -	int ret;
> -
>  	if (!cmd || !master)
>  		return -EINVAL;
>
> @@ -920,15 +926,7 @@ static int i3c_master_send_ccc_cmd_locked(struct i3c_master_controller *master,
>  	    !master->ops->supports_ccc_cmd(master, cmd))
>  		return -EOPNOTSUPP;
>
> -	ret = master->ops->send_ccc_cmd(master, cmd);
> -	if (ret) {
> -		if (cmd->err != I3C_ERROR_UNKNOWN)
> -			return cmd->err;
> -
> -		return ret;
> -	}
> -
> -	return 0;
> +	return master->ops->send_ccc_cmd(master, cmd);
>  }
>
>  static struct i2c_dev_desc *
> @@ -1036,8 +1034,7 @@ static int i3c_master_rstdaa_locked(struct i3c_master_controller *master,
>   *
>   * This function must be called with the bus lock held in write mode.
>   *
> - * Return: 0 in case of success, a positive I3C error code if the error is
> - * one of the official Mx error codes, and a negative error code otherwise.
> + * Return: 0 in case of success, or a negative error code otherwise.
>   */
>  int i3c_master_entdaa_locked(struct i3c_master_controller *master)
>  {
> @@ -1097,8 +1094,7 @@ static int i3c_master_enec_disec_locked(struct i3c_master_controller *master,
>   *
>   * This function must be called with the bus lock held in write mode.
>   *
> - * Return: 0 in case of success, a positive I3C error code if the error is
> - * one of the official Mx error codes, and a negative error code otherwise.
> + * Return: 0 in case of success, or a negative error code otherwise.
>   */
>  int i3c_master_disec_locked(struct i3c_master_controller *master, u8 addr,
>  			    u8 evts)
> @@ -1118,8 +1114,7 @@ EXPORT_SYMBOL_GPL(i3c_master_disec_locked);
>   *
>   * This function must be called with the bus lock held in write mode.
>   *
> - * Return: 0 in case of success, a positive I3C error code if the error is
> - * one of the official Mx error codes, and a negative error code otherwise.
> + * Return: 0 in case of success, or a negative error code otherwise.
>   */
>  int i3c_master_enec_locked(struct i3c_master_controller *master, u8 addr,
>  			   u8 evts)
> @@ -1144,8 +1139,7 @@ EXPORT_SYMBOL_GPL(i3c_master_enec_locked);
>   *
>   * This function must be called with the bus lock held in write mode.
>   *
> - * Return: 0 in case of success, a positive I3C error code if the error is
> - * one of the official Mx error codes, and a negative error code otherwise.
> + * Return: 0 in case of success, or a negative error code otherwise.
>   */
>  int i3c_master_defslvs_locked(struct i3c_master_controller *master)
>  {
>
> --
> 2.51.1
>

-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 4/5] i3c: master: Fix error codes at send_ccc_cmd
  2026-03-13 18:45   ` Adrian Hunter
@ 2026-03-23 16:04     ` Jorge Marques
  0 siblings, 0 replies; 18+ messages in thread
From: Jorge Marques @ 2026-03-23 16:04 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: Jorge Marques, Alexandre Belloni, Frank Li, Przemysław Gaj,
	linux-i3c, linux-kernel, Dan Carpenter, Jonathan Cameron

On Fri, Mar 13, 2026 at 08:45:37PM +0200, Adrian Hunter wrote:
> On 12/03/2026 18:38, Jorge Marques wrote:
> > i3c_master_send_ccc_cmd_locked would propagate cmd->err (positive,
> > Mx codes) to the ret variable, cascading down multiple methods until
> > reaching methods that explicitly stated they would return 0 on success
> > or negative error code. For example, the call chain:
> > 
> >   i3c_device_enable_ibi <- i3c_dev_enable_ibi_locked <-
> >   master->ops.enable_ibi <- i3c_master_enec_locked <-
> >   i3c_master_enec_disec_locked <- i3c_master_send_ccc_cmd_locked
> > 
> > Fix this by returning the ret value, callers can
> > still read the cmd->err value if ret is negative.
> > 
> > All corner cases where the Mx codes do need to be handled individually,
> > are resolved in previous commits. Those corner cases are all scenarios
> > when I3C_ERROR_M2 is expected and acceptable.
> 
> There needs to be a simple way to ensure the essential
> prerequisite patches would be back ported also, if this
> patch is back ported.  Could at least list their titles
> here e.g.
> 
> The essential prerequisite patches for the fix are:
> 	i3c: master: Move rstdaa error suppression
> 	i3c: master: Move entdaa error suppression
> 	i3c: master: Move bus_init error suppression
> 

Ack all e-mails.

Regards,
Jorge
> > 
> > Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> > Closes: https://lore.kernel.org/linux-iio/aYXvT5FW0hXQwhm_@stanley.mountain/
> > Fixes: 3a379bbcea0a ("i3c: Add core I3C infrastructure")
> > Signed-off-by: Jorge Marques <jorge.marques@analog.com>
> 
> Otherwise:
> 
> Reviewed-by: Adrian Hunter <adrian.hunter@intel.com>
> 

-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 4/5] i3c: master: Fix error codes at send_ccc_cmd
  2026-03-18 14:27   ` Frank Li
@ 2026-03-23 16:04     ` Jorge Marques
  0 siblings, 0 replies; 18+ messages in thread
From: Jorge Marques @ 2026-03-23 16:04 UTC (permalink / raw)
  To: Frank Li
  Cc: Jorge Marques, Alexandre Belloni, Przemysław Gaj, linux-i3c,
	linux-kernel, Dan Carpenter, Jonathan Cameron

On Wed, Mar 18, 2026 at 10:27:09AM -0400, Frank Li wrote:
> On Thu, Mar 12, 2026 at 05:38:07PM +0100, Jorge Marques wrote:
> > i3c_master_send_ccc_cmd_locked would propagate cmd->err (positive,
> 
> function name need (), i3c_dev_enable_ibi_locked(), check others.
> 
> > Mx codes) to the ret variable, cascading down multiple methods until
> > reaching methods that explicitly stated they would return 0 on success
> > or negative error code. For example, the call chain:
> >
> >   i3c_device_enable_ibi <- i3c_dev_enable_ibi_locked <-
> >   master->ops.enable_ibi <- i3c_master_enec_locked <-
> >   i3c_master_enec_disec_locked <- i3c_master_send_ccc_cmd_locked
> 
> why "<-" , look like should be "->" Or
> 
> 	i3c_device_enable_ibi()
> 	i3c_dev_enable_ibi_locked()
> 
> function need (), i3c_dev_enable_ibi_locked(),
> 
> >
> > Fix this by returning the ret value, callers can
> > still read the cmd->err value if ret is negative.
> 
> Can you wrap at 75 char.
> Fix this by returning the ret value, callers can still read the cmd->err
> value if ret is negative.
> 
> Frank

Ack all review comments.

Regards,
Jorge

-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2026-03-23 16:05 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-12 16:38 [PATCH v2 0/5] Fix paths unexpectedly returning Mx error codes Jorge Marques
2026-03-12 16:38 ` [PATCH v2 1/5] i3c: master: Move rstdaa error suppression Jorge Marques
2026-03-13 18:43   ` Adrian Hunter
2026-03-18 14:16   ` Frank Li
2026-03-12 16:38 ` [PATCH v2 2/5] i3c: master: Move entdaa " Jorge Marques
2026-03-13 18:43   ` Adrian Hunter
2026-03-18 14:17   ` Frank Li
2026-03-12 16:38 ` [PATCH v2 3/5] i3c: master: Move bus_init " Jorge Marques
2026-03-13 18:45   ` Adrian Hunter
2026-03-18 14:18   ` Frank Li
2026-03-12 16:38 ` [PATCH v2 4/5] i3c: master: Fix error codes at send_ccc_cmd Jorge Marques
2026-03-13 18:45   ` Adrian Hunter
2026-03-23 16:04     ` Jorge Marques
2026-03-18 14:27   ` Frank Li
2026-03-23 16:04     ` Jorge Marques
2026-03-12 16:38 ` [PATCH v2 5/5] i3c: master: adi: Fix error propagation for CCCs Jorge Marques
2026-03-12 19:58   ` Frank Li
2026-03-13 18:46   ` Adrian Hunter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox