Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: 3a379bbcea0a ("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>

authored by

Jorge Marques and committed by
Alexandre Belloni
ef8b5229 49775afa

+13 -19
+13 -19
drivers/i3c/master.c
··· 925 925 cmd->err = I3C_ERROR_UNKNOWN; 926 926 } 927 927 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 + */ 928 936 static int i3c_master_send_ccc_cmd_locked(struct i3c_master_controller *master, 929 937 struct i3c_ccc_cmd *cmd) 930 938 { 931 - int ret; 932 - 933 939 if (!cmd || !master) 934 940 return -EINVAL; 935 941 ··· 953 947 !master->ops->supports_ccc_cmd(master, cmd)) 954 948 return -EOPNOTSUPP; 955 949 956 - ret = master->ops->send_ccc_cmd(master, cmd); 957 - if (ret) { 958 - if (cmd->err != I3C_ERROR_UNKNOWN) 959 - return cmd->err; 960 - 961 - return ret; 962 - } 963 - 964 - return 0; 950 + return master->ops->send_ccc_cmd(master, cmd); 965 951 } 966 952 967 953 static struct i2c_dev_desc * ··· 1061 1063 * 1062 1064 * This function must be called with the bus lock held in write mode. 1063 1065 * 1064 - * Return: 0 in case of success, a positive I3C error code if the error is 1065 - * one of the official Mx error codes, and a negative error code otherwise. 1066 + * Return: 0 in case of success, or a negative error code otherwise. 1066 1067 */ 1067 1068 int i3c_master_entdaa_locked(struct i3c_master_controller *master) 1068 1069 { ··· 1121 1124 * 1122 1125 * This function must be called with the bus lock held in write mode. 1123 1126 * 1124 - * Return: 0 in case of success, a positive I3C error code if the error is 1125 - * one of the official Mx error codes, and a negative error code otherwise. 1127 + * Return: 0 in case of success, or a negative error code otherwise. 1126 1128 */ 1127 1129 int i3c_master_disec_locked(struct i3c_master_controller *master, u8 addr, 1128 1130 u8 evts) ··· 1141 1145 * 1142 1146 * This function must be called with the bus lock held in write mode. 1143 1147 * 1144 - * Return: 0 in case of success, a positive I3C error code if the error is 1145 - * one of the official Mx error codes, and a negative error code otherwise. 1148 + * Return: 0 in case of success, or a negative error code otherwise. 1146 1149 */ 1147 1150 int i3c_master_enec_locked(struct i3c_master_controller *master, u8 addr, 1148 1151 u8 evts) ··· 1166 1171 * 1167 1172 * This function must be called with the bus lock held in write mode. 1168 1173 * 1169 - * Return: 0 in case of success, a positive I3C error code if the error is 1170 - * one of the official Mx error codes, and a negative error code otherwise. 1174 + * Return: 0 in case of success, or a negative error code otherwise. 1171 1175 */ 1172 1176 int i3c_master_defslvs_locked(struct i3c_master_controller *master) 1173 1177 {