Re: [PATCH v2 4/5] i3c: master: Fix error codes at send_ccc_cmd
From: Adrian Hunter
Date: Fri Mar 13 2026 - 14:47:21 EST
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@xxxxxxxxxx>
> Closes: https://lore.kernel.org/linux-iio/aYXvT5FW0hXQwhm_@stanley.mountain/
> Fixes: 3a379bbcea0a ("i3c: Add core I3C infrastructure")
> Signed-off-by: Jorge Marques <jorge.marques@xxxxxxxxxx>
Otherwise:
Reviewed-by: Adrian Hunter <adrian.hunter@xxxxxxxxx>
> ---
> 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)
> {
>