[PATCH u-boot] cmd: mmc: Return CMD_RET_* from commands
Pali Rohár
pali at kernel.org
Sun Mar 19 20:39:01 CET 2023
On Monday 20 March 2023 08:29:04 Simon Glass wrote:
> Hi Pali,
>
> On Mon, 20 Mar 2023 at 05:34, Pali Rohár <pali at kernel.org> wrote:
> >
> > Numeric return values may cause strange errors line:
> > exit not allowed from main input shell.
> >
> > Signed-off-by: Pali Rohár <pali at kernel.org>
> > ---
> > cmd/mmc.c | 18 +++++++++++++-----
> > 1 file changed, 13 insertions(+), 5 deletions(-)
> >
> > diff --git a/cmd/mmc.c b/cmd/mmc.c
> > index c79d9407986d..0b8fc903e1f6 100644
> > --- a/cmd/mmc.c
> > +++ b/cmd/mmc.c
> > @@ -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;
>
> Please use 'ret' as that is what we normally do with driver model.
Ok.
> > 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)
>
> > + 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.
>
> > }
> > #endif
> > static int do_mmc_setdsr(struct cmd_tbl *cmdtp, int flag,
> > --
> > 2.20.1
> >
>
> Regards,
> Simon
More information about the U-Boot
mailing list