All of lore.kernel.org
 help / color / mirror / Atom feed
From: roel <12o3l@tiscali.nl>
To: Matthew Wilcox <willy@linux.intel.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/4] dmapool: Validate parameters to dma_pool_create
Date: Wed, 26 Sep 2007 21:47:41 +0200	[thread overview]
Message-ID: <46FAB75D.9020800@tiscali.nl> (raw)
In-Reply-To: <11908332793750-git-send-email-willy@linux.intel.com>

Matthew Wilcox wrote:
> Check that 'align' is a power of two, like the API specifies.
> Align 'size' to 'align' correctly -- the current code has an off-by-one.
> The ALIGN macro in kernel.h doesn't.
> 
> Signed-off-by: Matthew Wilcox <willy@linux.intel.com>
> ---
>  mm/dmapool.c |   15 ++++++++-------
>  1 files changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/mm/dmapool.c b/mm/dmapool.c
> index a359b5e..f5d12a7 100644
> --- a/mm/dmapool.c
> +++ b/mm/dmapool.c
> @@ -107,17 +107,18 @@ struct dma_pool *dma_pool_create(const char *name, struct device *dev,
>  {
>  	struct dma_pool *retval;
>  
> -	if (align == 0)
> +	if (align == 0) {
>  		align = 1;
> -	if (size == 0)
> +	} else if (align & (align - 1)) {
>  		return NULL;
> -	else if (size < align)
> -		size = align;
> -	else if ((size % align) != 0) {
> -		size += align + 1;
> -		size &= ~(align - 1);
>  	}
>  
> +	if (size == 0)
> +		return NULL;

The brackets in the first if/else are not required, and you could combine the two statements:

	if (align == 0)
		align = 1;
	else if (align & (align - 1) || size == 0)
		return NULL;
> +
> +	if ((size % align) != 0)
> +		size = ALIGN(size, align);
> +
>  	if (allocation == 0) {
>  		if (PAGE_SIZE < size)
>  			allocation = size;


  reply	other threads:[~2007-09-26 19:47 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-26 18:57 dmapool Matthew Wilcox
2007-09-26 19:01 ` [PATCH 1/4] Avoid taking waitqueue lock in dmapool Matthew Wilcox
2007-09-26 21:10   ` David Miller
2007-09-26 19:01 ` [PATCH 2/4] dmapool: Validate parameters to dma_pool_create Matthew Wilcox
2007-09-26 19:47   ` roel [this message]
     [not found]     ` <20070926214022.GA14710@linuxntel.com>
2007-09-26 21:08       ` roel
2007-09-26 21:10   ` David Miller
2007-09-26 19:01 ` [PATCH 3/4] Change dmapool free block management Matthew Wilcox
2007-09-26 19:23   ` Roland Dreier
2007-09-26 20:07   ` roel
2007-09-26 21:13   ` David Miller
2007-09-26 19:01 ` [PATCH 4/4] dmapool: Improve memory usage for devices which can't cross boundaries Matthew Wilcox
2007-09-26 20:12   ` roel
2007-09-26 21:14   ` David Miller

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=46FAB75D.9020800@tiscali.nl \
    --to=12o3l@tiscali.nl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=willy@linux.intel.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.