Skip to content

Commit ef8b522

Browse files
gastmaieralexandrebelloni
authored andcommitted
i3c: master: Fix error codes at send_ccc_cmd
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. The 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: 3a379bb ("i3c: Add core I3C infrastructure") Reviewed-by: Adrian Hunter <adrian.hunter@intel.com> Signed-off-by: Jorge Marques <jorge.marques@analog.com> Link: https://patch.msgid.link/20260323-ad4062-positive-error-fix-v3-4-30bdc68004be@analog.com Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
1 parent 49775af commit ef8b522

1 file changed

Lines changed: 13 additions & 19 deletions

File tree

drivers/i3c/master.c

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -925,11 +925,17 @@ static void i3c_ccc_cmd_init(struct i3c_ccc_cmd *cmd, bool rnw, u8 id,
925925
cmd->err = I3C_ERROR_UNKNOWN;
926926
}
927927

928+
/**
929+
* i3c_master_send_ccc_cmd_locked() - send a CCC (Common Command Codes)
930+
* @master: master used to send frames on the bus
931+
* @cmd: command to send
932+
*
933+
* Return: 0 in case of success, or a negative error code otherwise.
934+
* I3C Mx error codes are stored in cmd->err.
935+
*/
928936
static int i3c_master_send_ccc_cmd_locked(struct i3c_master_controller *master,
929937
struct i3c_ccc_cmd *cmd)
930938
{
931-
int ret;
932-
933939
if (!cmd || !master)
934940
return -EINVAL;
935941

@@ -947,15 +953,7 @@ static int i3c_master_send_ccc_cmd_locked(struct i3c_master_controller *master,
947953
!master->ops->supports_ccc_cmd(master, cmd))
948954
return -EOPNOTSUPP;
949955

950-
ret = master->ops->send_ccc_cmd(master, cmd);
951-
if (ret) {
952-
if (cmd->err != I3C_ERROR_UNKNOWN)
953-
return cmd->err;
954-
955-
return ret;
956-
}
957-
958-
return 0;
956+
return master->ops->send_ccc_cmd(master, cmd);
959957
}
960958

961959
static struct i2c_dev_desc *
@@ -1063,8 +1061,7 @@ static int i3c_master_rstdaa_locked(struct i3c_master_controller *master,
10631061
*
10641062
* This function must be called with the bus lock held in write mode.
10651063
*
1066-
* Return: 0 in case of success, a positive I3C error code if the error is
1067-
* one of the official Mx error codes, and a negative error code otherwise.
1064+
* Return: 0 in case of success, or a negative error code otherwise.
10681065
*/
10691066
int i3c_master_entdaa_locked(struct i3c_master_controller *master)
10701067
{
@@ -1124,8 +1121,7 @@ static int i3c_master_enec_disec_locked(struct i3c_master_controller *master,
11241121
*
11251122
* This function must be called with the bus lock held in write mode.
11261123
*
1127-
* Return: 0 in case of success, a positive I3C error code if the error is
1128-
* one of the official Mx error codes, and a negative error code otherwise.
1124+
* Return: 0 in case of success, or a negative error code otherwise.
11291125
*/
11301126
int i3c_master_disec_locked(struct i3c_master_controller *master, u8 addr,
11311127
u8 evts)
@@ -1145,8 +1141,7 @@ EXPORT_SYMBOL_GPL(i3c_master_disec_locked);
11451141
*
11461142
* This function must be called with the bus lock held in write mode.
11471143
*
1148-
* Return: 0 in case of success, a positive I3C error code if the error is
1149-
* one of the official Mx error codes, and a negative error code otherwise.
1144+
* Return: 0 in case of success, or a negative error code otherwise.
11501145
*/
11511146
int i3c_master_enec_locked(struct i3c_master_controller *master, u8 addr,
11521147
u8 evts)
@@ -1171,8 +1166,7 @@ EXPORT_SYMBOL_GPL(i3c_master_enec_locked);
11711166
*
11721167
* This function must be called with the bus lock held in write mode.
11731168
*
1174-
* Return: 0 in case of success, a positive I3C error code if the error is
1175-
* one of the official Mx error codes, and a negative error code otherwise.
1169+
* Return: 0 in case of success, or a negative error code otherwise.
11761170
*/
11771171
int i3c_master_defslvs_locked(struct i3c_master_controller *master)
11781172
{

0 commit comments

Comments
 (0)