Skip to contentSkip to conversation

cmd: mmc: Return CMD_RET_* from commands

PATCH Superseded Pali Rohár 2 participants 5 messages Mar 19, 2023 – Mar 23, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cmd: mmc: Return CMD_RET_* from commands

Numeric return values may cause strange errors line:
exit not allowed from main input shell.

---
 cmd/mmc.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
cmd/mmc.c +13 -5
index c79d9407986d..0b8fc903e1f6 100644
@@ -175,7 +175,7 @@ static int do_mmcinfo(struct cmd_tbl *cmdtp, int flag, int argc,
 			curr_device = 0;
 		else {
 			puts("No MMC device available\n");
-			return 1;
+			return CMD_RET_FAILURE;
 		}
 	}
 
@@ -927,7 +927,7 @@ static int mmc_partconf_print(struct mmc *mmc, const char *varname)
 static int do_mmc_partconf(struct cmd_tbl *cmdtp, int flag,
 			   int argc, char *const argv[])
 {
-	int dev;
+	int r, dev;
 	struct mmc *mmc;
 	u8 ack, part_num, access;
 
@@ -953,13 +953,17 @@ static int do_mmc_partconf(struct cmd_tbl *cmdtp, int flag,
 	access = dectoul(argv[4], NULL);
 
 	/* acknowledge to be sent during boot operation */
-	return mmc_set_part_conf(mmc, ack, part_num, access);
+	r = mmc_set_part_conf(mmc, ack, part_num, access);
+	if (r != 0)
+		return CMD_RET_FAILURE;
+
+	return CMD_RET_SUCCESS;
 }
 
 static int do_mmc_rst_func(struct cmd_tbl *cmdtp, int flag,
 			   int argc, char *const argv[])
 {
-	int dev;
+	int r, dev;
 	struct mmc *mmc;
 	u8 enable;
 
@@ -988,7 +992,11 @@ static int do_mmc_rst_func(struct cmd_tbl *cmdtp, int flag,
 		return CMD_RET_FAILURE;
 	}
 
-	return mmc_set_rst_n_function(mmc, enable);
+	r = mmc_set_rst_n_function(mmc, enable);
+	if (r != 0)
+		return CMD_RET_FAILURE;
+
+	return CMD_RET_SUCCESS;
 }
 #endif
 static int do_mmc_setdsr(struct cmd_tbl *cmdtp, int flag,
Signature · 1 line
2.20.1
#1 lore raw

Hi Pali,

Quoted 38 lines · Pali Rohár

Numeric return values may cause strange errors line:
exit not allowed from main input shell.

---
 cmd/mmc.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
cmd/mmc.c +4 -3
index c79d9407986d..0b8fc903e1f6 100644
@@ -175,7 +175,7 @@ static int do_mmcinfo(struct cmd_tbl *cmdtp, int flag, int argc,
                        curr_device = 0;
                else {
                        puts("No MMC device available\n");
-                       return 1;
+                       return CMD_RET_FAILURE;
                }
        }
 
@@ -927,7 +927,7 @@ static int mmc_partconf_print(struct mmc *mmc, const char *varname)
 static int do_mmc_partconf(struct cmd_tbl *cmdtp, int flag,
                           int argc, char *const argv[])
 {
-       int dev;
+       int r, dev;
        struct mmc *mmc;
        u8 ack, part_num, access;
 
@@ -953,13 +953,17 @@ static int do_mmc_partconf(struct cmd_tbl *cmdtp, int flag,
        access = dectoul(argv[4], NULL);
 
        /* acknowledge to be sent during boot operation */
-       return mmc_set_part_conf(mmc, ack, part_num, access);
+       r = mmc_set_part_conf(mmc, ack, part_num, access);
+       if (r != 0)

cmd/mmc.c static int do_mmc_partconf(struct cmd_tbl *cmdtp, int flag, · line 966

Quoted 10 lines
cmd/mmc.c +4 -1
+               return CMD_RET_FAILURE;
+
+       return CMD_RET_SUCCESS;
 }
 
 static int do_mmc_rst_func(struct cmd_tbl *cmdtp, int flag,
                           int argc, char *const argv[])
 {
-       int dev;
+       int r, dev;

Please use 'ret' as that is what we normally do with driver model.

cmd/mmc.c static int do_mmc_rst_func(struct cmd_tbl *cmdtp, int flag, · line 996

Quoted 10 lines
cmd/mmc.c +2 -1
        struct mmc *mmc;
        u8 enable;
 
@@ -988,7 +992,11 @@ static int do_mmc_rst_func(struct cmd_tbl *cmdtp, int flag,
                return CMD_RET_FAILURE;
        }
 
-       return mmc_set_rst_n_function(mmc, enable);
+       r = mmc_set_rst_n_function(mmc, enable);
+       if (r != 0)

if (ret)

cmd/mmc.c static int do_mmc_partconf(struct cmd_tbl *cmdtp, int flag, · line 960

Quoted 3 lines
cmd/mmc.c +3 -0
+               return CMD_RET_FAILURE;
+
+       return CMD_RET_SUCCESS;

'return 0' is fine here as less verbose. Success is 0 in U-Boot.

Quoted 6 lines
cmd/mmc.c +0 -1
 }
 #endif
 static int do_mmc_setdsr(struct cmd_tbl *cmdtp, int flag,
--

2.20.1

Regards,
Simon

#2 lore raw
Quoted 46 lines · On Monday 20 March 2023 08:29:04 Simon Glass wrote:

Hi Pali,

Quoted 43 lines · Pali Rohár

Numeric return values may cause strange errors line:
exit not allowed from main input shell.

---
 cmd/mmc.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
cmd/mmc.c +7 -3
index c79d9407986d..0b8fc903e1f6 100644
@@ -175,7 +175,7 @@ static int do_mmcinfo(struct cmd_tbl *cmdtp, int flag, int argc,
                        curr_device = 0;
                else {
                        puts("No MMC device available\n");
-                       return 1;
+                       return CMD_RET_FAILURE;
                }
        }
 
@@ -927,7 +927,7 @@ static int mmc_partconf_print(struct mmc *mmc, const char *varname)
 static int do_mmc_partconf(struct cmd_tbl *cmdtp, int flag,
                           int argc, char *const argv[])
 {
-       int dev;
+       int r, dev;
        struct mmc *mmc;
        u8 ack, part_num, access;
 
@@ -953,13 +953,17 @@ static int do_mmc_partconf(struct cmd_tbl *cmdtp, int flag,
        access = dectoul(argv[4], NULL);
 
        /* acknowledge to be sent during boot operation */
-       return mmc_set_part_conf(mmc, ack, part_num, access);
+       r = mmc_set_part_conf(mmc, ack, part_num, access);
+       if (r != 0)
+               return CMD_RET_FAILURE;
+
+       return CMD_RET_SUCCESS;
 }
 
Quoted 7 lines

cmd/mmc.c static int do_mmc_partconf(struct cmd_tbl *cmdtp, int flag, · line 966

Quoted 5 lines
cmd/mmc.c +1 -1
 static int do_mmc_rst_func(struct cmd_tbl *cmdtp, int flag,
                           int argc, char *const argv[])
 {
-       int dev;
+       int r, dev;

Please use 'ret' as that is what we normally do with driver model.

Ok.

Quoted 13 lines

cmd/mmc.c static int do_mmc_rst_func(struct cmd_tbl *cmdtp, int flag, · line 996

Quoted 10 lines
cmd/mmc.c +2 -1
        struct mmc *mmc;
        u8 enable;
 
@@ -988,7 +992,11 @@ static int do_mmc_rst_func(struct cmd_tbl *cmdtp, int flag,
                return CMD_RET_FAILURE;
        }
 
-       return mmc_set_rst_n_function(mmc, enable);
+       r = mmc_set_rst_n_function(mmc, enable);
+       if (r != 0)

if (ret)

Quoted 5 lines

cmd/mmc.c static int do_mmc_partconf(struct cmd_tbl *cmdtp, int flag, · line 960

Quoted 3 lines
cmd/mmc.c +3 -0
+               return CMD_RET_FAILURE;
+
+       return CMD_RET_SUCCESS;

'return 0' is fine here as less verbose. Success is 0 in U-Boot.

On all other mmc.c places is used verbose CMD_RET_SUCCESS macro. So it is better to have one common style.

Quoted 10 lines
Quoted 7 lines
cmd/mmc.c +0 -1
 }
 #endif
 static int do_mmc_setdsr(struct cmd_tbl *cmdtp, int flag,
--

2.20.1

Regards,
Simon

#3 lore raw

PATCH v2 1/1 cmd: mmc: Return CMD_RET_* from commands

In reply to Pali Rohár

Numeric return values may cause strange errors line:
exit not allowed from main input shell.

---
Rename r to ret.

---
 cmd/mmc.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
cmd/mmc.c +13 -5
index c79d9407986d..539d3e0bf768 100644
@@ -175,7 +175,7 @@ static int do_mmcinfo(struct cmd_tbl *cmdtp, int flag, int argc,
 			curr_device = 0;
 		else {
 			puts("No MMC device available\n");
-			return 1;
+			return CMD_RET_FAILURE;
 		}
 	}
 
@@ -927,7 +927,7 @@ static int mmc_partconf_print(struct mmc *mmc, const char *varname)
 static int do_mmc_partconf(struct cmd_tbl *cmdtp, int flag,
 			   int argc, char *const argv[])
 {
-	int dev;
+	int ret, dev;
 	struct mmc *mmc;
 	u8 ack, part_num, access;
 
@@ -953,13 +953,17 @@ static int do_mmc_partconf(struct cmd_tbl *cmdtp, int flag,
 	access = dectoul(argv[4], NULL);
 
 	/* acknowledge to be sent during boot operation */
-	return mmc_set_part_conf(mmc, ack, part_num, access);
+	ret = mmc_set_part_conf(mmc, ack, part_num, access);
+	if (ret != 0)
+		return CMD_RET_FAILURE;
+
+	return CMD_RET_SUCCESS;
 }
 
 static int do_mmc_rst_func(struct cmd_tbl *cmdtp, int flag,
 			   int argc, char *const argv[])
 {
-	int dev;
+	int ret, dev;
 	struct mmc *mmc;
 	u8 enable;
 
@@ -988,7 +992,11 @@ static int do_mmc_rst_func(struct cmd_tbl *cmdtp, int flag,
 		return CMD_RET_FAILURE;
 	}
 
-	return mmc_set_rst_n_function(mmc, enable);
+	ret = mmc_set_rst_n_function(mmc, enable);
+	if (ret != 0)
+		return CMD_RET_FAILURE;
+
+	return CMD_RET_SUCCESS;
 }
 #endif
 static int do_mmc_setdsr(struct cmd_tbl *cmdtp, int flag,
Signature · 1 line
2.20.1