mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Krzysztof Halasa <khc@pm.waw.pl>
Cc: barebox@lists.infradead.org
Subject: Re: RFC: memmap() now returns NULL on failure.
Date: Sun, 6 May 2012 20:05:55 +0200	[thread overview]
Message-ID: <20120506180555.GX4141@pengutronix.de> (raw)
In-Reply-To: <m3bom2mhek.fsf@intrepid.localdomain>

On Sat, May 05, 2012 at 11:45:07PM +0200, Krzysztof Halasa wrote:
> Originally, most callers expected -1 while some thought they'd get NULL
> on failure. NULL seems cleaner to me.

Unix mmap also returns (void *)-1, so returning this value is not that
unusual. I think we should keep this and fix the error checks instead,
for the reason you mention below.

Sascha

> 
> Of course is we want to allow memmapping of "/dev/ram" or something
> alike then we can't apply this patch, we need to fix the NULL-expecters
> instead. Alternatively we could pass &mem as an argument (that's what
> individual fs memmap implementations do).
> 
> Signed-off-by: Krzysztof Hałasa <khc@pm.waw.pl>
> 
> diff --git a/arch/arm/lib/bootu.c b/arch/arm/lib/bootu.c
> index 0d155cb..478525e 100644
> --- a/arch/arm/lib/bootu.c
> +++ b/arch/arm/lib/bootu.c
> @@ -17,7 +17,7 @@ static int do_bootu(int argc, char *argv[])
>  
>  	fd = open(argv[1], O_RDONLY);
>  	if (fd > 0)
> -		kernel = (void *)memmap(fd, PROT_READ);
> +		kernel = memmap(fd, PROT_READ);
>  
>  	if (!kernel)
>  		kernel = (void *)simple_strtoul(argv[1], NULL, 0);
> diff --git a/commands/bmp.c b/commands/bmp.c
> index 4130474..97e5877 100644
> --- a/commands/bmp.c
> +++ b/commands/bmp.c
> @@ -74,7 +74,7 @@ static int do_bmp(int argc, char *argv[])
>  	}
>  
>  	fb = memmap(fd, PROT_READ | PROT_WRITE);
> -	if (fb == (void *)-1) {
> +	if (fb == NULL) {
>  		perror("memmap");
>  		goto failed_memmap;
>  	}
> diff --git a/commands/go.c b/commands/go.c
> index e9e9d40..11b0cff 100644
> --- a/commands/go.c
> +++ b/commands/go.c
> @@ -49,7 +49,7 @@ static int do_go(int argc, char *argv[])
>  		}
>  
>  		addr = memmap(fd, PROT_READ);
> -		if (addr == (void *)-1) {
> +		if (addr == NULL) {
>  			perror("memmap");
>  			goto out;
>  		}
> diff --git a/common/digest.c b/common/digest.c
> index a327395..7cc5dc3 100644
> --- a/common/digest.c
> +++ b/common/digest.c
> @@ -97,7 +97,7 @@ int digest_file_window(struct digest *d, char *filename,
>  	}
>  
>  	buf = memmap(fd, PROT_READ);
> -	if (buf == (void *)-1) {
> +	if (buf == NULL) {
>  		buf = xmalloc(4096);
>  		flags = 1;
>  	}
> diff --git a/fs/fs.c b/fs/fs.c
> index 04dace4..4ebd2bc 100644
> --- a/fs/fs.c
> +++ b/fs/fs.c
> @@ -781,7 +781,7 @@ void *memmap(int fd, int flags)
>  	struct device_d *dev;
>  	struct fs_driver_d *fsdrv;
>  	FILE *f = &files[fd];
> -	void *ret = (void *)-1;
> +	void *ret = NULL;
>  
>  	if (check_fd(fd))
>  		return ret;
> 
> _______________________________________________
> 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:[~2012-05-06 18:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-05 21:45 Krzysztof Halasa
2012-05-06 18:05 ` 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=20120506180555.GX4141@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=khc@pm.waw.pl \
    /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