summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2019-03-06 23:49:21 -0800
committerSascha Hauer <s.hauer@pengutronix.de>2019-03-11 07:55:46 +0100
commit219b954a11e82afbbd7b6ef13d8c5ba94a5b0ff3 (patch)
treebbb2d633b9b16fa3565bb6d6fba2e6076b14d671
parent7af10336201f9d458a4f7baefec4d0d8a8c60141 (diff)
downloadbarebox-219b954a11e82afbbd7b6ef13d8c5ba94a5b0ff3.tar.gz
state: Fix lseek error check in state_backend_bucket_direct_read()
Don't use 'int' to store lseek()'s return value to avoid problems with large seek offsets. While at it, make sure to populate return error code from 'errno'. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--common/state/backend_bucket_direct.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/common/state/backend_bucket_direct.c b/common/state/backend_bucket_direct.c
index 1f00b0f..1524312 100644
--- a/common/state/backend_bucket_direct.c
+++ b/common/state/backend_bucket_direct.c
@@ -56,10 +56,9 @@ static int state_backend_bucket_direct_read(struct state_backend_storage_bucket
void *buf;
int ret;
- ret = lseek(direct->fd, direct->offset, SEEK_SET);
- if (ret < 0) {
- dev_err(direct->dev, "Failed to seek file, %d\n", ret);
- return ret;
+ if (lseek(direct->fd, direct->offset, SEEK_SET) != direct->offset) {
+ dev_err(direct->dev, "Failed to seek file, %d\n", -errno);
+ return -errno;
}
ret = read_full(direct->fd, &meta, sizeof(meta));
if (ret < 0) {
@@ -77,10 +76,11 @@ static int state_backend_bucket_direct_read(struct state_backend_storage_bucket
return -EINVAL;
}
read_len = direct->max_size;
- ret = lseek(direct->fd, direct->offset, SEEK_SET);
- if (ret < 0) {
- dev_err(direct->dev, "Failed to seek file, %d\n", ret);
- return ret;
+ if (lseek(direct->fd, direct->offset, SEEK_SET) !=
+ direct->offset) {
+ dev_err(direct->dev, "Failed to seek file, %d\n",
+ -errno);
+ return -errno;
}
}