[U-Boot] [PATCH v5 09/16] cmd: gpt: use error number in set_gpt_info

Patrick Delaunay patrick.delaunay at st.com
Thu Apr 13 09:52:47 UTC 2017


-1 => -ENOENT : "No partition list provided"
-2 => -EBADF : "Missing disk guid"
-3 => -EFAULT &
-4 => -EINVAL : "Partition list incomplete"

Signed-off-by: Patrick Delaunay <patrick.delaunay at st.com>
Reviewed-by: Christophe KERELLO <christophe.kerello at st.com>
---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 cmd/gpt.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/cmd/gpt.c b/cmd/gpt.c
index d84b0a2..f685dc8 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -183,7 +183,7 @@ static int set_gpt_info(unsigned int lba,
 	debug("%s:  lba num: 0x%x %d\n", __func__, lba, lba);
 
 	if (str_part == NULL)
-		return -1;
+		return -ENOENT;
 
 	str = strdup(str_part);
 
@@ -196,7 +196,7 @@ static int set_gpt_info(unsigned int lba,
 		gen_rand_uuid_str(*str_disk_guid, UUID_STR_FORMAT_STD);
 #else
 		free(str);
-		return -2;
+		return -EBADF;
 #endif
 	} else {
 		val = strsep(&val, ";");
@@ -208,7 +208,7 @@ static int set_gpt_info(unsigned int lba,
 		strsep(&s, ";");
 	}
 	if (strlen(s) == 0)
-		return -3;
+		return -EFAULT;
 
 	i = strlen(s) - 1;
 	if (s[i] == ';')
@@ -239,7 +239,7 @@ static int set_gpt_info(unsigned int lba,
 #ifdef CONFIG_RANDOM_UUID
 			gen_rand_uuid_str(parts[i].uuid, UUID_STR_FORMAT_STD);
 #else
-			errno = -4;
+			errno = -EINVAL;
 			goto err;
 #endif
 		} else {
@@ -247,7 +247,7 @@ static int set_gpt_info(unsigned int lba,
 				p = val;
 			if (strlen(p) >= sizeof(parts[i].uuid)) {
 				printf("Wrong uuid format for partition %d\n", i);
-				errno = -4;
+				errno = -EINVAL;
 				goto err;
 			}
 			strcpy((char *)parts[i].uuid, p);
@@ -263,7 +263,7 @@ static int set_gpt_info(unsigned int lba,
 			if (strlen(p) >= sizeof(parts[i].type_guid)) {
 				printf("Wrong type guid format for partition %d\n",
 				       i);
-				errno = -4;
+				errno = -EINVAL;
 				goto err;
 			}
 			strcpy((char *)parts[i].type_guid, p);
@@ -273,13 +273,13 @@ static int set_gpt_info(unsigned int lba,
 		/* name */
 		val = extract_val(tok, "name");
 		if (!val) { /* name is mandatory */
-			errno = -4;
+			errno = -EINVAL;
 			goto err;
 		}
 		if (extract_env(val, &p))
 			p = val;
 		if (strlen(p) >= sizeof(parts[i].name)) {
-			errno = -4;
+			errno = -EINVAL;
 			goto err;
 		}
 		strcpy((char *)parts[i].name, p);
@@ -288,7 +288,7 @@ static int set_gpt_info(unsigned int lba,
 		/* size */
 		val = extract_val(tok, "size");
 		if (!val) { /* 'size' is mandatory */
-			errno = -4;
+			errno = -EINVAL;
 			goto err;
 		}
 		if (extract_env(val, &p))
@@ -344,11 +344,11 @@ static int gpt_default(struct blk_desc *blk_dev_desc, const char *str_part)
 	ret = set_gpt_info(blk_dev_desc->lba, blk_dev_desc->blksz, str_part,
 			&str_disk_guid, &partitions, &part_count);
 	if (ret) {
-		if (ret == -1)
+		if (ret == -ENOENT)
 			printf("No partition list provided\n");
-		if (ret == -2)
+		if (ret == -EBADF)
 			printf("Missing disk guid\n");
-		if ((ret == -3) || (ret == -4))
+		if ((ret == -EFAULT) || (ret == -EINVAL))
 			printf("Partition list incomplete\n");
 		return -1;
 	}
@@ -375,15 +375,15 @@ static int gpt_verify(struct blk_desc *blk_dev_desc, const char *str_part)
 	ret = set_gpt_info(blk_dev_desc->lba, blk_dev_desc->blksz, str_part,
 			&str_disk_guid, &partitions, &part_count);
 	if (ret) {
-		if (ret == -1) {
+		if (ret == -ENOENT) {
 			printf("No partition list provided - only basic check\n");
 			ret = gpt_verify_headers(blk_dev_desc, gpt_head,
 						 &gpt_pte);
 			goto out;
 		}
-		if (ret == -2)
+		if (ret == -EBADF)
 			printf("Missing disk guid\n");
-		if ((ret == -3) || (ret == -4))
+		if ((ret == -EFAULT) || (ret == -EINVAL))
 			printf("Partition list incomplete\n");
 		return -1;
 	}
-- 
1.9.1



More information about the U-Boot mailing list