[PATCH 12/17] state: Fix lseek error check in state_backend_bucket_direct_read()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 common/state/backend_bucket_direct.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/common/state/backend_bucket_direct.c b/common/state/backend_bucket_direct.c
index 1f00b0fb2..152431214 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;
 		}
 	}
 
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux