diff --git a/drivers/mtd/nand/nand-bb.c b/drivers/mtd/nand/nand-bb.c index 012163e..e578d72 100644 --- a/drivers/mtd/nand/nand-bb.c +++ b/drivers/mtd/nand/nand-bb.c @@ -236,17 +236,16 @@ return 0; } -static loff_t nand_bb_lseek(struct cdev *cdev, loff_t __offset) +static int nand_bb_lseek(struct cdev *cdev, loff_t offset) { struct nand_bb *bb = cdev->priv; loff_t raw_pos = 0; - uint32_t offset = __offset; /* lseek only in readonly mode */ if (bb->flags & O_ACCMODE) return -ENOSYS; while (raw_pos < bb->mtd->size) { - off_t now = min(offset, bb->mtd->erasesize); + off_t now = min_t(loff_t, offset, bb->mtd->erasesize); if (mtd_block_isbad(bb->mtd, raw_pos)) { raw_pos += bb->mtd->erasesize; @@ -257,7 +256,7 @@ if (!offset) { bb->offset = raw_pos; - return __offset; + return 0; } } diff --git a/drivers/mtd/ubi/barebox.c b/drivers/mtd/ubi/barebox.c index 65f5456..781061d 100644 --- a/drivers/mtd/ubi/barebox.c +++ b/drivers/mtd/ubi/barebox.c @@ -151,7 +151,7 @@ return 0; } -static loff_t ubi_volume_cdev_lseek(struct cdev *cdev, loff_t ofs) +static int ubi_volume_cdev_lseek(struct cdev *cdev, loff_t ofs) { struct ubi_volume_cdev_priv *priv = cdev->priv; @@ -159,7 +159,7 @@ if (priv->written) return -EINVAL; - return ofs; + return 0; } static int ubi_volume_cdev_truncate(struct cdev *cdev, size_t size) diff --git a/fs/bpkfs.c b/fs/bpkfs.c index f1db963..655cde0 100644 --- a/fs/bpkfs.c +++ b/fs/bpkfs.c @@ -192,7 +192,7 @@ } } -static loff_t bpkfs_lseek(struct device_d *dev, FILE *file, loff_t pos) +static int bpkfs_lseek(struct device_d *dev, FILE *file, loff_t pos) { struct bpkfs_handle_data *d = file->priv; @@ -201,7 +201,7 @@ d->pos = pos; - return pos; + return 0; } struct somfy_readdir { diff --git a/fs/devfs.c b/fs/devfs.c index 5599f39..007dea9 100644 --- a/fs/devfs.c +++ b/fs/devfs.c @@ -57,10 +57,10 @@ return cdev_write(cdev, buf, size, f->pos, f->flags); } -static loff_t devfs_lseek(struct device_d *_dev, FILE *f, loff_t pos) +static int devfs_lseek(struct device_d *_dev, FILE *f, loff_t pos) { struct cdev *cdev = f->priv; - loff_t ret; + int ret; if (cdev->ops->lseek) { ret = cdev->ops->lseek(cdev, pos + cdev->offset); @@ -68,7 +68,7 @@ return ret; } - return pos; + return 0; } static int devfs_erase(struct device_d *_dev, FILE *f, loff_t count, loff_t offset) diff --git a/fs/efi.c b/fs/efi.c index 074ef6b..cd4fee7 100644 --- a/fs/efi.c +++ b/fs/efi.c @@ -292,7 +292,7 @@ return bufsize; } -static loff_t efifs_lseek(struct device_d *dev, FILE *f, loff_t pos) +static int efifs_lseek(struct device_d *dev, FILE *f, loff_t pos) { struct efifs_file *ufile = f->priv; efi_status_t efiret; @@ -302,7 +302,7 @@ return -efi_errno(efiret); } - return pos; + return 0; } static int efifs_truncate(struct device_d *dev, FILE *f, unsigned long size) diff --git a/fs/fat/fat.c b/fs/fat/fat.c index ee7751e..1367577 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -268,7 +268,7 @@ return outsize; } -static loff_t fat_lseek(struct device_d *dev, FILE *f, loff_t pos) +static int fat_lseek(struct device_d *dev, FILE *f, loff_t pos) { FIL *f_file = f->priv; int ret; @@ -277,7 +277,7 @@ if (ret) return ret; - return pos; + return 0; } static DIR* fat_opendir(struct device_d *dev, const char *pathname) diff --git a/fs/fs.c b/fs/fs.c index 8cd965b..21f15ec 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -439,11 +439,9 @@ } if (fsdrv->lseek) { - pos = fsdrv->lseek(&f->fsdev->dev, f, pos); - if (IS_ERR_VALUE(pos)) { - errno = -pos; - return -1; - } + ret = fsdrv->lseek(&f->fsdev->dev, f, pos); + if (ret < 0) + goto out; } f->pos = pos; diff --git a/fs/nfs.c b/fs/nfs.c index cc8795c..c58fca7 100644 --- a/fs/nfs.c +++ b/fs/nfs.c @@ -1060,13 +1060,13 @@ return kfifo_get(priv->fifo, buf, insize); } -static loff_t nfs_lseek(struct device_d *dev, FILE *file, loff_t pos) +static int nfs_lseek(struct device_d *dev, FILE *file, loff_t pos) { struct file_priv *priv = file->priv; kfifo_reset(priv->fifo); - return pos; + return 0; } static int nfs_iterate(struct file *file, struct dir_context *ctx) diff --git a/fs/pstore/fs.c b/fs/pstore/fs.c index a879a68..9a7e0b5 100644 --- a/fs/pstore/fs.c +++ b/fs/pstore/fs.c @@ -172,13 +172,13 @@ return insize; } -static loff_t pstore_lseek(struct device_d *dev, FILE *file, loff_t pos) +static int pstore_lseek(struct device_d *dev, FILE *file, loff_t pos) { struct pstore_private *d = file->priv; d->pos = pos; - return pos; + return 0; } static DIR *pstore_opendir(struct device_d *dev, const char *pathname) diff --git a/fs/smhfs.c b/fs/smhfs.c index 18eaa9d..7a69336 100644 --- a/fs/smhfs.c +++ b/fs/smhfs.c @@ -109,13 +109,13 @@ return -semihosting_errno(); } -static loff_t smhfs_lseek(struct device_d __always_unused *dev, +static int smhfs_lseek(struct device_d __always_unused *dev, FILE *f, loff_t pos) { if (semihosting_seek(file_to_fd(f), pos)) return -semihosting_errno(); - return pos; + return 0; } static DIR* smhfs_opendir(struct device_d __always_unused *dev, diff --git a/fs/tftp.c b/fs/tftp.c index f9e204d..41f904f 100644 --- a/fs/tftp.c +++ b/fs/tftp.c @@ -573,13 +573,13 @@ return outsize; } -static loff_t tftp_lseek(struct device_d *dev, FILE *f, loff_t pos) +static int tftp_lseek(struct device_d *dev, FILE *f, loff_t pos) { /* We cannot seek backwards without reloading or caching the file */ loff_t f_pos = f->pos; if (pos >= f_pos) { - loff_t ret; + int ret = 0; char *buf = xmalloc(1024); while (pos > f_pos) { @@ -596,8 +596,6 @@ f_pos += ret; } - ret = pos; - out_free: free(buf); if (ret < 0) { @@ -606,8 +604,10 @@ * failed since we can't move backwards */ f->pos = f_pos; + return ret; } - return ret; + + return 0; } return -ENOSYS; diff --git a/fs/uimagefs.c b/fs/uimagefs.c index c120944..e5ada82 100644 --- a/fs/uimagefs.c +++ b/fs/uimagefs.c @@ -116,7 +116,7 @@ } } -static loff_t uimagefs_lseek(struct device_d *dev, FILE *file, loff_t pos) +static int uimagefs_lseek(struct device_d *dev, FILE *file, loff_t pos) { struct uimagefs_handle_data *d = file->priv; @@ -125,7 +125,7 @@ d->pos = pos; - return pos; + return 0; } static DIR *uimagefs_opendir(struct device_d *dev, const char *pathname) diff --git a/include/driver.h b/include/driver.h index bcb31af..a8e046e 100644 --- a/include/driver.h +++ b/include/driver.h @@ -434,7 +434,7 @@ ssize_t (*write)(struct cdev*, const void* buf, size_t count, loff_t offset, ulong flags); int (*ioctl)(struct cdev*, int, void *); - loff_t (*lseek)(struct cdev*, loff_t); + int (*lseek)(struct cdev*, loff_t); int (*open)(struct cdev*, unsigned long flags); int (*close)(struct cdev*); int (*flush)(struct cdev*); diff --git a/include/fs.h b/include/fs.h index 181318f..68b6380 100644 --- a/include/fs.h +++ b/include/fs.h @@ -53,7 +53,7 @@ int (*read)(struct device_d *dev, FILE *f, void *buf, size_t size); int (*write)(struct device_d *dev, FILE *f, const void *buf, size_t size); int (*flush)(struct device_d *dev, FILE *f); - loff_t (*lseek)(struct device_d *dev, FILE *f, loff_t pos); + int (*lseek)(struct device_d *dev, FILE *f, loff_t pos); int (*ioctl)(struct device_d *dev, FILE *f, int request, void *buf); int (*erase)(struct device_d *dev, FILE *f, loff_t count,