[PATCH 05/10] nand command: use enumeration for command instead of bitmask

Alexander Aring alex.aring at gmail.com
Mon Mar 4 16:25:36 EST 2013


Hi,


On Mon, Mar 04, 2013 at 11:13:49AM +0100, Sascha Hauer wrote:
> A command can only be one of NAND_*, so use an enumeration instead
> of a bitmask.
> 
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> ---
>  commands/nand.c |   12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/commands/nand.c b/commands/nand.c
> index d00845f..79f6735 100644
> --- a/commands/nand.c
> +++ b/commands/nand.c
> @@ -29,9 +29,9 @@
>  #include <fcntl.h>
>  #include <libgen.h>
>  
> -#define NAND_ADD (1 << 0)
> -#define NAND_DEL (1 << 1)
> -#define NAND_MARKBAD (1 << 2)
> +#define NAND_ADD	1
> +#define NAND_DEL	2
> +#define NAND_MARKBAD	3
>  
>  static int do_nand(int argc, char *argv[])
>  {
> @@ -58,7 +58,7 @@ static int do_nand(int argc, char *argv[])
>  		}
>  	}
>  
> -	if (command & NAND_ADD) {
> +	if (command == NAND_ADD) {

some nitpick. Can we use switch case instead of if? With a default
branch when command == 0 to return COMMAND_ERROR_USAGE?

>  		while (optind < argc) {
>  			if (dev_add_bb_dev(basename(argv[optind]), NULL))
>  				return 1;
> @@ -67,14 +67,14 @@ static int do_nand(int argc, char *argv[])
>  		}
>  	}
>  
> -	if (command & NAND_DEL) {
> +	if (command == NAND_DEL) {
>  		while (optind < argc) {
>  			dev_remove_bb_dev(basename(argv[optind]));
>  			optind++;
>  		}
>  	}
>  
> -	if (command & NAND_MARKBAD) {
> +	if (command == NAND_MARKBAD) {
>  		if (optind < argc) {
>  			int ret = 0, fd;
>  
> -- 
> 1.7.10.4
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox



More information about the barebox mailing list