usb: ums: fix disk capacity miscalculation and code cleanup
authorPrzemyslaw Marczak <p.marczak@samsung.com>
Wed, 23 Oct 2013 12:30:44 +0000 (14:30 +0200)
committerChanho Park <chanho61.park@samsung.com>
Fri, 24 Jul 2015 07:29:56 +0000 (16:29 +0900)
This patch prevents:
- ums disk capacity miscalculation because of integer overflow

Changes v2:
- Prevents passing zero size disk capacity to ums gadget driver
- Change function ums_get_capacity() to ums_disk_init() and do ums disk
  initialization before gadget init
- Remove unnecessary code from mass storage driver

Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
Cc: Marek Vasut <marex@denx.de>
Signed-off-by: Chanho Park <chanho61.park@samsung.com>
Conflicts:
board/samsung/trats/trats.c

drivers/usb/gadget/storage_common.c
include/usb_mass_storage.h

index 8208e4dba2267d5c488445735e9252f0cf5d655f..42ba133774d5cf99ae96eabb9da5cf6fb8809edc 100644 (file)
@@ -584,36 +584,16 @@ static struct usb_gadget_strings  fsg_stringtab = {
 static int fsg_lun_open(struct fsg_lun *curlun, const char *filename)
 {
        int                             ro;
-       int                             rc = -EINVAL;
-       loff_t                          size;
-       loff_t                          num_sectors;
-       loff_t                          min_sectors;
 
        /* R/W if we can, R/O if we must */
        ro = curlun->initially_ro;
 
-       ums->get_capacity(ums, &size);
-       if (size < 0) {
-               printf("unable to find file size: %s\n", filename);
-               rc = (int) size;
-               goto out;
-       }
-       num_sectors = size >> 9;        /* File size in 512-byte blocks */
-       min_sectors = 1;
-       if (num_sectors < min_sectors) {
-               printf("file too small: %s\n", filename);
-               rc = -ETOOSMALL;
-               goto out;
-       }
-
        curlun->ro = ro;
-       curlun->file_length = size;
-       curlun->num_sectors = num_sectors;
+       curlun->file_length = ums->num_sectors << 9;
+       curlun->num_sectors = ums->num_sectors;
        debug("open backing file: %s\n", filename);
-       rc = 0;
 
-out:
-       return rc;
+       return 0;
 }
 
 static void fsg_lun_close(struct fsg_lun *curlun)
index 321dad34434afe994138f373ca417ca8f29527f8..3ba90bb682a208b2a3704cf55562317cf36c9218 100644 (file)
@@ -38,12 +38,10 @@ struct ums {
                           ulong start, lbaint_t blkcnt, void *buf);
        int (*write_sector)(struct ums *ums_dev,
                            ulong start, lbaint_t blkcnt, const void *buf);
-       void (*get_capacity)(struct ums *ums_dev,
-                            long long int *capacity);
+       unsigned int start_sector;
+       unsigned int num_sectors;
        const char *name;
        struct mmc *mmc;
-       int offset;
-       int part_size;
 };
 
 extern struct ums *ums;