drivers/usb/typec/tipd/core.c:1159:17-18: WARNING opportunity for min() (fwd)

From: Julia Lawall
Date: Fri Jan 19 2024 - 12:29:39 EST


Just a suggestion. You could also consider that he code is readable
enough as is.

---------- Forwarded message ----------
Date: Sat, 20 Jan 2024 01:27:01 +0800
From: kernel test robot <lkp@xxxxxxxxx>
To: oe-kbuild@xxxxxxxxxxxxxxx
Cc: lkp@xxxxxxxxx, Julia Lawall <julia.lawall@xxxxxxxx>
Subject: drivers/usb/typec/tipd/core.c:1159:17-18: WARNING opportunity for min()

BCC: lkp@xxxxxxxxx
CC: oe-kbuild-all@xxxxxxxxxxxxxxx
CC: linux-kernel@xxxxxxxxxxxxxxx
TO: Javier Carrasco <javier.carrasco@xxxxxxxxxxxxxx>
CC: Heikki Krogerus <heikki.krogerus@xxxxxxxxxxxxxxx>

tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 9d1694dc91ce7b80bc96d6d8eaf1a1eca668d847
commit: 4c3ea81aa8e11400f24e5541bf46c2cadb4202e9 usb: typec: tipd: add patch update support for tps6598x
date: 2 weeks ago
:::::: branch date: 15 hours ago
:::::: commit date: 2 weeks ago
config: i386-randconfig-053-20240118 (https://download.01.org/0day-ci/archive/20240120/202401200150.XOjrMEhu-lkp@xxxxxxxxx/config)
compiler: ClangBuiltLinux clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@xxxxxxxxx>
| Reported-by: Julia Lawall <julia.lawall@xxxxxxxx>
| Closes: https://lore.kernel.org/r/202401200150.XOjrMEhu-lkp@xxxxxxxxx/

cocci warnings: (new ones prefixed by >>)
>> drivers/usb/typec/tipd/core.c:1159:17-18: WARNING opportunity for min()

vim +1159 drivers/usb/typec/tipd/core.c

7e7a3c815d22170 Abdel Alkuor 2023-10-03 1127
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1128 static int tps6598x_apply_patch(struct tps6598x *tps)
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1129 {
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1130 u8 in = TPS_PTCS_CONTENT_DEV | TPS_PTCS_CONTENT_APP;
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1131 u8 out[TPS_MAX_LEN] = {0};
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1132 size_t in_len = sizeof(in);
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1133 size_t copied_bytes = 0;
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1134 size_t bytes_left;
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1135 const struct firmware *fw;
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1136 const char *firmware_name;
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1137 int ret;
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1138
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1139 ret = device_property_read_string(tps->dev, "firmware-name",
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1140 &firmware_name);
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1141 if (ret)
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1142 return ret;
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1143
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1144 ret = tps_request_firmware(tps, &fw);
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1145 if (ret)
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1146 return ret;
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1147
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1148 ret = tps6598x_exec_cmd(tps, "PTCs", in_len, &in,
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1149 TPS_PTCS_OUT_BYTES, out);
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1150 if (ret || out[TPS_PTCS_STATUS] == TPS_PTCS_STATUS_FAIL) {
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1151 if (!ret)
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1152 ret = -EBUSY;
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1153 dev_err(tps->dev, "Update start failed (%d)\n", ret);
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1154 goto release_fw;
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1155 }
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1156
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1157 bytes_left = fw->size;
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1158 while (bytes_left) {
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 @1159 if (bytes_left < TPS_MAX_LEN)
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1160 in_len = bytes_left;
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1161 else
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1162 in_len = TPS_MAX_LEN;
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1163 ret = tps6598x_exec_cmd(tps, "PTCd", in_len,
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1164 fw->data + copied_bytes,
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1165 TPS_PTCD_OUT_BYTES, out);
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1166 if (ret || out[TPS_PTCD_TRANSFER_STATUS] ||
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1167 out[TPS_PTCD_LOADING_STATE] == TPS_PTCD_LOAD_ERR) {
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1168 if (!ret)
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1169 ret = -EBUSY;
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1170 dev_err(tps->dev, "Patch download failed (%d)\n", ret);
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1171 goto release_fw;
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1172 }
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1173 copied_bytes += in_len;
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1174 bytes_left -= in_len;
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1175 }
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1176
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1177 ret = tps6598x_exec_cmd(tps, "PTCc", 0, NULL, TPS_PTCC_OUT_BYTES, out);
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1178 if (ret || out[TPS_PTCC_DEV] || out[TPS_PTCC_APP]) {
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1179 if (!ret)
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1180 ret = -EBUSY;
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1181 dev_err(tps->dev, "Update completion failed (%d)\n", ret);
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1182 goto release_fw;
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1183 }
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1184 msleep(TPS_SETUP_MS);
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1185 dev_info(tps->dev, "Firmware update succeeded\n");
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1186
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1187 release_fw:
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1188 release_firmware(fw);
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1189
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1190 return ret;
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1191 };
4c3ea81aa8e1140 Javier Carrasco 2023-12-14 1192

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki