Skip to contentSkip to conversation

crypto: digest: Return -errno if open() fails

PATCH Applied Andrey Smirnov 3 participants 7 messages Jan 17, 2019 Crypto API

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 crypto: digest: Return -errno if open() fails

Strictly speaking, open() doesn't return a detailed error code as its return value and it can and should be obtained via 'errno'.

---
 crypto/digest.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
crypto/digest.c +1 -1
index 9b7b73019..493e56902 100644
@@ -289,7 +289,7 @@ int digest_file_window(struct digest *d, const char *filename,
 	fd = open(filename, O_RDONLY);
 	if (fd < 0) {
 		perror(filename);
-		return fd;
+		return -errno;
 	}
 
 	buf = memmap(fd, PROT_READ);
Signature · 7 lines
2.20.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

PATCH 2/3 crypto: digest: Return -errno if lseek() fails

Strictly speaking, lseek() doesn't return a detailed error code as its return value and it can and should be obtained via 'errno'. In this case this change also allows us to avoid potential problems from downconverting 'loff_t' to 'int'.

---
 crypto/digest.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
crypto/digest.c +2 -2
index 493e56902..230db26e8 100644
@@ -226,9 +226,9 @@ static int digest_update_from_fd(struct digest *d, int fd,
 	unsigned char *buf = xmalloc(PAGE_SIZE);
 	int ret = 0;
 
-	ret = lseek(fd, start, SEEK_SET);
-	if (ret == -1) {
+	if (lseek(fd, start, SEEK_SET) != start) {
 		perror("lseek");
+		ret = -errno;
 		goto out_free;
 	}
 
Signature · 7 lines
2.20.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

PATCH 3/3 crypto: digest: Return -errno if stat() fails

In reply to Andrey Smirnov

Strictly speaking, stat() doesn't return a detailed error code as its return value and it can and should be obtained via 'errno'.

---
 crypto/digest.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
crypto/digest.c +2 -5
index 230db26e8..2c4de2e4f 100644
@@ -317,12 +317,9 @@ int digest_file(struct digest *d, const char *filename,
 		const unsigned char *sig)
 {
 	struct stat st;
-	int ret;
-
-	ret = stat(filename, &st);
 
-	if (ret < 0)
-		return ret;
+	if (stat(filename, &st))
+		return -errno;
 
 	return digest_file_window(d, filename, hash, sig, 0, st.st_size);
 }
Signature · 7 lines
2.20.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Reviewed-by on v1 2/3
#2 lore raw

Re: [PATCH 2/3] crypto: digest: Return -errno if lseek() fails

In reply to Andrey Smirnov
Quoted 15 lines · Andrey Smirnov

Strictly speaking, lseek() doesn't return a detailed error code as its return value and it can and should be obtained via 'errno'. In this case this change also allows us to avoid potential problems from downconverting 'loff_t' to 'int'.

---
 crypto/digest.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
crypto/digest.c +0 -0
index 493e56902..230db26e8 100644

crypto/digest.c static int digest_update_from_fd(struct digest *d, int fd, · line 233

Quoted 10 lines
crypto/digest.c +2 -2
@@ -226,9 +226,9 @@ static int digest_update_from_fd(struct digest *d, int fd,
 	unsigned char *buf = xmalloc(PAGE_SIZE);
 	int ret = 0;
 
-	ret = lseek(fd, start, SEEK_SET);
-	if (ret == -1) {
+	if (lseek(fd, start, SEEK_SET) != start) {
 		perror("lseek");
+		ret = -errno;
 		goto out_free;
 	}

Looks fine,

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

Reviewed-by on v1 3/3
#4 lore raw

Re: [PATCH 3/3] crypto: digest: Return -errno if stat() fails

In reply to Andrey Smirnov
Quoted 17 lines · Andrey Smirnov

Strictly speaking, stat() doesn't return a detailed error code as its return value and it can and should be obtained via 'errno'.

---
 crypto/digest.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
crypto/digest.c +0 -1
index 230db26e8..2c4de2e4f 100644
@@ -317,12 +317,9 @@ int digest_file(struct digest *d, const char *filename,
 		const unsigned char *sig)
 {
 	struct stat st;
-	int ret;

crypto/digest.c int digest_file(struct digest *d, const char *filename, · line 325

Quoted 10 lines
crypto/digest.c +2 -4
-
-	ret = stat(filename, &st);
 
-	if (ret < 0)
-		return ret;
+	if (stat(filename, &st))
+		return -errno;
 
 	return digest_file_window(d, filename, hash, sig, 0, st.st_size);
 }

Likewise fine,

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

Reviewed-by on v1 1/3
#5 lore raw
In reply to Andrey Smirnov
Quoted 13 lines · Andrey Smirnov

Strictly speaking, open() doesn't return a detailed error code as its return value and it can and should be obtained via 'errno'.

---
 crypto/digest.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
crypto/digest.c +0 -0
index 9b7b73019..493e56902 100644

crypto/digest.c int digest_file_window(struct digest *d, const char *filename, · line 295

Quoted 8 lines
crypto/digest.c +1 -1
@@ -289,7 +289,7 @@ int digest_file_window(struct digest *d, const char *filename,
 	fd = open(filename, O_RDONLY);
 	if (fd < 0) {
 		perror(filename);
-		return fd;
+		return -errno;
 	}
 
 	buf = memmap(fd, PROT_READ);

Looks fine,

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

Applied
#6 lore raw
In reply to Andrey Smirnov
Quoted 7 lines · Andrey Smirnov

Strictly speaking, open() doesn't return a detailed error code as its return value and it can and should be obtained via 'errno'.

---
 crypto/digest.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox