mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 2/4] ubiattach command: Properly check return values
Date: Tue, 23 Jul 2013 12:28:00 +0200	[thread overview]
Message-ID: <1374575282-9592-3-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1374575282-9592-1-git-send-email-s.hauer@pengutronix.de>

- print error when ioctl fails, not a combined message when one of
  ioctl or ubi_attach_mtd_dev failed.
- ubi_attach_mtd_dev() returns the ubi number for success, not 0, so
  check for ret < 0 to detect errors.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/ubi.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/commands/ubi.c b/commands/ubi.c
index 854ea83..5b57d0b 100644
--- a/commands/ubi.c
+++ b/commands/ubi.c
@@ -71,12 +71,17 @@ static int do_ubiattach(int argc, char *argv[])
 	}
 
 	ret = ioctl(fd, MEMGETINFO, &user);
-	if (!ret)
-		ret = ubi_attach_mtd_dev(user.mtd, UBI_DEV_NUM_AUTO, 0);
+	if (ret) {
+		printf("MEMGETINFO failed: %s\n", strerror(-ret));
+		goto err;
+	}
 
-	if (ret)
+	ret = ubi_attach_mtd_dev(user.mtd, UBI_DEV_NUM_AUTO, 0);
+	if (ret < 0)
 		printf("failed to attach: %s\n", strerror(-ret));
-
+	else
+		ret = 0;
+err:
 	close(fd);
 
 	return ret ? 1 : 0;
-- 
1.8.3.2


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

  parent reply	other threads:[~2013-07-23 10:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-23 10:27 [PATCH] update UBI support Sascha Hauer
2013-07-23 10:27 ` [PATCH 1/4] UBI: Add ubidetach command Sascha Hauer
2013-07-23 10:28 ` Sascha Hauer [this message]
2013-07-23 10:28 ` [PATCH 3/4] UBI: remove old ubi support Sascha Hauer
2013-07-23 10:28 ` [PATCH 4/4] UBI: reimport UBI from Linux v3.10 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=1374575282-9592-3-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@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