[PATCH] Do not print error message when successfully attaching more than one UBI device

Xavier Douville barebox at douville.org
Tue Feb 12 10:31:23 EST 2013


Hi

This patch fix a bug where an error message is printed when 
attaching more than one UBI device. ubi_attach_mtd_dev() returns
the UBI device number (>=0) on success.

Signed-off-by: Xavier Douville <barebox at douville.org>
---
 commands/ubi.c |   12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/commands/ubi.c b/commands/ubi.c
index 1653eaa..8dc95ee 100644
--- a/commands/ubi.c
+++ b/commands/ubi.c
@@ -71,15 +71,19 @@ static int do_ubiattach(int argc, char *argv[])
 	}
 
 	ret = ioctl(fd, MEMGETINFO, &user);
-	if (!ret)
+	if (!ret) {
 		ret = ubi_attach_mtd_dev(user.mtd, UBI_DEV_NUM_AUTO, 0);
+		if (ret >= 0) {
+			close(fd);
+			return 0;
+		}
+	}
 
-	if (ret)
-		printf("failed to attach: %s\n", strerror(-ret));
+	printf("failed to attach: %s\n", strerror(ret));
 
 	close(fd);
 
-	return ret ? 1 : 0;
+	return 1;
 }
 
 static const __maybe_unused char cmd_ubiattach_help[] =
-- 
1.7.9.5



More information about the barebox mailing list