Skip to contentSkip to conversation

cmd/nand.c: Remove unnecessarily repeated step

PATCH New Ahmed Samir Khalil 2 participants 2 messages Oct 10, 2016 – Oct 13, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cmd/nand.c: Remove unnecessarily repeated step

Getting the current NAND device is already done once as part
of nand command. Therefore, repeating this step as part of the sub-commands is unnecessary.

---
 cmd/nand.c | 6 ------
 1 file changed, 6 deletions(-)
cmd/nand.c +0 -6
index ec7f1df..71ffe85 100644
@@ -528,8 +528,6 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		if (set_dev(dev))
 			return 1;
 
-		mtd = nand_info[dev];
-
 		memset(&opts, 0, sizeof(opts));
 		opts.offset = off;
 		opts.length = size;
@@ -597,8 +595,6 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 			if (set_dev(dev))
 				return 1;
 
-			mtd = nand_info[dev];
-
 			if (argc > 4 && !str2long(argv[4], &pagecount)) {
 				printf("'%s' is not a number\n", argv[4]);
 				return 1;
@@ -626,8 +622,6 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 			rwsize = size;
 		}
 
-		mtd = nand_info[dev];
-
 		if (!s || !strcmp(s, ".jffs2") ||
 		    !strcmp(s, ".e") || !strcmp(s, ".i")) {
 			if (read)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/1 cmd/nand.c: Remove unnecessarily repeated step

Dear Ahmed Samir Khalil,

Quoted 32 lines · Ahmed Samir Khalil

Getting the current NAND device is already done once as part
of nand command. Therefore, repeating this step as part of the sub-commands is unnecessary.

---
 cmd/nand.c | 6 ------
 1 file changed, 6 deletions(-)
cmd/nand.c +0 -4
index ec7f1df..71ffe85 100644
@@ -528,8 +528,6 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                if (set_dev(dev))
                        return 1;
 
-               mtd = nand_info[dev];
-
                memset(&opts, 0, sizeof(opts));
                opts.offset = off;
                opts.length = size;
@@ -597,8 +595,6 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                        if (set_dev(dev))
                                return 1;
 
-                       mtd = nand_info[dev];
-
                        if (argc > 4 && !str2long(argv[4], &pagecount)) {
                                printf("'%s' is not a number\n", argv[4]);
                                return 1;

cmd/nand.c static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) · line 627

Quoted 8 lines
cmd/nand.c +0 -2
@@ -626,8 +622,6 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                        rwsize = size;
                }
 
-               mtd = nand_info[dev];
-
                if (!s || !strcmp(s, ".jffs2") ||
                    !strcmp(s, ".e") || !strcmp(s, ".i")) {
                        if (read)

Quickly looking at the code, these assignments of mtd directly follow calls to mtd_arg_off_size(), which may alter dev, so they are required and should not be removed. This is even mentioned in the comment block above the initialization of mtd that you refer to: "The following commands operate on the current device, _unless overridden by a partition specifier_.".

Best regards,
Beno?t