public inbox for linux-i3c@lists.infradead.org
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: "Jorge Marques" <jorge.marques@analog.com>,
	"Alexandre Belloni" <alexandre.belloni@bootlin.com>,
	"Frank Li" <Frank.Li@nxp.com>,
	"Przemysław Gaj" <pgaj@cadence.com>
Cc: <linux-i3c@lists.infradead.org>, <linux-kernel@vger.kernel.org>,
	"Dan Carpenter" <dan.carpenter@linaro.org>,
	Jonathan Cameron <jic23@kernel.org>
Subject: Re: [PATCH 4/5] i3c: master: Negative error codes at send_ccc_cmd
Date: Tue, 10 Mar 2026 21:14:53 +0200	[thread overview]
Message-ID: <a8bac9d0-3d7e-4d9c-8066-e030dd221153@intel.com> (raw)
In-Reply-To: <20260308-ad4062-positive-error-fix-v1-4-72d3c5290b4a@analog.com>

On 08/03/2026 18:47, 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.

You should say something about how you know that is safe
to do. e.g. although there are myriad call paths, the code
never distinguishes positive from negative error codes except
in cases where it explicitly checks for I3C_ERROR_M2 and
those have been dealt with in the preparation patches.

> 
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Closes: https://lore.kernel.org/linux-iio/aYXvT5FW0hXQwhm_@stanley.mountain/

Fixes tag?

> 
> Signed-off-by: Jorge Marques <jorge.marques@analog.com>
> ---
>  drivers/i3c/master.c | 29 ++++++++++++-----------------
>  1 file changed, 12 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> index 3e465587c9c7..8459fffbdebb 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 *
> @@ -1101,8 +1099,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)
> @@ -1122,8 +1119,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)
> @@ -1148,8 +1144,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

  reply	other threads:[~2026-03-10 19:15 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-08 16:47 [PATCH 0/5] Fix paths unexpectedly returning Mx error codes Jorge Marques
2026-03-08 16:47 ` [PATCH 1/5] i3c: master: Move rstdaa error suppression Jorge Marques
2026-03-09 11:39   ` Adrian Hunter
2026-03-09 12:17     ` Jorge Marques
2026-03-09 12:34       ` Adrian Hunter
2026-03-10  8:05         ` Jorge Marques
2026-03-10 19:13           ` Adrian Hunter
2026-03-10 19:13   ` Adrian Hunter
2026-03-08 16:47 ` [PATCH 2/5] i3c: master: Move entdaa " Jorge Marques
2026-03-10 19:13   ` Adrian Hunter
2026-03-08 16:47 ` [PATCH 3/5] i3c: master: Move bus_init " Jorge Marques
2026-03-10 19:14   ` Adrian Hunter
2026-03-08 16:47 ` [PATCH 4/5] i3c: master: Negative error codes at send_ccc_cmd Jorge Marques
2026-03-10 19:14   ` Adrian Hunter [this message]
2026-03-08 16:47 ` [PATCH 5/5] i3c: master: adi: Return xfer->ret at send CCC Jorge Marques
2026-03-10 19:15   ` Adrian Hunter
2026-03-12 15:50     ` Jorge Marques

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a8bac9d0-3d7e-4d9c-8066-e030dd221153@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=Frank.Li@nxp.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=dan.carpenter@linaro.org \
    --cc=jic23@kernel.org \
    --cc=jorge.marques@analog.com \
    --cc=linux-i3c@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pgaj@cadence.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox