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

Patrick Delaunay patrick.delaunay at st.com
Thu May 11 07:51:59 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>
Reviewed-by: Simon Glass <sjg at chromium.org>
---

Changes in v6: None
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 5dfbce5..a36dbdf 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -184,7 +184,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);
 
@@ -197,7 +197,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, ";");
@@ -209,7 +209,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] == ';')
@@ -240,7 +240,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 {
@@ -248,7 +248,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);
@@ -264,7 +264,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);
@@ -274,13 +274,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);
@@ -289,7 +289,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))
@@ -345,11 +345,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;
 	}
@@ -376,15 +376,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