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

Stefan Roese sr at denx.de
Mon Mar 14 16:14:18 CET 2011


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 at denx.de>
Cc: Wolfgang Denk <wd at denx.de>
---
 common/cmd_ubi.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

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;
 }
 
-- 
1.7.4.1



More information about the U-Boot mailing list