[PATCH v2 09/14] jffs2: use negative error codes

Alexey Romanov avromanov at salutedevices.com
Tue Jan 9 18:32:21 CET 2024


It is bad practice to use such error codes. Error codes
must be negative.

Signed-off-by: Alexey Romanov <avromanov at salutedevices.com>
---
 cmd/jffs2.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/cmd/jffs2.c b/cmd/jffs2.c
index e00fcc2022..15bf8c0edf 100644
--- a/cmd/jffs2.c
+++ b/cmd/jffs2.c
@@ -151,7 +151,7 @@ extern int cramfs_info (struct part_info *info);
  * Check device number to be within valid range for given device type.
  *
  * @param dev device to validate
- * Return: 0 if device is valid, 1 otherwise
+ * Return: 0 if device is valid, -errno otherwise
  */
 static int mtd_device_validate(u8 type, u8 num, u32 *size)
 {
@@ -191,7 +191,7 @@ static int mtd_device_validate(u8 type, u8 num, u32 *size)
 	} else
 		printf("Unknown defice type %d\n", type);
 
-	return 1;
+	return -EINVAL;
 }
 
 /**
@@ -202,7 +202,7 @@ static int mtd_device_validate(u8 type, u8 num, u32 *size)
  * @param ret_id output pointer to next char after parse completes (output)
  * @param dev_type parsed device type (output)
  * @param dev_num parsed device number (output)
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 static int mtd_id_parse(const char *id, const char **ret_id, u8 *dev_type, u8 *dev_num)
 {
@@ -220,12 +220,12 @@ static int mtd_id_parse(const char *id, const char **ret_id, u8 *dev_type, u8 *d
 		p += 7;
 	} else {
 		printf("incorrect device type in %s\n", id);
-		return 1;
+		return -EINVAL;
 	}
 
 	if (!isdigit(*p)) {
 		printf("incorrect device number in %s\n", id);
-		return 1;
+		return -EINVAL;
 	}
 
 	*dev_num = simple_strtoul(p, (char **)&p, 0);
@@ -328,7 +328,7 @@ static inline u32 get_part_sector_size(struct mtdids *id, struct part_info *part
  * 'Static' version of command line mtdparts_init() routine. Single partition on
  * a single device configuration.
  *
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 int mtdparts_init(void)
 {
@@ -348,7 +348,7 @@ int mtdparts_init(void)
 					sizeof(struct mtdids));
 		if (!current_mtd_dev) {
 			printf("out of memory\n");
-			return 1;
+			return -ENOMEM;
 		}
 		memset(current_mtd_dev, 0, sizeof(struct mtd_device) +
 		       sizeof(struct part_info) + sizeof(struct mtdids));
@@ -365,7 +365,7 @@ int mtdparts_init(void)
 				(mtd_device_validate(id->type, id->num, &size) != 0)) {
 			printf("incorrect device: %s%d\n", MTD_DEV_TYPE(id->type), id->num);
 			free(current_mtd_dev);
-			return 1;
+			return -EINVAL;
 		}
 		id->size = size;
 		INIT_LIST_HEAD(&id->link);
@@ -500,15 +500,16 @@ int do_jffs2_fsload(struct cmd_tbl *cmdtp, int flag, int argc,
 			size = jffs2_1pass_load((char *)offset, part, filename);
 		}
 
-		if (size > 0) {
-			printf("### %s load complete: %d bytes loaded to 0x%lx\n",
-				fsname, size, offset);
-			env_set_hex("filesize", size);
-		} else {
+		if (size <= 0) {
 			printf("### %s LOAD ERROR<%x> for %s!\n", fsname, size, filename);
+			return 1;
 		}
 
-		return !(size > 0);
+		printf("### %s load complete: %d bytes loaded to 0x%lx\n",
+			fsname, size, offset);
+		env_set_hex("filesize", size);
+
+		return 0;
 	}
 	return 1;
 }
-- 
2.30.1



More information about the U-Boot mailing list