PERFORCE change 159379 for review
Hans Petter Selasky
hselasky at FreeBSD.org
Wed Mar 18 07:04:07 PDT 2009
http://perforce.freebsd.org/chv.cgi?CH=159379
Change 159379 by hselasky at hselasky_laptop001 on 2009/03/18 14:03:10
USB storage: Device side mode fixes for 8-bit
and 16-bit compilation.
Affected files ...
.. //depot/projects/usb/src/sys/dev/usb/storage/ustorage_fs.c#3 edit
Differences ...
==== //depot/projects/usb/src/sys/dev/usb/storage/ustorage_fs.c#3 (text+ko) ====
@@ -60,10 +60,27 @@
/* 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 @@
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 @@
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 @@
* 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 @@
* 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 @@
* 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 @@
{
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 @@
break;
}
error = ustorage_fs_check_cmd(sc, 6,
- (1 << 4) | 1, 0);
+ (1UL << 4) | 1, 0);
if (error) {
break;
}
@@ -1600,7 +1613,7 @@
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 @@
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 @@
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 @@
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 @@
break;
}
error = ustorage_fs_check_cmd(sc, 6,
- (1 << 4) | 1, 0);
+ (1UL << 4) | 1, 0);
if (error) {
break;
}
@@ -1672,13 +1685,13 @@
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 @@
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 @@
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 @@
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 @@
break;
}
error = ustorage_fs_check_cmd(sc, 10,
- (3 << 7) | 1, 1);
+ (3UL << 7) | 1, 1);
if (error) {
break;
}
@@ -1752,7 +1771,7 @@
break;
}
error = ustorage_fs_check_cmd(sc, 6,
- (1 << 4) | 1, 0);
+ (1UL << 4) | 1, 0);
if (error) {
break;
}
@@ -1766,7 +1785,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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;
}
More information about the p4-projects
mailing list