Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 20 Mar 2009 18:59:53 +0000 (UTC)
From:      Andrew Thompson <thompsa@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r190173 - in head/sys/dev/usb: . storage
Message-ID:  <200903201859.n2KIxrK1010988@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: thompsa
Date: Fri Mar 20 18:59:53 2009
New Revision: 190173
URL: http://svn.freebsd.org/changeset/base/190173

Log:
  MFp4 //depot/projects/usb @159379,159380
  
  Fixes for 8-bit and 16-bit compilation.
  
  Submitted by:	Hans Petter Selasky

Modified:
  head/sys/dev/usb/storage/ustorage_fs.c
  head/sys/dev/usb/usb_endian.h

Modified: head/sys/dev/usb/storage/ustorage_fs.c
==============================================================================
--- head/sys/dev/usb/storage/ustorage_fs.c	Fri Mar 20 18:56:27 2009	(r190172)
+++ head/sys/dev/usb/storage/ustorage_fs.c	Fri Mar 20 18:59:53 2009	(r190173)
@@ -60,10 +60,27 @@ SYSCTL_INT(_hw_usb2_ustorage_fs, OID_AUT
 
 /* Define some limits */
 
-#define	USTORAGE_FS_BULK_SIZE (1 << 17)
+#define	USTORAGE_FS_BULK_SIZE (1UL << 17)
 #define	USTORAGE_FS_MAX_LUN 8
-#define	USTORAGE_FS_RELEASE 0x0101
-#define	USTORAGE_FS_RAM_SECT (1 << 13)
+
+/*
+ * The SCSI ID string must be exactly 28 characters long
+ * exluding the terminating zero.
+ */
+#ifndef USTORAGE_FS_ID_STRING
+#define	USTORAGE_FS_ID_STRING \
+	"FreeBSD " /* 8 */ \
+	"File-Stor Gadget" /* 16 */ \
+	"0101" /* 4 */
+#endif
+
+/*
+ * The following macro defines the number of
+ * sectors to be allocated for the RAM disk:
+ */
+#ifndef USTORAGE_FS_RAM_SECT
+#define	USTORAGE_FS_RAM_SECT (1UL << 13)
+#endif
 
 static uint8_t *ustorage_fs_ramdisk;
 
@@ -955,8 +972,6 @@ static uint8_t
 ustorage_fs_inquiry(struct ustorage_fs_softc *sc)
 {
 	uint8_t *buf = sc->sc_transfer.data_ptr;
-	static const char vendor_id[] = "FreeBSD ";
-	static const char product_id[] = "File-Stor Gadget";
 
 	struct ustorage_fs_lun *currlun = sc->sc_transfer.currlun;
 
@@ -978,12 +993,9 @@ ustorage_fs_inquiry(struct ustorage_fs_s
 	buf[4] = 31;
 	/* Additional length */
 	/* No special options */
-	/*
-	 * NOTE: We are writing an extra zero here, that is not
-	 * transferred to the peer:
-	 */
-	snprintf(buf + 8, 28 + 1, "%-8s%-16s%04x", vendor_id, product_id,
-	    USTORAGE_FS_RELEASE);
+	/* Copy in ID string */
+	memcpy(buf + 8, USTORAGE_FS_ID_STRING, 28);
+
 	return (ustorage_fs_min_len(sc, 36, 0 - 1));
 }
 
@@ -1332,7 +1344,7 @@ ustorage_fs_read(struct ustorage_fs_soft
 	 * too big
 	 */
 	if (sc->sc_transfer.cmd_data[0] == SC_READ_6) {
-		lba = (sc->sc_transfer.cmd_data[1] << 16) |
+		lba = (((uint32_t)sc->sc_transfer.cmd_data[1]) << 16) |
 		    get_be16(&sc->sc_transfer.cmd_data[2]);
 	} else {
 		lba = get_be32(&sc->sc_transfer.cmd_data[2]);
@@ -1391,7 +1403,7 @@ ustorage_fs_write(struct ustorage_fs_sof
 	 * too big.
 	 */
 	if (sc->sc_transfer.cmd_data[0] == SC_WRITE_6)
-		lba = (sc->sc_transfer.cmd_data[1] << 16) |
+		lba = (((uint32_t)sc->sc_transfer.cmd_data[1]) << 16) |
 		    get_be16(&sc->sc_transfer.cmd_data[2]);
 	else {
 		lba = get_be32(&sc->sc_transfer.cmd_data[2]);
@@ -1539,7 +1551,7 @@ ustorage_fs_check_cmd(struct ustorage_fs
 	 * non-zero.
 	 */
 	for (i = 0; i != min_cmd_size; i++) {
-		if (sc->sc_transfer.cmd_data[i] && !(mask & (1 << i))) {
+		if (sc->sc_transfer.cmd_data[i] && !(mask & (1UL << i))) {
 			if (currlun) {
 				currlun->sense_data = SS_INVALID_FIELD_IN_CDB;
 			}
@@ -1570,6 +1582,7 @@ ustorage_fs_do_cmd(struct ustorage_fs_so
 {
 	uint8_t error = 1;
 	uint8_t i;
+	uint32_t temp;
 
 	/* set default data transfer pointer */
 	sc->sc_transfer.data_ptr = sc->sc_qdata;
@@ -1585,7 +1598,7 @@ ustorage_fs_do_cmd(struct ustorage_fs_so
 			break;
 		}
 		error = ustorage_fs_check_cmd(sc, 6,
-		    (1 << 4) | 1, 0);
+		    (1UL << 4) | 1, 0);
 		if (error) {
 			break;
 		}
@@ -1600,7 +1613,7 @@ ustorage_fs_do_cmd(struct ustorage_fs_so
 			break;
 		}
 		error = ustorage_fs_check_cmd(sc, 6,
-		    (1 << 1) | (1 << 4) | 1, 0);
+		    (1UL << 1) | (1UL << 4) | 1, 0);
 		if (error) {
 			break;
 		}
@@ -1616,7 +1629,7 @@ ustorage_fs_do_cmd(struct ustorage_fs_so
 			break;
 		}
 		error = ustorage_fs_check_cmd(sc, 10,
-		    (1 << 1) | (3 << 7) | 1, 0);
+		    (1UL << 1) | (3UL << 7) | 1, 0);
 		if (error) {
 			break;
 		}
@@ -1631,7 +1644,7 @@ ustorage_fs_do_cmd(struct ustorage_fs_so
 			break;
 		}
 		error = ustorage_fs_check_cmd(sc, 6,
-		    (1 << 1) | (1 << 2) | (1 << 4) | 1, 0);
+		    (1UL << 1) | (1UL << 2) | (1UL << 4) | 1, 0);
 		if (error) {
 			break;
 		}
@@ -1647,7 +1660,7 @@ ustorage_fs_do_cmd(struct ustorage_fs_so
 			break;
 		}
 		error = ustorage_fs_check_cmd(sc, 10,
-		    (1 << 1) | (1 << 2) | (3 << 7) | 1, 0);
+		    (1UL << 1) | (1UL << 2) | (3UL << 7) | 1, 0);
 		if (error) {
 			break;
 		}
@@ -1661,7 +1674,7 @@ ustorage_fs_do_cmd(struct ustorage_fs_so
 			break;
 		}
 		error = ustorage_fs_check_cmd(sc, 6,
-		    (1 << 4) | 1, 0);
+		    (1UL << 4) | 1, 0);
 		if (error) {
 			break;
 		}
@@ -1672,13 +1685,13 @@ ustorage_fs_do_cmd(struct ustorage_fs_so
 	case SC_READ_6:
 		i = sc->sc_transfer.cmd_data[4];
 		sc->sc_transfer.cmd_dir = DIR_WRITE;
-		error = ustorage_fs_min_len(sc,
-		    ((i == 0) ? 256 : i) << 9, 0 - (1 << 9));
+		temp = ((i == 0) ? 256UL : i);
+		error = ustorage_fs_min_len(sc, temp << 9, 0 - (1UL << 9));
 		if (error) {
 			break;
 		}
 		error = ustorage_fs_check_cmd(sc, 6,
-		    (7 << 1) | (1 << 4) | 1, 1);
+		    (7UL << 1) | (1UL << 4) | 1, 1);
 		if (error) {
 			break;
 		}
@@ -1688,13 +1701,13 @@ ustorage_fs_do_cmd(struct ustorage_fs_so
 
 	case SC_READ_10:
 		sc->sc_transfer.cmd_dir = DIR_WRITE;
-		error = ustorage_fs_min_len(sc,
-		    get_be16(&sc->sc_transfer.cmd_data[7]) << 9, 0 - (1 << 9));
+		temp = get_be16(&sc->sc_transfer.cmd_data[7]);
+		error = ustorage_fs_min_len(sc, temp << 9, 0 - (1UL << 9));
 		if (error) {
 			break;
 		}
 		error = ustorage_fs_check_cmd(sc, 10,
-		    (1 << 1) | (0xf << 2) | (3 << 7) | 1, 1);
+		    (1UL << 1) | (0xfUL << 2) | (3UL << 7) | 1, 1);
 		if (error) {
 			break;
 		}
@@ -1704,13 +1717,19 @@ ustorage_fs_do_cmd(struct ustorage_fs_so
 
 	case SC_READ_12:
 		sc->sc_transfer.cmd_dir = DIR_WRITE;
-		error = ustorage_fs_min_len(sc,
-		    get_be32(&sc->sc_transfer.cmd_data[6]) << 9, 0 - (1 << 9));
+		temp = get_be32(&sc->sc_transfer.cmd_data[6]);
+		if (temp >= (1UL << (32 - 9))) {
+			/* numerical overflow */
+			sc->sc_csw.bCSWStatus = CSWSTATUS_FAILED;
+			error = 1;
+			break;
+		}
+		error = ustorage_fs_min_len(sc, temp << 9, 0 - (1UL << 9));
 		if (error) {
 			break;
 		}
 		error = ustorage_fs_check_cmd(sc, 12,
-		    (1 << 1) | (0xf << 2) | (0xf << 6) | 1, 1);
+		    (1UL << 1) | (0xfUL << 2) | (0xfUL << 6) | 1, 1);
 		if (error) {
 			break;
 		}
@@ -1721,7 +1740,7 @@ ustorage_fs_do_cmd(struct ustorage_fs_so
 	case SC_READ_CAPACITY:
 		sc->sc_transfer.cmd_dir = DIR_WRITE;
 		error = ustorage_fs_check_cmd(sc, 10,
-		    (0xf << 2) | (1 << 8) | 1, 1);
+		    (0xfUL << 2) | (1UL << 8) | 1, 1);
 		if (error) {
 			break;
 		}
@@ -1737,7 +1756,7 @@ ustorage_fs_do_cmd(struct ustorage_fs_so
 			break;
 		}
 		error = ustorage_fs_check_cmd(sc, 10,
-		    (3 << 7) | 1, 1);
+		    (3UL << 7) | 1, 1);
 		if (error) {
 			break;
 		}
@@ -1752,7 +1771,7 @@ ustorage_fs_do_cmd(struct ustorage_fs_so
 			break;
 		}
 		error = ustorage_fs_check_cmd(sc, 6,
-		    (1 << 4) | 1, 0);
+		    (1UL << 4) | 1, 0);
 		if (error) {
 			break;
 		}
@@ -1766,7 +1785,7 @@ ustorage_fs_do_cmd(struct ustorage_fs_so
 			break;
 		}
 		error = ustorage_fs_check_cmd(sc, 6,
-		    (1 << 1) | (1 << 4) | 1, 0);
+		    (1UL << 1) | (1UL << 4) | 1, 0);
 		if (error) {
 			break;
 		}
@@ -1780,7 +1799,7 @@ ustorage_fs_do_cmd(struct ustorage_fs_so
 			break;
 		}
 		error = ustorage_fs_check_cmd(sc, 10,
-		    (0xf << 2) | (3 << 7) | 1, 1);
+		    (0xfUL << 2) | (3UL << 7) | 1, 1);
 		if (error) {
 			break;
 		}
@@ -1807,7 +1826,7 @@ ustorage_fs_do_cmd(struct ustorage_fs_so
 			break;
 		}
 		error = ustorage_fs_check_cmd(sc, 10,
-		    (1 << 1) | (0xf << 2) | (3 << 7) | 1, 1);
+		    (1UL << 1) | (0xfUL << 2) | (3UL << 7) | 1, 1);
 		if (error) {
 			break;
 		}
@@ -1818,13 +1837,13 @@ ustorage_fs_do_cmd(struct ustorage_fs_so
 	case SC_WRITE_6:
 		i = sc->sc_transfer.cmd_data[4];
 		sc->sc_transfer.cmd_dir = DIR_READ;
-		error = ustorage_fs_min_len(sc,
-		    ((i == 0) ? 256 : i) << 9, 0 - (1 << 9));
+		temp = ((i == 0) ? 256UL : i);
+		error = ustorage_fs_min_len(sc, temp << 9, 0 - (1UL << 9));
 		if (error) {
 			break;
 		}
 		error = ustorage_fs_check_cmd(sc, 6,
-		    (7 << 1) | (1 << 4) | 1, 1);
+		    (7UL << 1) | (1UL << 4) | 1, 1);
 		if (error) {
 			break;
 		}
@@ -1834,13 +1853,13 @@ ustorage_fs_do_cmd(struct ustorage_fs_so
 
 	case SC_WRITE_10:
 		sc->sc_transfer.cmd_dir = DIR_READ;
-		error = ustorage_fs_min_len(sc,
-		    get_be16(&sc->sc_transfer.cmd_data[7]) << 9, 0 - (1 << 9));
+		temp = get_be16(&sc->sc_transfer.cmd_data[7]);
+		error = ustorage_fs_min_len(sc, temp << 9, 0 - (1UL << 9));
 		if (error) {
 			break;
 		}
 		error = ustorage_fs_check_cmd(sc, 10,
-		    (1 << 1) | (0xf << 2) | (3 << 7) | 1, 1);
+		    (1UL << 1) | (0xfUL << 2) | (3UL << 7) | 1, 1);
 		if (error) {
 			break;
 		}
@@ -1850,13 +1869,19 @@ ustorage_fs_do_cmd(struct ustorage_fs_so
 
 	case SC_WRITE_12:
 		sc->sc_transfer.cmd_dir = DIR_READ;
-		error = ustorage_fs_min_len(sc,
-		    get_be32(&sc->sc_transfer.cmd_data[6]) << 9, 0 - (1 << 9));
+		temp = get_be32(&sc->sc_transfer.cmd_data[6]);
+		if (temp >= (1UL << (32 - 9))) {
+			/* numerical overflow */
+			sc->sc_csw.bCSWStatus = CSWSTATUS_FAILED;
+			error = 1;
+			break;
+		}
+		error = ustorage_fs_min_len(sc, temp << 9, 0 - (1UL << 9));
 		if (error) {
 			break;
 		}
 		error = ustorage_fs_check_cmd(sc, 12,
-		    (1 << 1) | (0xf << 2) | (0xf << 6) | 1, 1);
+		    (1UL << 1) | (0xfUL << 2) | (0xfUL << 6) | 1, 1);
 		if (error) {
 			break;
 		}

Modified: head/sys/dev/usb/usb_endian.h
==============================================================================
--- head/sys/dev/usb/usb_endian.h	Fri Mar 20 18:56:27 2009	(r190172)
+++ head/sys/dev/usb/usb_endian.h	Fri Mar 20 18:59:53 2009	(r190173)
@@ -48,19 +48,19 @@ typedef uint8_t uQWord[8];
 
 #define	UGETW(w)			\
   ((w)[0] |				\
-  ((w)[1] << 8))
+  (((uint16_t)((w)[1])) << 8))
 
 #define	UGETDW(w)			\
   ((w)[0] |				\
-  ((w)[1] << 8) |			\
-  ((w)[2] << 16) |			\
-  ((w)[3] << 24))
+  (((uint16_t)((w)[1])) << 8) |		\
+  (((uint32_t)((w)[2])) << 16) |	\
+  (((uint32_t)((w)[3])) << 24))
 
 #define	UGETQW(w)			\
   ((w)[0] |				\
-  ((w)[1] << 8) |			\
-  ((w)[2] << 16) |			\
-  ((w)[3] << 24) |			\
+  (((uint16_t)((w)[1])) << 8) |		\
+  (((uint32_t)((w)[2])) << 16) |	\
+  (((uint32_t)((w)[3])) << 24) |	\
   (((uint64_t)((w)[4])) << 32) |	\
   (((uint64_t)((w)[5])) << 40) |	\
   (((uint64_t)((w)[6])) << 48) |	\



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200903201859.n2KIxrK1010988>