diff mbox series

[U-Boot,1/3] cmd: fpga: Reorder the arguments parsing code

Message ID 1527603765-24481-1-git-send-email-siva.durga.paladugu@xilinx.com
State Superseded
Delegated to: Michal Simek
Headers show
Series [U-Boot,1/3] cmd: fpga: Reorder the arguments parsing code | expand

Commit Message

Siva Durga Prasad Paladugu May 29, 2018, 2:22 p.m. UTC
This patch modifies the arguments parsing code by parsing
based on requested operation for fpga loadfs and then
parses the most common/basic args for other fpga load
commands. This makes it easy for new command extensions
or additions especially the commands with more args.

Signed-off-by: Siva Durga Prasad Paladugu <siva.durga.paladugu@xilinx.com>
---
 cmd/fpga.c | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

--
2.7.4

This email and any attachments are intended for the sole use of the named recipient(s) and contain(s) confidential information that may be proprietary, privileged or copyrighted under applicable law. If you are not the intended recipient, do not read, copy, or forward this email message or any attachments. Delete this email message and any attachments immediately.

Comments

Michal Simek May 30, 2018, 3:07 p.m. UTC | #1
On 29.5.2018 16:22, Siva Durga Prasad Paladugu wrote:
> This patch modifies the arguments parsing code by parsing
> based on requested operation for fpga loadfs and then
> parses the most common/basic args for other fpga load
> commands. This makes it easy for new command extensions
> or additions especially the commands with more args.
> 
> Signed-off-by: Siva Durga Prasad Paladugu <siva.durga.paladugu@xilinx.com>
> ---
>  cmd/fpga.c | 31 +++++++++++++++++++------------
>  1 file changed, 19 insertions(+), 12 deletions(-)
> 
> diff --git a/cmd/fpga.c b/cmd/fpga.c
> index 14ad4e5..0981826 100644
> --- a/cmd/fpga.c
> +++ b/cmd/fpga.c
> @@ -60,15 +60,31 @@ int do_fpga(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
>  	if (datastr)
>  		fpga_data = (void *)simple_strtoul(datastr, NULL, 16);
>  
> -	switch (argc) {
> +	if (argc > 9 && argc < 3) {

&& is completely broken here.
Also there is an option to use fpga and fpgadata variable and 2 args are
valid too.

Thanks,
Michal
Siva Durga Prasad Paladugu May 31, 2018, 4:25 a.m. UTC | #2
Hi,
> -----Original Message-----
> From: Michal Simek [mailto:michal.simek@xilinx.com]
> Sent: Wednesday, May 30, 2018 8:37 PM
> To: Siva Durga Prasad Paladugu <sivadur@xilinx.com>; u-
> boot@lists.denx.de
> Cc: michal.simek@xilinx.com
> Subject: Re: [PATCH 1/3] cmd: fpga: Reorder the arguments parsing code
> 
> On 29.5.2018 16:22, Siva Durga Prasad Paladugu wrote:
> > This patch modifies the arguments parsing code by parsing based on
> > requested operation for fpga loadfs and then parses the most
> > common/basic args for other fpga load commands. This makes it easy for
> > new command extensions or additions especially the commands with
> more
> > args.
> >
> > Signed-off-by: Siva Durga Prasad Paladugu
> > <siva.durga.paladugu@xilinx.com>
> > ---
> >  cmd/fpga.c | 31 +++++++++++++++++++------------
> >  1 file changed, 19 insertions(+), 12 deletions(-)
> >
> > diff --git a/cmd/fpga.c b/cmd/fpga.c
> > index 14ad4e5..0981826 100644
> > --- a/cmd/fpga.c
> > +++ b/cmd/fpga.c
> > @@ -60,15 +60,31 @@ int do_fpga(cmd_tbl_t *cmdtp, int flag, int argc,
> char *const argv[])
> >  	if (datastr)
> >  		fpga_data = (void *)simple_strtoul(datastr, NULL, 16);
> >
> > -	switch (argc) {
> > +	if (argc > 9 && argc < 3) {
> 
> && is completely broken here.
> Also there is an option to use fpga and fpgadata variable and 2 args are
> valid too.

:-) Yes, thanks for catching it. Will correct and send next version.

Thanks,
Siva
> 
> Thanks,
> Michal
diff mbox series

Patch

diff --git a/cmd/fpga.c b/cmd/fpga.c
index 14ad4e5..0981826 100644
--- a/cmd/fpga.c
+++ b/cmd/fpga.c
@@ -60,15 +60,31 @@  int do_fpga(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
        if (datastr)
                fpga_data = (void *)simple_strtoul(datastr, NULL, 16);

-       switch (argc) {
+       if (argc > 9 && argc < 3) {
+               debug("%s: Too many or too few args (%d)\n", __func__, argc);
+               return CMD_RET_USAGE;
+       }
+
+       op = (int)fpga_get_op(argv[1]);
+
+       switch (op) {
 #if defined(CONFIG_CMD_FPGA_LOADFS)
-       case 9:
+       case FPGA_LOADFS:
+               if (argc < 9)
+                       return CMD_RET_USAGE;
                fpga_fsinfo.blocksize = (unsigned int)
-                                            simple_strtoul(argv[5], NULL, 16);
+                                       simple_strtoul(argv[5], NULL, 16);
                fpga_fsinfo.interface = argv[6];
                fpga_fsinfo.dev_part = argv[7];
                fpga_fsinfo.filename = argv[8];
+               argc = 5;
+               break;
 #endif
+       default:
+               break;
+       }
+
+       switch (argc) {
        case 5:         /* fpga <op> <dev> <data> <datasize> */
                data_size = simple_strtoul(argv[4], NULL, 16);

@@ -117,15 +133,6 @@  int do_fpga(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
                              __func__, (ulong)fpga_data);
                        dev = FPGA_INVALID_DEVICE;      /* reset device num */
                }
-
-       case 2:         /* fpga <op> */
-               op = (int)fpga_get_op(argv[1]);
-               break;
-
-       default:
-               debug("%s: Too many or too few args (%d)\n", __func__, argc);
-               op = FPGA_NONE; /* force usage display */
-               break;
        }

        if (dev == FPGA_INVALID_DEVICE) {