diff mbox

[U-Boot] UBI: Fix error code handling in ubi commands

Message ID 1300115658-12975-1-git-send-email-sr@denx.de
State Superseded
Headers show

Commit Message

Stefan Roese March 14, 2011, 3:14 p.m. UTC
Some ubi commands returned negative error codes, resulting in
the following error message on the prompt:

"exit not allowed from main input shell."

Negative error codes are not allowed.

This patch now changes the UBI code to return positive error codes.
Additionally "better" error codes are used, for example "ENOMEM" when
no memory is available for the UBI volume creation any more.

Note that the new positive error codes are currently not returned
via the U-Boot HUSH version to the user. All positive codes are returned
as 1. This might change in the future though, so it makes sense to
already support multiple positive return codes.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Wolfgang Denk <wd@denx.de>
---
 common/cmd_ubi.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
diff mbox

Patch

diff --git a/common/cmd_ubi.c b/common/cmd_ubi.c
index b486ca8..620102c 100644
--- a/common/cmd_ubi.c
+++ b/common/cmd_ubi.c
@@ -123,7 +123,7 @@  static int ubi_info(int layout)
 static int verify_mkvol_req(const struct ubi_device *ubi,
 			    const struct ubi_mkvol_req *req)
 {
-	int n, err = -EINVAL;
+	int n, err = EINVAL;
 
 	if (req->bytes < 0 || req->alignment < 0 || req->vol_type < 0 ||
 	    req->name_len < 0)
@@ -136,8 +136,11 @@  static int verify_mkvol_req(const struct ubi_device *ubi,
 	if (req->alignment == 0)
 		goto bad;
 
-	if (req->bytes == 0)
+	if (req->bytes == 0) {
+		printf("No space left in UBI device!\n");
+		err = ENOMEM;
 		goto bad;
+	}
 
 	if (req->vol_type != UBI_DYNAMIC_VOLUME &&
 	    req->vol_type != UBI_STATIC_VOLUME)
@@ -151,13 +154,13 @@  static int verify_mkvol_req(const struct ubi_device *ubi,
 		goto bad;
 
 	if (req->name_len > UBI_VOL_NAME_MAX) {
-		err = -ENAMETOOLONG;
+		printf("Name too long!\n");
+		err = ENAMETOOLONG;
 		goto bad;
 	}
 
 	return 0;
 bad:
-	printf("bad volume creation request");
 	return err;
 }