[U-Boot] [PATCH] fpga: Simplify error path in fpga_add

Michal Simek michal.simek at xilinx.com
Thu Feb 1 08:05:36 UTC 2018


Check !desc earlier to simplify code.

Signed-off-by: Michal Simek <michal.simek at xilinx.com>
---

 drivers/fpga/fpga.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/drivers/fpga/fpga.c b/drivers/fpga/fpga.c
index 6aead27f1626..ac01612d7518 100644
--- a/drivers/fpga/fpga.c
+++ b/drivers/fpga/fpga.c
@@ -148,20 +148,21 @@ int fpga_add(fpga_type devtype, void *desc)
 {
 	int devnum = FPGA_INVALID_DEVICE;
 
+	if (!desc) {
+		printf("%s: NULL device descriptor\n", __func__);
+		return devnum;
+	}
+
 	if (next_desc < 0) {
 		printf("%s: FPGA support not initialized!\n", __func__);
 	} else if ((devtype > fpga_min_type) && (devtype < fpga_undefined)) {
-		if (desc) {
-			if (next_desc < CONFIG_MAX_FPGA_DEVICES) {
-				devnum = next_desc;
-				desc_table[next_desc].devtype = devtype;
-				desc_table[next_desc++].devdesc = desc;
-			} else {
-				printf("%s: Exceeded Max FPGA device count\n",
-				       __func__);
-			}
+		if (next_desc < CONFIG_MAX_FPGA_DEVICES) {
+			devnum = next_desc;
+			desc_table[next_desc].devtype = devtype;
+			desc_table[next_desc++].devdesc = desc;
 		} else {
-			printf("%s: NULL device descriptor\n", __func__);
+			printf("%s: Exceeded Max FPGA device count\n",
+			       __func__);
 		}
 	} else {
 		printf("%s: Unsupported FPGA type %d\n", __func__, devtype);
-- 
1.9.1



More information about the U-Boot mailing list