From owner-p4-projects@FreeBSD.ORG Wed Mar 18 14:04:05 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 33B2F106566B; Wed, 18 Mar 2009 14:04:05 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DFF841065670 for ; Wed, 18 Mar 2009 14:04:04 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id CCCEC8FC17 for ; Wed, 18 Mar 2009 14:04:04 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n2IE44Mi066272 for ; Wed, 18 Mar 2009 14:04:04 GMT (envelope-from hselasky@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n2IE44Lo066270 for perforce@freebsd.org; Wed, 18 Mar 2009 14:04:04 GMT (envelope-from hselasky@FreeBSD.org) Date: Wed, 18 Mar 2009 14:04:04 GMT Message-Id: <200903181404.n2IE44Lo066270@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky To: Perforce Change Reviews Cc: Subject: PERFORCE change 159379 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Mar 2009 14:04:07 -0000 http://perforce.freebsd.org/chv.cgi?CH=159379 Change 159379 by hselasky@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; }