mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] USB: serial: io_ti: Use common error handling code in do_download_mode()
@ 2026-06-10 14:12 Markus Elfring
  2026-06-10 23:58 ` kernel test robot
  2026-06-11  2:26 ` kernel test robot
  0 siblings, 2 replies; 3+ messages in thread
From: Markus Elfring @ 2026-06-10 14:12 UTC (permalink / raw)
  To: linux-usb, Greg Kroah-Hartman, Johan Hovold
  Cc: LKML, kernel-janitors, Adrian Korwel, Felix Gu

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 10 Jun 2026 16:00:06 +0200

Use additional labels so that a bit of exception handling can be better
reused at the end of this function implementation.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/usb/serial/io_ti.c | 133 ++++++++++++++-----------------------
 1 file changed, 51 insertions(+), 82 deletions(-)

diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index 07c0eff3bef4..a83e3dd1e5ab 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -1103,23 +1103,21 @@ static int do_download_mode(struct edgeport_serial *serial,
 		return -ENOMEM;
 
 	status = get_manuf_info(serial, (u8 *)ti_manuf_desc);
-	if (status) {
-		kfree(ti_manuf_desc);
-		return status;
-	}
+	if (status)
+		goto free_ti_manuf_desc;
 
 	/* Check version number of ION descriptor */
 	if (!ignore_cpu_rev && ti_cpu_rev(ti_manuf_desc) < 2) {
 		dev_dbg(dev, "%s - Wrong CPU Rev %d (Must be 2)\n",
 			__func__, ti_cpu_rev(ti_manuf_desc));
-		kfree(ti_manuf_desc);
-		return -EINVAL;
+		status = -EINVAL;
+		goto free_ti_manuf_desc;
 	}
 
 	rom_desc = kmalloc_obj(*rom_desc);
 	if (!rom_desc) {
-		kfree(ti_manuf_desc);
-		return -ENOMEM;
+		status = -ENOMEM;
+		goto free_ti_manuf_desc;
 	}
 
 	/* Search for type 2 record (firmware record) */
@@ -1133,11 +1131,8 @@ static int do_download_mode(struct edgeport_serial *serial,
 				__func__);
 
 		firmware_version = kmalloc_obj(*firmware_version);
-		if (!firmware_version) {
-			kfree(rom_desc);
-			kfree(ti_manuf_desc);
-			return -ENOMEM;
-		}
+		if (!firmware_version)
+			goto e_nomem;
 
 		/*
 		 * Validate version number
@@ -1147,12 +1142,8 @@ static int do_download_mode(struct edgeport_serial *serial,
 				sizeof(struct ti_i2c_desc),
 				sizeof(struct ti_i2c_firmware_rec),
 				(u8 *)firmware_version);
-		if (status) {
-			kfree(firmware_version);
-			kfree(rom_desc);
-			kfree(ti_manuf_desc);
-			return status;
-		}
+		if (status)
+			goto free_firmware_version;
 
 		/*
 		 * Check version number of download with current
@@ -1182,10 +1173,8 @@ static int do_download_mode(struct edgeport_serial *serial,
 
 			record = kmalloc(1, GFP_KERNEL);
 			if (!record) {
-				kfree(firmware_version);
-				kfree(rom_desc);
-				kfree(ti_manuf_desc);
-				return -ENOMEM;
+				status = -ENOMEM;
+				goto free_firmware_version;
 			}
 			/*
 			 * In order to update the I2C firmware we must
@@ -1208,13 +1197,8 @@ static int do_download_mode(struct edgeport_serial *serial,
 			 */
 			status = write_rom(serial, start_address,
 					sizeof(*record), record);
-			if (status) {
-				kfree(record);
-				kfree(firmware_version);
-				kfree(rom_desc);
-				kfree(ti_manuf_desc);
-				return status;
-			}
+			if (status)
+				goto free_record;
 
 			/*
 			 * verify the write -- must do this in order
@@ -1225,22 +1209,13 @@ static int do_download_mode(struct edgeport_serial *serial,
 						start_address,
 						sizeof(*record),
 						record);
-			if (status) {
-				kfree(record);
-				kfree(firmware_version);
-				kfree(rom_desc);
-				kfree(ti_manuf_desc);
-				return status;
-			}
+			if (status)
+				goto free_record;
 
 			if (*record != I2C_DESC_TYPE_FIRMWARE_BLANK) {
 				dev_err(dev, "%s - error resetting device\n",
 						__func__);
-				kfree(record);
-				kfree(firmware_version);
-				kfree(rom_desc);
-				kfree(ti_manuf_desc);
-				return -ENODEV;
+				goto e_nodev;
 			}
 
 			dev_dbg(dev, "%s - HARDWARE RESET\n", __func__);
@@ -1255,11 +1230,7 @@ static int do_download_mode(struct edgeport_serial *serial,
 					__func__, status);
 
 			/* return an error on purpose. */
-			kfree(record);
-			kfree(firmware_version);
-			kfree(rom_desc);
-			kfree(ti_manuf_desc);
-			return -ENODEV;
+			goto e_nodev;
 		}
 		/* Same or newer fw version is already loaded */
 		serial->fw_version = download_cur_ver;
@@ -1276,18 +1247,13 @@ static int do_download_mode(struct edgeport_serial *serial,
 			u8 *vheader;
 
 			header = kmalloc(HEADER_SIZE, GFP_KERNEL);
-			if (!header) {
-				kfree(rom_desc);
-				kfree(ti_manuf_desc);
-				return -ENOMEM;
-			}
+			if (!header)
+				goto e_nomem;
 
 			vheader = kmalloc(HEADER_SIZE, GFP_KERNEL);
 			if (!vheader) {
 				kfree(header);
-				kfree(rom_desc);
-				kfree(ti_manuf_desc);
-				return -ENOMEM;
+				goto e_nomem;
 			}
 
 			dev_dbg(dev, "%s - Found Type BLANK FIRMWARE (Type F2) record\n",
@@ -1305,13 +1271,8 @@ static int do_download_mode(struct edgeport_serial *serial,
 			 * record type from 0xf2 to 0x02.
 			 */
 			status = build_i2c_fw_hdr(header, fw);
-			if (status) {
-				kfree(vheader);
-				kfree(header);
-				kfree(rom_desc);
-				kfree(ti_manuf_desc);
-				return -EINVAL;
-			}
+			if (status)
+				goto e_inval;
 
 			/*
 			 * Update I2C with type 0xf2 record with correct
@@ -1321,13 +1282,8 @@ static int do_download_mode(struct edgeport_serial *serial,
 						start_address,
 						HEADER_SIZE,
 						header);
-			if (status) {
-				kfree(vheader);
-				kfree(header);
-				kfree(rom_desc);
-				kfree(ti_manuf_desc);
-				return -EINVAL;
-			}
+			if (status)
+				goto e_inval;
 
 			/*
 			 * verify the write -- must do this in order for
@@ -1339,20 +1295,12 @@ static int do_download_mode(struct edgeport_serial *serial,
 			if (status) {
 				dev_dbg(dev, "%s - can't read header back\n",
 						__func__);
-				kfree(vheader);
-				kfree(header);
-				kfree(rom_desc);
-				kfree(ti_manuf_desc);
-				return status;
+				goto free_vheader;
 			}
 			if (memcmp(vheader, header, HEADER_SIZE)) {
 				dev_dbg(dev, "%s - write download record failed\n",
 						__func__);
-				kfree(vheader);
-				kfree(header);
-				kfree(rom_desc);
-				kfree(ti_manuf_desc);
-				return -EINVAL;
+				goto e_inval;
 			}
 
 			kfree(vheader);
@@ -1372,9 +1320,7 @@ static int do_download_mode(struct edgeport_serial *serial,
 				dev_err(dev,
 					"%s - UMPC_COPY_DNLD_TO_I2C failed\n",
 					__func__);
-				kfree(rom_desc);
-				kfree(ti_manuf_desc);
-				return status;
+				goto free_rom_desc;
 			}
 		}
 	}
@@ -1383,6 +1329,29 @@ static int do_download_mode(struct edgeport_serial *serial,
 	kfree(rom_desc);
 	kfree(ti_manuf_desc);
 	return 0;
+
+e_inval:
+	status = -EINVAL;
+free_vheader:
+	kfree(vheader);
+	kfree(header);
+	goto free_rom_desc;
+
+e_nomem:
+	status = -ENOMEM;
+	goto free_rom_desc;
+
+e_nodev:
+	status = -ENODEV;
+free_record:
+	kfree(record);
+free_firmware_version:
+	kfree(firmware_version);
+free_rom_desc:
+	kfree(rom_desc);
+free_ti_manuf_desc:
+	kfree(ti_manuf_desc);
+	return status;
 }
 
 static int do_boot_mode(struct edgeport_serial *serial,
-- 
2.54.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] USB: serial: io_ti: Use common error handling code in do_download_mode()
  2026-06-10 14:12 [PATCH] USB: serial: io_ti: Use common error handling code in do_download_mode() Markus Elfring
@ 2026-06-10 23:58 ` kernel test robot
  2026-06-11  2:26 ` kernel test robot
  1 sibling, 0 replies; 3+ messages in thread
From: kernel test robot @ 2026-06-10 23:58 UTC (permalink / raw)
  To: Markus Elfring, linux-usb, Greg Kroah-Hartman, Johan Hovold
  Cc: oe-kbuild-all, LKML, kernel-janitors, Adrian Korwel, Felix Gu

Hi Markus,

kernel test robot noticed the following build errors:

[auto build test ERROR on johan-usb-serial/usb-next]
[also build test ERROR on johan-usb-serial/usb-linus usb/usb-testing usb/usb-next usb/usb-linus westeri-thunderbolt/next linus/master v7.1-rc7 next-20260609]
[cannot apply to peter-chen-usb/for-usb-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Markus-Elfring/USB-serial-io_ti-Use-common-error-handling-code-in-do_download_mode/20260610-232603
base:   https://git.kernel.org/pub/scm/linux/kernel/git/johan/usb-serial.git usb-next
patch link:    https://lore.kernel.org/r/188a2ea8-6bb6-46aa-883d-a1472b35217f%40web.de
patch subject: [PATCH] USB: serial: io_ti: Use common error handling code in do_download_mode()
config: powerpc-randconfig-002-20260611 (https://download.01.org/0day-ci/archive/20260611/202606110758.5k78JhiV-lkp@intel.com/config)
compiler: powerpc-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260611/202606110758.5k78JhiV-lkp@intel.com/reproduce)

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@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202606110758.5k78JhiV-lkp@intel.com/

All errors (new ones prefixed by >>):

   drivers/usb/serial/io_ti.c: In function 'do_download_mode':
>> drivers/usb/serial/io_ti.c:1325:8: error: 'vheader' undeclared (first use in this function); did you mean 'freader'?
     kfree(vheader);
           ^~~~~~~
           freader
   drivers/usb/serial/io_ti.c:1325:8: note: each undeclared identifier is reported only once for each function it appears in
>> drivers/usb/serial/io_ti.c:1326:8: error: 'header' undeclared (first use in this function); did you mean 'freader'?
     kfree(header);
           ^~~~~~
           freader
>> drivers/usb/serial/io_ti.c:1336:8: error: 'record' undeclared (first use in this function); did you mean 'ror8'?
     kfree(record);
           ^~~~~~
           ror8
>> drivers/usb/serial/io_ti.c:1338:8: error: 'firmware_version' undeclared (first use in this function); did you mean 'free_firmware_version'?
     kfree(firmware_version);
           ^~~~~~~~~~~~~~~~
           free_firmware_version


vim +1325 drivers/usb/serial/io_ti.c

  1065	
  1066	static int do_download_mode(struct edgeport_serial *serial,
  1067			const struct firmware *fw)
  1068	{
  1069		struct device *dev = &serial->serial->interface->dev;
  1070		int status = 0;
  1071		int start_address;
  1072		struct edge_ti_manuf_descriptor *ti_manuf_desc;
  1073		int download_cur_ver;
  1074		int download_new_ver;
  1075		struct edgeport_fw_hdr *fw_hdr = (struct edgeport_fw_hdr *)fw->data;
  1076		struct ti_i2c_desc *rom_desc;
  1077	
  1078		dev_dbg(dev, "%s - RUNNING IN DOWNLOAD MODE\n", __func__);
  1079	
  1080		status = check_i2c_image(serial);
  1081		if (status) {
  1082			dev_dbg(dev, "%s - DOWNLOAD MODE -- BAD I2C\n", __func__);
  1083			return status;
  1084		}
  1085	
  1086		/*
  1087		 * Validate Hardware version number
  1088		 * Read Manufacturing Descriptor from TI Based Edgeport
  1089		 */
  1090		ti_manuf_desc = kmalloc_obj(*ti_manuf_desc);
  1091		if (!ti_manuf_desc)
  1092			return -ENOMEM;
  1093	
  1094		status = get_manuf_info(serial, (u8 *)ti_manuf_desc);
  1095		if (status)
  1096			goto free_ti_manuf_desc;
  1097	
  1098		/* Check version number of ION descriptor */
  1099		if (!ignore_cpu_rev && ti_cpu_rev(ti_manuf_desc) < 2) {
  1100			dev_dbg(dev, "%s - Wrong CPU Rev %d (Must be 2)\n",
  1101				__func__, ti_cpu_rev(ti_manuf_desc));
  1102			status = -EINVAL;
  1103			goto free_ti_manuf_desc;
  1104		}
  1105	
  1106		rom_desc = kmalloc_obj(*rom_desc);
  1107		if (!rom_desc) {
  1108			status = -ENOMEM;
  1109			goto free_ti_manuf_desc;
  1110		}
  1111	
  1112		/* Search for type 2 record (firmware record) */
  1113		start_address = get_descriptor_addr(serial,
  1114				I2C_DESC_TYPE_FIRMWARE_BASIC, rom_desc);
  1115		if (start_address != 0) {
  1116			struct ti_i2c_firmware_rec *firmware_version;
  1117			u8 *record;
  1118	
  1119			dev_dbg(dev, "%s - Found Type FIRMWARE (Type 2) record\n",
  1120					__func__);
  1121	
  1122			firmware_version = kmalloc_obj(*firmware_version);
  1123			if (!firmware_version)
  1124				goto e_nomem;
  1125	
  1126			/*
  1127			 * Validate version number
  1128			 * Read the descriptor data
  1129			 */
  1130			status = read_rom(serial, start_address +
  1131					sizeof(struct ti_i2c_desc),
  1132					sizeof(struct ti_i2c_firmware_rec),
  1133					(u8 *)firmware_version);
  1134			if (status)
  1135				goto free_firmware_version;
  1136	
  1137			/*
  1138			 * Check version number of download with current
  1139			 * version in I2c
  1140			 */
  1141			download_cur_ver = (firmware_version->Ver_Major << 8) +
  1142					   (firmware_version->Ver_Minor);
  1143			download_new_ver = (fw_hdr->major_version << 8) +
  1144					   (fw_hdr->minor_version);
  1145	
  1146			dev_dbg(dev, "%s - >> FW Versions Device %d.%d  Driver %d.%d\n",
  1147				__func__, firmware_version->Ver_Major,
  1148				firmware_version->Ver_Minor,
  1149				fw_hdr->major_version, fw_hdr->minor_version);
  1150	
  1151			/*
  1152			 * Check if we have an old version in the I2C and
  1153			 * update if necessary
  1154			 */
  1155			if (download_cur_ver < download_new_ver) {
  1156				dev_dbg(dev, "%s - Update I2C dld from %d.%d to %d.%d\n",
  1157					__func__,
  1158					firmware_version->Ver_Major,
  1159					firmware_version->Ver_Minor,
  1160					fw_hdr->major_version,
  1161					fw_hdr->minor_version);
  1162	
  1163				record = kmalloc(1, GFP_KERNEL);
  1164				if (!record) {
  1165					status = -ENOMEM;
  1166					goto free_firmware_version;
  1167				}
  1168				/*
  1169				 * In order to update the I2C firmware we must
  1170				 * change the type 2 record to type 0xF2. This
  1171				 * will force the UMP to come up in Boot Mode.
  1172				 * Then while in boot mode, the driver will
  1173				 * download the latest firmware (padded to
  1174				 * 15.5k) into the UMP ram. Finally when the
  1175				 * device comes back up in download mode the
  1176				 * driver will cause the new firmware to be
  1177				 * copied from the UMP Ram to I2C and the
  1178				 * firmware will update the record type from
  1179				 * 0xf2 to 0x02.
  1180				 */
  1181				*record = I2C_DESC_TYPE_FIRMWARE_BLANK;
  1182	
  1183				/*
  1184				 * Change the I2C Firmware record type to
  1185				 * 0xf2 to trigger an update
  1186				 */
  1187				status = write_rom(serial, start_address,
  1188						sizeof(*record), record);
  1189				if (status)
  1190					goto free_record;
  1191	
  1192				/*
  1193				 * verify the write -- must do this in order
  1194				 * for write to complete before we do the
  1195				 * hardware reset
  1196				 */
  1197				status = read_rom(serial,
  1198							start_address,
  1199							sizeof(*record),
  1200							record);
  1201				if (status)
  1202					goto free_record;
  1203	
  1204				if (*record != I2C_DESC_TYPE_FIRMWARE_BLANK) {
  1205					dev_err(dev, "%s - error resetting device\n",
  1206							__func__);
  1207					goto e_nodev;
  1208				}
  1209	
  1210				dev_dbg(dev, "%s - HARDWARE RESET\n", __func__);
  1211	
  1212				/* Reset UMP -- Back to BOOT MODE */
  1213				status = ti_vsend_sync(serial->serial->dev,
  1214						UMPC_HARDWARE_RESET,
  1215						0, 0, NULL, 0,
  1216						TI_VSEND_TIMEOUT_DEFAULT);
  1217	
  1218				dev_dbg(dev, "%s - HARDWARE RESET return %d\n",
  1219						__func__, status);
  1220	
  1221				/* return an error on purpose. */
  1222				goto e_nodev;
  1223			}
  1224			/* Same or newer fw version is already loaded */
  1225			serial->fw_version = download_cur_ver;
  1226			kfree(firmware_version);
  1227		}
  1228		/* Search for type 0xF2 record (firmware blank record) */
  1229		else {
  1230			start_address = get_descriptor_addr(serial,
  1231					I2C_DESC_TYPE_FIRMWARE_BLANK, rom_desc);
  1232			if (start_address != 0) {
  1233	#define HEADER_SIZE	(sizeof(struct ti_i2c_desc) + \
  1234					sizeof(struct ti_i2c_firmware_rec))
  1235				u8 *header;
  1236				u8 *vheader;
  1237	
  1238				header = kmalloc(HEADER_SIZE, GFP_KERNEL);
  1239				if (!header)
  1240					goto e_nomem;
  1241	
  1242				vheader = kmalloc(HEADER_SIZE, GFP_KERNEL);
  1243				if (!vheader) {
  1244					kfree(header);
  1245					goto e_nomem;
  1246				}
  1247	
  1248				dev_dbg(dev, "%s - Found Type BLANK FIRMWARE (Type F2) record\n",
  1249						__func__);
  1250	
  1251				/*
  1252				 * In order to update the I2C firmware we must change
  1253				 * the type 2 record to type 0xF2. This will force the
  1254				 * UMP to come up in Boot Mode.  Then while in boot
  1255				 * mode, the driver will download the latest firmware
  1256				 * (padded to 15.5k) into the UMP ram. Finally when the
  1257				 * device comes back up in download mode the driver
  1258				 * will cause the new firmware to be copied from the
  1259				 * UMP Ram to I2C and the firmware will update the
  1260				 * record type from 0xf2 to 0x02.
  1261				 */
  1262				status = build_i2c_fw_hdr(header, fw);
  1263				if (status)
  1264					goto e_inval;
  1265	
  1266				/*
  1267				 * Update I2C with type 0xf2 record with correct
  1268				 * size and checksum
  1269				 */
  1270				status = write_rom(serial,
  1271							start_address,
  1272							HEADER_SIZE,
  1273							header);
  1274				if (status)
  1275					goto e_inval;
  1276	
  1277				/*
  1278				 * verify the write -- must do this in order for
  1279				 * write to complete before we do the hardware reset
  1280				 */
  1281				status = read_rom(serial, start_address,
  1282								HEADER_SIZE, vheader);
  1283	
  1284				if (status) {
  1285					dev_dbg(dev, "%s - can't read header back\n",
  1286							__func__);
  1287					goto free_vheader;
  1288				}
  1289				if (memcmp(vheader, header, HEADER_SIZE)) {
  1290					dev_dbg(dev, "%s - write download record failed\n",
  1291							__func__);
  1292					goto e_inval;
  1293				}
  1294	
  1295				kfree(vheader);
  1296				kfree(header);
  1297	
  1298				dev_dbg(dev, "%s - Start firmware update\n", __func__);
  1299	
  1300				/* Tell firmware to copy download image into I2C */
  1301				status = ti_vsend_sync(serial->serial->dev,
  1302						UMPC_COPY_DNLD_TO_I2C,
  1303						0, 0, NULL, 0,
  1304						TI_VSEND_TIMEOUT_FW_DOWNLOAD);
  1305	
  1306				dev_dbg(dev, "%s - Update complete 0x%x\n", __func__,
  1307						status);
  1308				if (status) {
  1309					dev_err(dev,
  1310						"%s - UMPC_COPY_DNLD_TO_I2C failed\n",
  1311						__func__);
  1312					goto free_rom_desc;
  1313				}
  1314			}
  1315		}
  1316	
  1317		/* The device is running the download code */
  1318		kfree(rom_desc);
  1319		kfree(ti_manuf_desc);
  1320		return 0;
  1321	
  1322	e_inval:
  1323		status = -EINVAL;
  1324	free_vheader:
> 1325		kfree(vheader);
> 1326		kfree(header);
  1327		goto free_rom_desc;
  1328	
  1329	e_nomem:
  1330		status = -ENOMEM;
  1331		goto free_rom_desc;
  1332	
  1333	e_nodev:
  1334		status = -ENODEV;
  1335	free_record:
> 1336		kfree(record);
  1337	free_firmware_version:
> 1338		kfree(firmware_version);
  1339	free_rom_desc:
  1340		kfree(rom_desc);
  1341	free_ti_manuf_desc:
  1342		kfree(ti_manuf_desc);
  1343		return status;
  1344	}
  1345	

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] USB: serial: io_ti: Use common error handling code in do_download_mode()
  2026-06-10 14:12 [PATCH] USB: serial: io_ti: Use common error handling code in do_download_mode() Markus Elfring
  2026-06-10 23:58 ` kernel test robot
@ 2026-06-11  2:26 ` kernel test robot
  1 sibling, 0 replies; 3+ messages in thread
From: kernel test robot @ 2026-06-11  2:26 UTC (permalink / raw)
  To: Markus Elfring, linux-usb, Greg Kroah-Hartman, Johan Hovold
  Cc: llvm, oe-kbuild-all, LKML, kernel-janitors, Adrian Korwel, Felix Gu

Hi Markus,

kernel test robot noticed the following build errors:

[auto build test ERROR on johan-usb-serial/usb-next]
[also build test ERROR on johan-usb-serial/usb-linus usb/usb-testing usb/usb-next usb/usb-linus westeri-thunderbolt/next linus/master v7.1-rc7 next-20260609]
[cannot apply to peter-chen-usb/for-usb-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Markus-Elfring/USB-serial-io_ti-Use-common-error-handling-code-in-do_download_mode/20260610-232603
base:   https://git.kernel.org/pub/scm/linux/kernel/git/johan/usb-serial.git usb-next
patch link:    https://lore.kernel.org/r/188a2ea8-6bb6-46aa-883d-a1472b35217f%40web.de
patch subject: [PATCH] USB: serial: io_ti: Use common error handling code in do_download_mode()
config: i386-buildonly-randconfig-003-20260611 (https://download.01.org/0day-ci/archive/20260611/202606111021.E9ag1FLC-lkp@intel.com/config)
compiler: clang version 22.1.3 (https://github.com/llvm/llvm-project e9846648fd6183ee6d8cbdb4502213fcf902a211)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260611/202606111021.E9ag1FLC-lkp@intel.com/reproduce)

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@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202606111021.E9ag1FLC-lkp@intel.com/

All errors (new ones prefixed by >>):

>> drivers/usb/serial/io_ti.c:1325:8: error: use of undeclared identifier 'vheader'
    1325 |         kfree(vheader);
         |               ^~~~~~~
>> drivers/usb/serial/io_ti.c:1326:8: error: use of undeclared identifier 'header'
    1326 |         kfree(header);
         |               ^~~~~~
>> drivers/usb/serial/io_ti.c:1336:8: error: use of undeclared identifier 'record'
    1336 |         kfree(record);
         |               ^~~~~~
>> drivers/usb/serial/io_ti.c:1338:8: error: use of undeclared identifier 'firmware_version'
    1338 |         kfree(firmware_version);
         |               ^~~~~~~~~~~~~~~~
   4 errors generated.


vim +/vheader +1325 drivers/usb/serial/io_ti.c

  1065	
  1066	static int do_download_mode(struct edgeport_serial *serial,
  1067			const struct firmware *fw)
  1068	{
  1069		struct device *dev = &serial->serial->interface->dev;
  1070		int status = 0;
  1071		int start_address;
  1072		struct edge_ti_manuf_descriptor *ti_manuf_desc;
  1073		int download_cur_ver;
  1074		int download_new_ver;
  1075		struct edgeport_fw_hdr *fw_hdr = (struct edgeport_fw_hdr *)fw->data;
  1076		struct ti_i2c_desc *rom_desc;
  1077	
  1078		dev_dbg(dev, "%s - RUNNING IN DOWNLOAD MODE\n", __func__);
  1079	
  1080		status = check_i2c_image(serial);
  1081		if (status) {
  1082			dev_dbg(dev, "%s - DOWNLOAD MODE -- BAD I2C\n", __func__);
  1083			return status;
  1084		}
  1085	
  1086		/*
  1087		 * Validate Hardware version number
  1088		 * Read Manufacturing Descriptor from TI Based Edgeport
  1089		 */
  1090		ti_manuf_desc = kmalloc_obj(*ti_manuf_desc);
  1091		if (!ti_manuf_desc)
  1092			return -ENOMEM;
  1093	
  1094		status = get_manuf_info(serial, (u8 *)ti_manuf_desc);
  1095		if (status)
  1096			goto free_ti_manuf_desc;
  1097	
  1098		/* Check version number of ION descriptor */
  1099		if (!ignore_cpu_rev && ti_cpu_rev(ti_manuf_desc) < 2) {
  1100			dev_dbg(dev, "%s - Wrong CPU Rev %d (Must be 2)\n",
  1101				__func__, ti_cpu_rev(ti_manuf_desc));
  1102			status = -EINVAL;
  1103			goto free_ti_manuf_desc;
  1104		}
  1105	
  1106		rom_desc = kmalloc_obj(*rom_desc);
  1107		if (!rom_desc) {
  1108			status = -ENOMEM;
  1109			goto free_ti_manuf_desc;
  1110		}
  1111	
  1112		/* Search for type 2 record (firmware record) */
  1113		start_address = get_descriptor_addr(serial,
  1114				I2C_DESC_TYPE_FIRMWARE_BASIC, rom_desc);
  1115		if (start_address != 0) {
  1116			struct ti_i2c_firmware_rec *firmware_version;
  1117			u8 *record;
  1118	
  1119			dev_dbg(dev, "%s - Found Type FIRMWARE (Type 2) record\n",
  1120					__func__);
  1121	
  1122			firmware_version = kmalloc_obj(*firmware_version);
  1123			if (!firmware_version)
  1124				goto e_nomem;
  1125	
  1126			/*
  1127			 * Validate version number
  1128			 * Read the descriptor data
  1129			 */
  1130			status = read_rom(serial, start_address +
  1131					sizeof(struct ti_i2c_desc),
  1132					sizeof(struct ti_i2c_firmware_rec),
  1133					(u8 *)firmware_version);
  1134			if (status)
  1135				goto free_firmware_version;
  1136	
  1137			/*
  1138			 * Check version number of download with current
  1139			 * version in I2c
  1140			 */
  1141			download_cur_ver = (firmware_version->Ver_Major << 8) +
  1142					   (firmware_version->Ver_Minor);
  1143			download_new_ver = (fw_hdr->major_version << 8) +
  1144					   (fw_hdr->minor_version);
  1145	
  1146			dev_dbg(dev, "%s - >> FW Versions Device %d.%d  Driver %d.%d\n",
  1147				__func__, firmware_version->Ver_Major,
  1148				firmware_version->Ver_Minor,
  1149				fw_hdr->major_version, fw_hdr->minor_version);
  1150	
  1151			/*
  1152			 * Check if we have an old version in the I2C and
  1153			 * update if necessary
  1154			 */
  1155			if (download_cur_ver < download_new_ver) {
  1156				dev_dbg(dev, "%s - Update I2C dld from %d.%d to %d.%d\n",
  1157					__func__,
  1158					firmware_version->Ver_Major,
  1159					firmware_version->Ver_Minor,
  1160					fw_hdr->major_version,
  1161					fw_hdr->minor_version);
  1162	
  1163				record = kmalloc(1, GFP_KERNEL);
  1164				if (!record) {
  1165					status = -ENOMEM;
  1166					goto free_firmware_version;
  1167				}
  1168				/*
  1169				 * In order to update the I2C firmware we must
  1170				 * change the type 2 record to type 0xF2. This
  1171				 * will force the UMP to come up in Boot Mode.
  1172				 * Then while in boot mode, the driver will
  1173				 * download the latest firmware (padded to
  1174				 * 15.5k) into the UMP ram. Finally when the
  1175				 * device comes back up in download mode the
  1176				 * driver will cause the new firmware to be
  1177				 * copied from the UMP Ram to I2C and the
  1178				 * firmware will update the record type from
  1179				 * 0xf2 to 0x02.
  1180				 */
  1181				*record = I2C_DESC_TYPE_FIRMWARE_BLANK;
  1182	
  1183				/*
  1184				 * Change the I2C Firmware record type to
  1185				 * 0xf2 to trigger an update
  1186				 */
  1187				status = write_rom(serial, start_address,
  1188						sizeof(*record), record);
  1189				if (status)
  1190					goto free_record;
  1191	
  1192				/*
  1193				 * verify the write -- must do this in order
  1194				 * for write to complete before we do the
  1195				 * hardware reset
  1196				 */
  1197				status = read_rom(serial,
  1198							start_address,
  1199							sizeof(*record),
  1200							record);
  1201				if (status)
  1202					goto free_record;
  1203	
  1204				if (*record != I2C_DESC_TYPE_FIRMWARE_BLANK) {
  1205					dev_err(dev, "%s - error resetting device\n",
  1206							__func__);
  1207					goto e_nodev;
  1208				}
  1209	
  1210				dev_dbg(dev, "%s - HARDWARE RESET\n", __func__);
  1211	
  1212				/* Reset UMP -- Back to BOOT MODE */
  1213				status = ti_vsend_sync(serial->serial->dev,
  1214						UMPC_HARDWARE_RESET,
  1215						0, 0, NULL, 0,
  1216						TI_VSEND_TIMEOUT_DEFAULT);
  1217	
  1218				dev_dbg(dev, "%s - HARDWARE RESET return %d\n",
  1219						__func__, status);
  1220	
  1221				/* return an error on purpose. */
  1222				goto e_nodev;
  1223			}
  1224			/* Same or newer fw version is already loaded */
  1225			serial->fw_version = download_cur_ver;
  1226			kfree(firmware_version);
  1227		}
  1228		/* Search for type 0xF2 record (firmware blank record) */
  1229		else {
  1230			start_address = get_descriptor_addr(serial,
  1231					I2C_DESC_TYPE_FIRMWARE_BLANK, rom_desc);
  1232			if (start_address != 0) {
  1233	#define HEADER_SIZE	(sizeof(struct ti_i2c_desc) + \
  1234					sizeof(struct ti_i2c_firmware_rec))
  1235				u8 *header;
  1236				u8 *vheader;
  1237	
  1238				header = kmalloc(HEADER_SIZE, GFP_KERNEL);
  1239				if (!header)
  1240					goto e_nomem;
  1241	
  1242				vheader = kmalloc(HEADER_SIZE, GFP_KERNEL);
  1243				if (!vheader) {
  1244					kfree(header);
  1245					goto e_nomem;
  1246				}
  1247	
  1248				dev_dbg(dev, "%s - Found Type BLANK FIRMWARE (Type F2) record\n",
  1249						__func__);
  1250	
  1251				/*
  1252				 * In order to update the I2C firmware we must change
  1253				 * the type 2 record to type 0xF2. This will force the
  1254				 * UMP to come up in Boot Mode.  Then while in boot
  1255				 * mode, the driver will download the latest firmware
  1256				 * (padded to 15.5k) into the UMP ram. Finally when the
  1257				 * device comes back up in download mode the driver
  1258				 * will cause the new firmware to be copied from the
  1259				 * UMP Ram to I2C and the firmware will update the
  1260				 * record type from 0xf2 to 0x02.
  1261				 */
  1262				status = build_i2c_fw_hdr(header, fw);
  1263				if (status)
  1264					goto e_inval;
  1265	
  1266				/*
  1267				 * Update I2C with type 0xf2 record with correct
  1268				 * size and checksum
  1269				 */
  1270				status = write_rom(serial,
  1271							start_address,
  1272							HEADER_SIZE,
  1273							header);
  1274				if (status)
  1275					goto e_inval;
  1276	
  1277				/*
  1278				 * verify the write -- must do this in order for
  1279				 * write to complete before we do the hardware reset
  1280				 */
  1281				status = read_rom(serial, start_address,
  1282								HEADER_SIZE, vheader);
  1283	
  1284				if (status) {
  1285					dev_dbg(dev, "%s - can't read header back\n",
  1286							__func__);
  1287					goto free_vheader;
  1288				}
  1289				if (memcmp(vheader, header, HEADER_SIZE)) {
  1290					dev_dbg(dev, "%s - write download record failed\n",
  1291							__func__);
  1292					goto e_inval;
  1293				}
  1294	
  1295				kfree(vheader);
  1296				kfree(header);
  1297	
  1298				dev_dbg(dev, "%s - Start firmware update\n", __func__);
  1299	
  1300				/* Tell firmware to copy download image into I2C */
  1301				status = ti_vsend_sync(serial->serial->dev,
  1302						UMPC_COPY_DNLD_TO_I2C,
  1303						0, 0, NULL, 0,
  1304						TI_VSEND_TIMEOUT_FW_DOWNLOAD);
  1305	
  1306				dev_dbg(dev, "%s - Update complete 0x%x\n", __func__,
  1307						status);
  1308				if (status) {
  1309					dev_err(dev,
  1310						"%s - UMPC_COPY_DNLD_TO_I2C failed\n",
  1311						__func__);
  1312					goto free_rom_desc;
  1313				}
  1314			}
  1315		}
  1316	
  1317		/* The device is running the download code */
  1318		kfree(rom_desc);
  1319		kfree(ti_manuf_desc);
  1320		return 0;
  1321	
  1322	e_inval:
  1323		status = -EINVAL;
  1324	free_vheader:
> 1325		kfree(vheader);
> 1326		kfree(header);
  1327		goto free_rom_desc;
  1328	
  1329	e_nomem:
  1330		status = -ENOMEM;
  1331		goto free_rom_desc;
  1332	
  1333	e_nodev:
  1334		status = -ENODEV;
  1335	free_record:
> 1336		kfree(record);
  1337	free_firmware_version:
> 1338		kfree(firmware_version);
  1339	free_rom_desc:
  1340		kfree(rom_desc);
  1341	free_ti_manuf_desc:
  1342		kfree(ti_manuf_desc);
  1343		return status;
  1344	}
  1345	

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-06-11  2:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-10 14:12 [PATCH] USB: serial: io_ti: Use common error handling code in do_download_mode() Markus Elfring
2026-06-10 23:58 ` kernel test robot
2026-06-11  2:26 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®