PERFORCE change 162660 for review

Alexander Motin mav at FreeBSD.org
Sun May 24 17:44:10 UTC 2009


http://perforce.freebsd.org/chv.cgi?CH=162660

Change 162660 by mav at mav_mavbook on 2009/05/24 17:43:58

	Serial number may be not terminated.

Affected files ...

.. //depot/projects/scottl-camlock/src/sys/cam/ata/ata_xpt.c#4 edit

Differences ...

==== //depot/projects/scottl-camlock/src/sys/cam/ata/ata_xpt.c#4 (text+ko) ====

@@ -485,7 +485,6 @@
 			struct ata_params *ident_buf;
 			int16_t *ptr;
 
-			path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID;
 			ident_buf = &path->device->ident_data;
 
 			for (ptr = (int16_t *)ident_buf;
@@ -507,8 +506,26 @@
 			btrim(ident_buf->serial, sizeof(ident_buf->serial));
 			bpack(ident_buf->serial, ident_buf->serial, sizeof(ident_buf->serial));
 
-			path->device->serial_num = ident_buf->serial;
-			path->device->serial_num_len = strlen(ident_buf->serial);
+			/* Clean up from previous instance of this device */
+			if (path->device->serial_num != NULL) {
+				free(path->device->serial_num, M_CAMXPT);
+				path->device->serial_num = NULL;
+				path->device->serial_num_len = 0;
+			}
+			path->device->serial_num =
+				(u_int8_t *)malloc((sizeof(ident_buf->serial) + 1),
+						   M_CAMXPT, M_NOWAIT);
+			if (path->device->serial_num != NULL) {
+				bcopy(ident_buf->serial,
+				      path->device->serial_num,
+				      sizeof(ident_buf->serial));
+				path->device->serial_num[sizeof(ident_buf->serial)]
+				    = '\0';
+				path->device->serial_num_len =
+				    strlen(path->device->serial_num);
+			}
+
+			path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID;
 
 			scsi_find_quirk(path->device);
 


More information about the p4-projects mailing list