diff --git a/arch/arm/mach-omap/am33xx_bbu_nand.c b/arch/arm/mach-omap/am33xx_bbu_nand.c index ee767d3..25f0e79 100644 --- a/arch/arm/mach-omap/am33xx_bbu_nand.c +++ b/arch/arm/mach-omap/am33xx_bbu_nand.c @@ -40,7 +40,7 @@ return fd; } - ret = erase(fd, ~0, 0); + ret = erase(fd, ERASE_SIZE_ALL, 0); if (ret < 0) { pr_err("could not erase %s: %s\n", devfile, errno_str()); diff --git a/arch/arm/mach-omap/am33xx_bbu_spi_mlo.c b/arch/arm/mach-omap/am33xx_bbu_spi_mlo.c index 702bb9a..69a73ff 100644 --- a/arch/arm/mach-omap/am33xx_bbu_spi_mlo.c +++ b/arch/arm/mach-omap/am33xx_bbu_spi_mlo.c @@ -70,7 +70,7 @@ goto out; } - ret = erase(dstfd, ~0, 0); + ret = erase(dstfd, ERASE_SIZE_ALL, 0); if (ret < 0) { printf("could not erase %s: %s", data->devicefile, errno_str()); goto out1; diff --git a/commands/flash.c b/commands/flash.c index 99d3cb7..d881b4d 100644 --- a/commands/flash.c +++ b/commands/flash.c @@ -32,7 +32,7 @@ int fd; char *filename = NULL; struct stat s; - loff_t start = 0, size = ~0; + loff_t start = 0, size; int ret = 0; if (argc == 1) diff --git a/common/environment.c b/common/environment.c index 9cf44a0..be102db 100644 --- a/common/environment.c +++ b/common/environment.c @@ -88,6 +88,7 @@ } #else +#define ERASE_SIZE_ALL 0 static inline int protect(int fd, size_t count, unsigned long offset, int prot) { return 0; @@ -329,7 +330,7 @@ goto out; } - ret = erase(envfd, ~0, 0); + ret = erase(envfd, ERASE_SIZE_ALL, 0); /* ENOSYS and EOPNOTSUPP aren't errors here, many devices don't need it */ if (ret && errno != ENOSYS && errno != EOPNOTSUPP) { diff --git a/drivers/usb/gadget/dfu.c b/drivers/usb/gadget/dfu.c index 351b584..d7bf92c 100644 --- a/drivers/usb/gadget/dfu.c +++ b/drivers/usb/gadget/dfu.c @@ -359,7 +359,7 @@ ret = -EINVAL; goto err_out; } - ret = erase(fd, ~0, 0); + ret = erase(fd, ERASE_SIZE_ALL, 0); close(fd); if (ret && ret != -ENOSYS) { perror("erase"); @@ -479,7 +479,7 @@ goto out; } - ret = erase(dfufd, ~0, 0); + ret = erase(dfufd, ERASE_SIZE_ALL, 0); if (ret && ret != -ENOSYS) { dfu->dfu_status = DFU_STATUS_errERASE; perror("erase"); diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index 0df08c9..aaf7849 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -784,7 +784,7 @@ if (fd < 0) fastboot_tx_print(f_fb, "FAIL%s", strerror(-fd)); - ret = erase(fd, ~0, 0); + ret = erase(fd, ERASE_SIZE_ALL, 0); close(fd); diff --git a/fs/fs.c b/fs/fs.c index 440adae..966abe9 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -935,8 +935,10 @@ f = &files[fd]; if (offset >= f->size) return 0; - if (count > f->size - offset) + if (count == ERASE_SIZE_ALL || count > f->size - offset) count = f->size - offset; + if (count < 0) + return -EINVAL; fsdrv = f->fsdev->driver; if (fsdrv->erase) diff --git a/include/fs.h b/include/fs.h index b9d1e6e..943ba55 100644 --- a/include/fs.h +++ b/include/fs.h @@ -147,6 +147,7 @@ int umount_by_cdev(struct cdev *cdev); /* not-so-standard functions */ +#define ERASE_SIZE_ALL ((loff_t) - 1) int erase(int fd, loff_t count, loff_t offset); int protect(int fd, size_t count, loff_t offset, int prot); int protect_file(const char *file, int prot);