lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1177343905.6284.22.camel@mulgrave>
Date:	Mon, 23 Apr 2007 11:58:25 -0400
From:	James Bottomley <James.Bottomley@...elEye.com>
To:	Guennadi Liakhovetski <g.liakhovetski@....de>
Cc:	linux-kernel@...r.kernel.org, jayalk@...works.biz,
	akpm@...ux-foundation.org
Subject: Re: [PATCH] dma_declare_coherent_memory wrong allocation

On Mon, 2007-04-23 at 00:45 +0200, Guennadi Liakhovetski wrote:
> Right, thinko. How about using his:
> 
> +	int pages = DIV_ROUND_UP(size, PAGE_SIZE);

Actually, no ... this has to be size >> PAGE_SHIFT.  The reason being
that the  allocator is designed to allocate pages out of a device memory
buffer.  If the size isn't a multiple of page size, we have to round
down (we can't allocate the last page if the memory we have is only part
of a page).

I suppose if you want to catch the unlikely nutcase where size <
PAGE_SIZE you could

if (unlikely(pages == 0))
	goto out;

> +	int bitmap_size = BITS_TO_LONGS(pages) * BYTES_PER_LONG;

This is fine, except the BYTES_PER_LONG.  Traditionally, we do this with
sizeof(long).  The only reason to have a #define for it is if it has to
be used in a macro (the compiler does sizeof() not the preprocessor).

How about just a simple

int bitmap_size = BITS_TO_LONGS(pages) * sizeof(long);

?

Then you don't need the first patch defining BYTES_PER_LONG.

> to also allow for size not an integer number of pages as Andrew noticed? 
> This could be done in 2 patches:

James


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ