fs: fat: don't call disk_write with zero sector num
authorWu, Josh <Josh.wu@atmel.com>
Wed, 24 Jul 2013 09:55:30 +0000 (17:55 +0800)
committerChanho Park <chanho61.park@samsung.com>
Wed, 22 Jul 2015 12:00:44 +0000 (21:00 +0900)
In the set_cluster() function, it will convert the buffer size to sector
numbers. Then call disk_write() to write by sector.
For remaining buffer, the size is less than a sector, call disk_write()
again to write them in one sector.

But if the total buffer size is less then one sector, the original code
will call disk_write() with zero sector number. It is unnecessary.
So this patch fix this. Now it will not call disk_write() if total buffer size
is less than one sector.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
fs/fat/fat_write.c

index b4022aa29054abae1ae22d19e0015d18883c9545..3c3234e2bfcf3ca7ffa92e7884a2cf623110ada8 100644 (file)
@@ -569,9 +569,11 @@ set_cluster(fsdata *mydata, __u32 clustnum, __u8 *buffer,
 
        debug("clustnum: %d, startsect: %d\n", clustnum, startsect);
 
-       if (disk_write(startsect, size / mydata->sect_size, buffer) < 0) {
-               debug("Error writing data\n");
-               return -1;
+       if ((size / mydata->sect_size) > 0) {
+               if (disk_write(startsect, size / mydata->sect_size, buffer) < 0) {
+                       debug("Error writing data\n");
+                       return -1;
+               }
        }
 
        if (size % mydata->sect_size) {