All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Simek <michal.simek@xilinx.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 08/17] cmd: fpga: Clean wrong_parms handling
Date: Wed,  8 Aug 2018 13:37:34 +0200	[thread overview]
Message-ID: <cc598d16003d5e222a8b80f2fc7e6eacbc2a993a.1533728254.git.michal.simek@xilinx.com> (raw)
In-Reply-To: <cover.1533728254.git.michal.simek@xilinx.com>

There is no reason to check parameters in separate switch. Check them
directly when they are read. Also there is no reason to check loadmk
case separately because fpga_data address must be non zero too.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
---

Changes in v2: None
Changes in v1: None

 cmd/fpga.c | 35 ++++++++---------------------------
 1 file changed, 8 insertions(+), 27 deletions(-)

diff --git a/cmd/fpga.c b/cmd/fpga.c
index b03dd9dc0ace..0e5f4117c02e 100644
--- a/cmd/fpga.c
+++ b/cmd/fpga.c
@@ -83,7 +83,6 @@ int do_fpga(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 	char *devstr = env_get("fpga");
 	char *datastr = env_get("fpgadata");
 	int rc = FPGA_FAIL;
-	int wrong_parms = 0;
 #if defined(CONFIG_FIT)
 	const char *fit_uname = NULL;
 	ulong fit_addr;
@@ -160,7 +159,10 @@ int do_fpga(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 	switch (argc) {
 	case 5:		/* fpga <op> <dev> <data> <datasize> */
 		data_size = simple_strtoul(argv[4], NULL, 16);
-
+		if (!data_size) {
+			puts("Zero data_size\n");
+			return CMD_RET_USAGE;
+		}
 	case 4:		/* fpga <op> <dev> <data> */
 #if defined(CONFIG_FIT)
 		if (fit_parse_subimage(argv[3], (ulong)fpga_data,
@@ -177,7 +179,10 @@ int do_fpga(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 			      (ulong)fpga_data);
 		}
 		debug("%s: fpga_data = 0x%lx\n", __func__, (ulong)fpga_data);
-
+		if (!fpga_data) {
+			puts("Zero fpga_data address\n");
+			return CMD_RET_USAGE;
+		}
 	case 3:		/* fpga <op> <dev | data addr> */
 		dev = (int)simple_strtoul(argv[2], NULL, 16);
 		debug("%s: device = %d\n", __func__, dev);
@@ -190,30 +195,6 @@ int do_fpga(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 
 	switch (op) {
 	case FPGA_INFO:
-		break;
-	case FPGA_LOAD:
-	case FPGA_LOADP:
-	case FPGA_LOADB:
-	case FPGA_LOADBP:
-	case FPGA_DUMP:
-		if (!fpga_data || !data_size)
-			wrong_parms = 1;
-		break;
-#if defined(CONFIG_CMD_FPGA_LOADMK)
-	case FPGA_LOADMK:
-		if (!fpga_data)
-			wrong_parms = 1;
-		break;
-#endif
-	}
-
-	if (wrong_parms) {
-		puts("Wrong parameters for FPGA request\n");
-		return CMD_RET_USAGE;
-	}
-
-	switch (op) {
-	case FPGA_INFO:
 		rc = fpga_info(dev);
 		break;
 
-- 
1.9.1

  parent reply	other threads:[~2018-08-08 11:37 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-08 11:37 [U-Boot] [PATCH v2 00/17] cmd: fpga: Fix fpga command handling and add some fpga tests Michal Simek
2018-08-08 11:37 ` [U-Boot] [PATCH v2 01/17] cmd: fpga: Remove fit image support passed without fpga device Michal Simek
2018-08-08 11:37 ` [U-Boot] [PATCH v2 02/17] test/py: Extend fpga command to test all fpga load types Michal Simek
2018-08-08 11:37 ` [U-Boot] [PATCH v2 03/17] cmd: fpga: Move error handling to do_fpga() Michal Simek
2018-08-08 11:37 ` [U-Boot] [PATCH v2 04/17] cmd: fpga: Move fpga_get_op to avoid local function declaration Michal Simek
2018-08-08 11:37 ` [U-Boot] [PATCH v2 05/17] cmd: fpga: Cleanup error handling in connection to FPGA_NONE Michal Simek
2018-08-08 11:37 ` [U-Boot] [PATCH v2 06/17] cmd: fpga: Move parameter checking for loadfs/loads Michal Simek
2018-08-08 11:37 ` [U-Boot] [PATCH v2 07/17] cmd: fpga: Remove parameter checking from fpga loadfs command Michal Simek
2018-08-08 11:37 ` Michal Simek [this message]
2018-08-08 11:37 ` [U-Boot] [PATCH v2 09/17] cmd: fpga: Create new do_fpga_wrapper for using u-boot subcommands Michal Simek
2018-08-08 11:37 ` [U-Boot] [PATCH v2 10/17] cmd: fpga: Extract fpga info command to separate function Michal Simek
2018-08-08 11:37 ` [U-Boot] [PATCH v2 11/17] cmd: fpga: Fix dump and all direct fpga load commands Michal Simek
2018-08-08 11:37 ` [U-Boot] [PATCH v2 12/17] cmd: fpga: Fix loadfs command Michal Simek
2018-08-08 11:37 ` [U-Boot] [PATCH v2 13/17] cmd: fpga: Fix loadmk command Michal Simek
2018-08-08 11:37 ` [U-Boot] [PATCH v2 14/17] cmd: fpga: Add support for missing fpga loadmk commands Michal Simek
2018-08-09 11:20   ` Simon Glass
2018-08-08 11:37 ` [U-Boot] [PATCH v2 15/17] cmd: fpga: Use CMD_RET_FAILURE instead of simple 1 Michal Simek
2018-08-08 11:37 ` [U-Boot] [PATCH v2 16/17] cmd: fpga: Fix loads command Michal Simek
2018-08-08 11:37 ` [U-Boot] [PATCH v2 17/17] MAINTAINERS: Add myself as the FPGA maintainer Michal Simek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cc598d16003d5e222a8b80f2fc7e6eacbc2a993a.1533728254.git.michal.simek@xilinx.com \
    --to=michal.simek@xilinx.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.