mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] crypto: digest: Return -errno if open() fails
@ 2019-01-17  4:45 Andrey Smirnov
  2019-01-17  4:45 ` [PATCH 2/3] crypto: digest: Return -errno if lseek() fails Andrey Smirnov
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Andrey Smirnov @ 2019-01-17  4:45 UTC (permalink / raw)
  To: barebox; +Cc: 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'.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 crypto/digest.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/crypto/digest.c b/crypto/digest.c
index 9b7b73019..493e56902 100644
--- a/crypto/digest.c
+++ b/crypto/digest.c
@@ -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);
-- 
2.20.1


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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/3] crypto: digest: Return -errno if lseek() fails
  2019-01-17  4:45 [PATCH 1/3] crypto: digest: Return -errno if open() fails Andrey Smirnov
@ 2019-01-17  4:45 ` Andrey Smirnov
  2019-01-17  5:56   ` Sam Ravnborg
  2019-01-17  4:45 ` [PATCH 3/3] crypto: digest: Return -errno if stat() fails Andrey Smirnov
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Andrey Smirnov @ 2019-01-17  4:45 UTC (permalink / raw)
  To: barebox; +Cc: 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'.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 crypto/digest.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/crypto/digest.c b/crypto/digest.c
index 493e56902..230db26e8 100644
--- a/crypto/digest.c
+++ b/crypto/digest.c
@@ -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;
 	}
 
-- 
2.20.1


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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 3/3] crypto: digest: Return -errno if stat() fails
  2019-01-17  4:45 [PATCH 1/3] crypto: digest: Return -errno if open() fails Andrey Smirnov
  2019-01-17  4:45 ` [PATCH 2/3] crypto: digest: Return -errno if lseek() fails Andrey Smirnov
@ 2019-01-17  4:45 ` Andrey Smirnov
  2019-01-17  5:56   ` Sam Ravnborg
  2019-01-17  5:55 ` [PATCH 1/3] crypto: digest: Return -errno if open() fails Sam Ravnborg
  2019-01-17  8:42 ` Sascha Hauer
  3 siblings, 1 reply; 7+ messages in thread
From: Andrey Smirnov @ 2019-01-17  4:45 UTC (permalink / raw)
  To: barebox; +Cc: 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'.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 crypto/digest.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/crypto/digest.c b/crypto/digest.c
index 230db26e8..2c4de2e4f 100644
--- a/crypto/digest.c
+++ b/crypto/digest.c
@@ -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);
 }
-- 
2.20.1


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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] crypto: digest: Return -errno if open() fails
  2019-01-17  4:45 [PATCH 1/3] crypto: digest: Return -errno if open() fails Andrey Smirnov
  2019-01-17  4:45 ` [PATCH 2/3] crypto: digest: Return -errno if lseek() fails Andrey Smirnov
  2019-01-17  4:45 ` [PATCH 3/3] crypto: digest: Return -errno if stat() fails Andrey Smirnov
@ 2019-01-17  5:55 ` Sam Ravnborg
  2019-01-17  8:42 ` Sascha Hauer
  3 siblings, 0 replies; 7+ messages in thread
From: Sam Ravnborg @ 2019-01-17  5:55 UTC (permalink / raw)
  To: Andrey Smirnov; +Cc: barebox

On Wed, Jan 16, 2019 at 08:45:04PM -0800, Andrey Smirnov wrote:
> Strictly speaking, open() doesn't return a detailed error code as its
> return value and it can and should be obtained via 'errno'.
> 
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> ---
>  crypto/digest.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/crypto/digest.c b/crypto/digest.c
> index 9b7b73019..493e56902 100644
> --- a/crypto/digest.c
> +++ b/crypto/digest.c
> @@ -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,
Reviewed-by: Sam Ravnborg <sam@ravnborg.org>

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] crypto: digest: Return -errno if lseek() fails
  2019-01-17  4:45 ` [PATCH 2/3] crypto: digest: Return -errno if lseek() fails Andrey Smirnov
@ 2019-01-17  5:56   ` Sam Ravnborg
  0 siblings, 0 replies; 7+ messages in thread
From: Sam Ravnborg @ 2019-01-17  5:56 UTC (permalink / raw)
  To: Andrey Smirnov; +Cc: barebox

On Wed, Jan 16, 2019 at 08:45:05PM -0800, Andrey Smirnov wrote:
> 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'.
> 
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> ---
>  crypto/digest.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/crypto/digest.c b/crypto/digest.c
> index 493e56902..230db26e8 100644
> --- a/crypto/digest.c
> +++ b/crypto/digest.c
> @@ -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,
Reviewed-by: Sam Ravnborg <sam@ravnborg.org>


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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] crypto: digest: Return -errno if stat() fails
  2019-01-17  4:45 ` [PATCH 3/3] crypto: digest: Return -errno if stat() fails Andrey Smirnov
@ 2019-01-17  5:56   ` Sam Ravnborg
  0 siblings, 0 replies; 7+ messages in thread
From: Sam Ravnborg @ 2019-01-17  5:56 UTC (permalink / raw)
  To: Andrey Smirnov; +Cc: barebox

On Wed, Jan 16, 2019 at 08:45:06PM -0800, Andrey Smirnov wrote:
> Strictly speaking, stat() doesn't return a detailed error code as its
> return value and it can and should be obtained via 'errno'.
> 
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> ---
>  crypto/digest.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/crypto/digest.c b/crypto/digest.c
> index 230db26e8..2c4de2e4f 100644
> --- a/crypto/digest.c
> +++ b/crypto/digest.c
> @@ -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);
>  }
Likewise fine,
Reviewed-by: Sam Ravnborg <sam@ravnborg.org>

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] crypto: digest: Return -errno if open() fails
  2019-01-17  4:45 [PATCH 1/3] crypto: digest: Return -errno if open() fails Andrey Smirnov
                   ` (2 preceding siblings ...)
  2019-01-17  5:55 ` [PATCH 1/3] crypto: digest: Return -errno if open() fails Sam Ravnborg
@ 2019-01-17  8:42 ` Sascha Hauer
  3 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2019-01-17  8:42 UTC (permalink / raw)
  To: Andrey Smirnov; +Cc: barebox

On Wed, Jan 16, 2019 at 08:45:04PM -0800, Andrey Smirnov wrote:
> Strictly speaking, open() doesn't return a detailed error code as its
> return value and it can and should be obtained via 'errno'.
> 
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> ---
>  crypto/digest.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks

Sascha


-- 
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-01-17  8:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-17  4:45 [PATCH 1/3] crypto: digest: Return -errno if open() fails Andrey Smirnov
2019-01-17  4:45 ` [PATCH 2/3] crypto: digest: Return -errno if lseek() fails Andrey Smirnov
2019-01-17  5:56   ` Sam Ravnborg
2019-01-17  4:45 ` [PATCH 3/3] crypto: digest: Return -errno if stat() fails Andrey Smirnov
2019-01-17  5:56   ` Sam Ravnborg
2019-01-17  5:55 ` [PATCH 1/3] crypto: digest: Return -errno if open() fails Sam Ravnborg
2019-01-17  8:42 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox