summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2019-01-28 22:55:36 -0800
committerSascha Hauer <s.hauer@pengutronix.de>2019-01-29 09:27:03 +0100
commit6811cc0dbc04c71cdc1ff12efe0edc8660200563 (patch)
treed8fa3f5a8942b8cd524a776db5df31d996e38069
parent332304dd644384b4c639d10d65f3ce4c8f43c06c (diff)
downloadbarebox-6811cc0dbc04c71cdc1ff12efe0edc8660200563.tar.gz
barebox-6811cc0dbc04c71cdc1ff12efe0edc8660200563.tar.xz
devfs: Fix incorrect error check for cdev->ops->lseek()
Cdev->ops->lseek() will either return a negative error code on failure or requested position on success. In order to properly check for errors we need to test if the return value is negative, not just that it's not -1. Returning ret - cdev->offset, doesn't appear to be correct either, even if ret is -1, since on failure this will lead us to return (-1 - cdev->offset). Simplify that part by just returning 'pos', which is what we'd end up returning on success in original code as well. Third, make sure to return -ENOSYS, when no .lseek() callback is provided. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--fs/devfs.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/fs/devfs.c b/fs/devfs.c
index 81ae2c25a5..ae5e6475b1 100644
--- a/fs/devfs.c
+++ b/fs/devfs.c
@@ -60,15 +60,19 @@ static int devfs_write(struct device_d *_dev, FILE *f, const void *buf, size_t s
static loff_t devfs_lseek(struct device_d *_dev, FILE *f, loff_t pos)
{
struct cdev *cdev = f->priv;
- loff_t ret = -1;
+ loff_t ret;
- if (cdev->ops->lseek)
+ if (cdev->ops->lseek) {
ret = cdev->ops->lseek(cdev, pos + cdev->offset);
+ if (ret < 0)
+ return ret;
+ } else {
+ return -ENOSYS;
+ }
- if (ret != -1)
- f->pos = pos;
+ f->pos = pos;
- return ret - cdev->offset;
+ return pos;
}
static int devfs_erase(struct device_d *_dev, FILE *f, loff_t count, loff_t offset)