[PATCH v1 08/12] jffs2: use negative error codes
Alexey Romanov
avromanov at salutedevices.com
Thu Dec 28 16:39:11 CET 2023
It is bad practice to use such error codes. Error codes
must be negative.
And use CMD_RET_FAILURE and CMD_RET_SUCCESS defines instead
of 1 and 0.
Signed-off-by: Alexey Romanov <avromanov at salutedevices.com>
---
cmd/jffs2.c | 45 +++++++++++++++++++++++----------------------
1 file changed, 23 insertions(+), 22 deletions(-)
diff --git a/cmd/jffs2.c b/cmd/jffs2.c
index e00fcc2022..068eeedc58 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);
@@ -485,7 +485,7 @@ int do_jffs2_fsload(struct cmd_tbl *cmdtp, int flag, int argc,
/* make sure we are in sync with env variables */
if (mtdparts_init() !=0)
- return 1;
+ return CMD_RET_FAILURE;
if ((part = jffs2_part_info(current_mtd_dev, current_mtd_partnum))){
@@ -500,17 +500,18 @@ 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 CMD_RET_FAILURE;
}
- 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;
+ return CMD_RET_FAILURE;
}
/**
@@ -534,7 +535,7 @@ int do_jffs2_ls(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
/* make sure we are in sync with env variables */
if (mtdparts_init() !=0)
- return 1;
+ return CMD_RET_FAILURE;
if ((part = jffs2_part_info(current_mtd_dev, current_mtd_partnum))){
@@ -546,9 +547,9 @@ int do_jffs2_ls(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
ret = jffs2_1pass_ls(part, filename);
}
- return ret ? 0 : 1;
+ return ret ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
}
- return 1;
+ return CMD_RET_FAILURE;
}
/**
@@ -570,7 +571,7 @@ int do_jffs2_fsinfo(struct cmd_tbl *cmdtp, int flag, int argc,
/* make sure we are in sync with env variables */
if (mtdparts_init() !=0)
- return 1;
+ return CMD_RET_FAILURE;
if ((part = jffs2_part_info(current_mtd_dev, current_mtd_partnum))){
@@ -585,9 +586,9 @@ int do_jffs2_fsinfo(struct cmd_tbl *cmdtp, int flag, int argc,
ret = jffs2_1pass_info(part);
}
- return ret ? 0 : 1;
+ return ret ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
}
- return 1;
+ return CMD_RET_FAILURE;
}
/***************************************************/
--
2.30.1
More information about the U-Boot
mailing list