diff options
author | Andrey Smirnov <andrew.smirnov@gmail.com> | 2019-01-28 22:55:42 -0800 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2019-02-04 15:30:11 +0100 |
commit | d7c2384940bbeff6529e42d81a7f314c69833654 (patch) | |
tree | b07e853cbb67af0d697acbc26b4dde90d272cd99 /fs | |
parent | 71cd98395789829b79dc6e748046549fb9e90135 (diff) | |
download | barebox-d7c2384940bbeff6529e42d81a7f314c69833654.tar.gz barebox-d7c2384940bbeff6529e42d81a7f314c69833654.tar.xz |
fs: Simplify new position calculation in lseek()
All these checks are really testing is that resulting position is
within [0; f->size] interval. Convert all of the custom checks into a
signle one done after the switch statement to simplify the code.
Note this change also disables the validity check for f->size ==
FILE_SIZE_STREAM and whence == SEEK_END, but lseek(stream_fd, offset,
SEEK_END) wasn't a meaningful operation to begin with, so this
shouldn't be a problem.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/fs.c | 19 |
1 files changed, 8 insertions, 11 deletions
@@ -418,26 +418,23 @@ loff_t lseek(int fildes, loff_t offset, int whence) switch (whence) { case SEEK_SET: - if (f->size != FILE_SIZE_STREAM && offset > f->size) - goto out; - if (offset < 0) - goto out; - pos = offset; + pos = 0; break; case SEEK_CUR: - if (f->size != FILE_SIZE_STREAM && offset + f->pos > f->size) - goto out; - pos = f->pos + offset; + pos = f->pos; break; case SEEK_END: - if (offset > 0) - goto out; - pos = f->size + offset; + pos = f->size; break; default: goto out; } + pos += offset; + + if (f->size != FILE_SIZE_STREAM && (pos < 0 || pos > f->size)) + goto out; + if (fsdrv->lseek) { ret = fsdrv->lseek(&f->fsdev->dev, f, pos); if (ret < 0) |