[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20080416134805.fdd139c1.akpm@linux-foundation.org>
Date: Wed, 16 Apr 2008 13:48:05 -0700
From: Andrew Morton <akpm@...ux-foundation.org>
To: Masami Hiramatsu <mhiramat@...hat.com>
Cc: penberg@...helsinki.fi, zanussi@...cast.net, dwilder@...ibm.com,
systemtap@...rces.redhat.com, linux-kernel@...r.kernel.org,
tzanussi@...il.com
Subject: Re: [PATCH -mm] relayfs: support larger relay buffer take 3
On Wed, 16 Apr 2008 15:51:56 -0400
Masami Hiramatsu <mhiramat@...hat.com> wrote:
> +static struct page **relay_alloc_page_array(unsigned int n_pages)
> +{
> + struct page **array;
> + unsigned int pa_size = n_pages * sizeof(struct page *);
> +
> + if (pa_size > PAGE_SIZE) {
> + array = vmalloc(pa_size);
> + if (array)
> + memset(array, 0, pa_size);
> + } else {
> + array = kcalloc(n_pages, sizeof(struct page *), GFP_KERNEL);
> + }
> + return array;
> +}
It's a bit odd to multiply n_pages*sizeof() and to then call kcalloc(),
which needs to do the same multiplication.
The compiler will presumably optimise that away, but still, how about this?
--- a/kernel/relay.c~relayfs-support-larger-relay-buffer-take-3-cleanup
+++ a/kernel/relay.c
@@ -71,14 +71,14 @@ static struct vm_operations_struct relay
static struct page **relay_alloc_page_array(unsigned int n_pages)
{
struct page **array;
- unsigned int pa_size = n_pages * sizeof(struct page *);
+ size_t pa_size = n_pages * sizeof(struct page *);
if (pa_size > PAGE_SIZE) {
array = vmalloc(pa_size);
if (array)
memset(array, 0, pa_size);
} else {
- array = kcalloc(n_pages, sizeof(struct page *), GFP_KERNEL);
+ array = kzalloc(pa_size, GFP_KERNEL);
}
return array;
}
_
size_t is strictly the correct type for pa_size here. Even though
vmalloc() takes a ulong.
--
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