mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/4] libfile: have write_full return a descriptive error code
Date: Thu, 22 Aug 2019 08:54:06 +0200	[thread overview]
Message-ID: <20190822065408.29279-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20190822065408.29279-1-a.fatoum@pengutronix.de>

So far (p|)write_full has been returning -1 on error.
Some callers of write_full like imx_bbu_write_device print out the
function's return value on error, effectively rendering every printed
error message to be due to EPERM.

On the other hand, some callers like do_memcpy, use it correctly and
use errno. Sidestep the issue by having the function return -errno on
errors as well.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 lib/libfile.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/libfile.c b/lib/libfile.c
index b42753c2b5ea..f6c588d7373f 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -38,7 +38,7 @@ int pwrite_full(int fd, const void *buf, size_t size, loff_t offset)
 		now = pwrite(fd, buf, size, offset);
 		if (now == 0) {
 			errno = ENOSPC;
-			return -1;
+			return -errno;
 		}
 		if (now < 0)
 			return now;
@@ -66,7 +66,7 @@ int write_full(int fd, const void *buf, size_t size)
 		now = write(fd, buf, size);
 		if (now == 0) {
 			errno = ENOSPC;
-			return -1;
+			return -errno;
 		}
 		if (now < 0)
 			return now;
@@ -194,6 +194,7 @@ again:
 	buf = calloc(read_size + 1, 1);
 	if (!buf) {
 		ret = -ENOMEM;
+		errno = ENOMEM;
 		goto err_out;
 	}
 
-- 
2.20.1


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

  reply	other threads:[~2019-08-22  6:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-22  6:54 [PATCH 1/4] startup: allow ctrl+c abort during boot sequence Ahmad Fatoum
2019-08-22  6:54 ` Ahmad Fatoum [this message]
2019-08-22  6:54 ` [PATCH 3/4] ARM: i.MX: bbu: early exit when partition too small Ahmad Fatoum
2019-08-22  6:54 ` [PATCH 4/4] fs: omap4_usbbootfs: remove commented out code Ahmad Fatoum
2019-08-23  7:55 ` [PATCH 1/4] startup: allow ctrl+c abort during boot sequence Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190822065408.29279-2-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox