mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Oleg.Karfich@wago.com
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH] nand command: fix null pointer when adding/deleting a bb device
Date: Fri, 17 Aug 2018 08:18:37 +0200	[thread overview]
Message-ID: <20180817061837.c65oug6ydzcryrso@pengutronix.de> (raw)
In-Reply-To: <1534316853-11235-1-git-send-email-oleg.karfich@wago.com>

On Wed, Aug 15, 2018 at 07:07:40AM +0000, Oleg.Karfich@wago.com wrote:
> Commit 40ee300 introduces info option about bad blocks. The open()
> function call is therefore moved out from mark good/bad block to use the
> filedescriptor in info option too. If someone tries to add/delete a bb device
> the optind variable is incremented and the open() call gets a null pointer.
> Fix this issue by returning when the bb device is added/deleted.
> 
> Signed-off-by: Oleg Karfich <oleg.karfich@wago.com>
> ---
>  commands/nand.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/commands/nand.c b/commands/nand.c
> index b065a66..c57b394 100644
> --- a/commands/nand.c
> +++ b/commands/nand.c
> @@ -41,7 +41,7 @@ static int do_nand(int argc, char *argv[])
>  	int command = 0;
>  	loff_t badblock = 0;
>  	int fd;
> -	int ret;
> +	int ret = 0;
>  	struct mtd_info_user mtdinfo;
>  
>  	while((opt = getopt(argc, argv, "adb:g:i")) > 0) {
> @@ -88,13 +88,18 @@ static int do_nand(int argc, char *argv[])
>  
>  			optind++;
>  		}
> +
> +		goto out_ret;
>  	}
>  
>  	if (command == NAND_DEL) {
>  		while (optind < argc) {
> -			dev_remove_bb_dev(basename(argv[optind]));
> +			if (dev_remove_bb_dev(basename(argv[optind])))
> +				return 1;
>  			optind++;
>  		}
> +
> +		goto out_ret;
>  	}
>  
>  	fd = open(argv[optind], O_RDWR);
> @@ -149,10 +154,10 @@ static int do_nand(int argc, char *argv[])
>  			printf("No bad blocks\n");
>  	}
>  
> -	ret = 0;
>  out:
>  	close(fd);
>  
> +out_ret:
>  	return ret;
>  }
>  
> -- 
> 2.7.4
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

      reply	other threads:[~2018-08-17  6:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-15  7:07 Oleg.Karfich
2018-08-17  6:18 ` Sascha Hauer [this message]

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=20180817061837.c65oug6ydzcryrso@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=Oleg.Karfich@wago.com \
    --cc=barebox@lists.infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox