* [PATCH 3/3] remove explicit memset to memory allocated with k[zc]alloc
@ 2007-12-18 21:17 Christophe Jaillet
2007-12-18 22:53 ` Andi Drebes
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Christophe Jaillet @ 2007-12-18 21:17 UTC (permalink / raw)
To: kernel-janitors
1) Remove an explicit memset(.., 0, ...) to a varialable allocated with
kzalloc.
2) Allocate 'src' with kmalloc instead of kzalloc as all elements of the
'src' buffer are initialized in a 'for(...)' loop
Signed-off-by: Christophe Jaillet <christophe.jaillet@wanadoo.fr>
---
--- linux-2.6.24-rc5/drivers/dma/iop-adma.c 2007-12-16 11:15:52.000000000
+0100
+++ linux-2.6.24-rc5/drivers/dma/iop-adma.c.cj 2007-12-17 22:05:36.000000000
+0100
@@ -858,7 +858,7 @@ static int __devinit iop_adma_memcpy_sel
dev_dbg(device->common.dev, "%s\n", __FUNCTION__);
- src = kzalloc(sizeof(u8) * IOP_ADMA_TEST_SIZE, GFP_KERNEL);
+ src = kmalloc(sizeof(u8) * IOP_ADMA_TEST_SIZE, GFP_KERNEL);
if (!src)
return -ENOMEM;
dest = kzalloc(sizeof(u8) * IOP_ADMA_TEST_SIZE, GFP_KERNEL);
@@ -871,8 +871,6 @@ static int __devinit iop_adma_memcpy_sel
for (i = 0; i < IOP_ADMA_TEST_SIZE; i++)
((u8 *) src)[i] = (u8)i;
- memset(dest, 0, IOP_ADMA_TEST_SIZE);
-
/* Start copy, using first DMA channel */
dma_chan = container_of(device->common.channels.next,
struct dma_chan,
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH 3/3] remove explicit memset to memory allocated with k[zc]alloc
2007-12-18 21:17 [PATCH 3/3] remove explicit memset to memory allocated with k[zc]alloc Christophe Jaillet
@ 2007-12-18 22:53 ` Andi Drebes
2007-12-31 0:51 ` [PATCH 3/3] remove explicit memset to memory allocated with Adrian Bunk
2007-12-31 11:29 ` [PATCH 3/3] remove explicit memset to memory allocated with k[zc]alloc Andi Drebes
2 siblings, 0 replies; 4+ messages in thread
From: Andi Drebes @ 2007-12-18 22:53 UTC (permalink / raw)
To: kernel-janitors
Hi!
> 1) Remove an explicit memset(.., 0, ...) to a varialable allocated with
> kzalloc.
>
> 2) Allocate 'src' with kmalloc instead of kzalloc as all elements of the
> 'src' buffer are initialized in a 'for(...)' loop
The changes look good to me, but there's another thing that could be done in that file:
There's no need for the expression "sizeof(u8)" since it always returns 1. Could you
fix that too and submit a new patch?
There are quite a lot of statements like that in the kernel...
$ grep -r "sizeof(u8)" . | wc -l
53
> --- linux-2.6.24-rc5/drivers/dma/iop-adma.c 2007-12-16 11:15:52.000000000
> +0100
> +++ linux-2.6.24-rc5/drivers/dma/iop-adma.c.cj 2007-12-17 22:05:36.000000000
> +0100
> @@ -858,7 +858,7 @@ static int __devinit iop_adma_memcpy_sel
>
> dev_dbg(device->common.dev, "%s\n", __FUNCTION__);
>
> - src = kzalloc(sizeof(u8) * IOP_ADMA_TEST_SIZE, GFP_KERNEL);
> + src = kmalloc(sizeof(u8) * IOP_ADMA_TEST_SIZE, GFP_KERNEL);
> if (!src)
> return -ENOMEM;
> dest = kzalloc(sizeof(u8) * IOP_ADMA_TEST_SIZE, GFP_KERNEL);
> @@ -871,8 +871,6 @@ static int __devinit iop_adma_memcpy_sel
> for (i = 0; i < IOP_ADMA_TEST_SIZE; i++)
> ((u8 *) src)[i] = (u8)i;
>
> - memset(dest, 0, IOP_ADMA_TEST_SIZE);
> -
> /* Start copy, using first DMA channel */
> dma_chan = container_of(device->common.channels.next,
> struct dma_chan,
Regards,
Andi
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 3/3] remove explicit memset to memory allocated with
2007-12-18 21:17 [PATCH 3/3] remove explicit memset to memory allocated with k[zc]alloc Christophe Jaillet
2007-12-18 22:53 ` Andi Drebes
@ 2007-12-31 0:51 ` Adrian Bunk
2007-12-31 11:29 ` [PATCH 3/3] remove explicit memset to memory allocated with k[zc]alloc Andi Drebes
2 siblings, 0 replies; 4+ messages in thread
From: Adrian Bunk @ 2007-12-31 0:51 UTC (permalink / raw)
To: kernel-janitors
On Tue, Dec 18, 2007 at 11:53:58PM +0100, Andi Drebes wrote:
> Hi!
>
> > 1) Remove an explicit memset(.., 0, ...) to a varialable allocated with
> > kzalloc.
> >
> > 2) Allocate 'src' with kmalloc instead of kzalloc as all elements of the
> > 'src' buffer are initialized in a 'for(...)' loop
> The changes look good to me, but there's another thing that could be done in that file:
> There's no need for the expression "sizeof(u8)" since it always returns 1. Could you
> fix that too and submit a new patch?
>
> There are quite a lot of statements like that in the kernel...
>
> $ grep -r "sizeof(u8)" . | wc -l
> 53
What is the problem you are trying to solve?
It might in some places be an improvement to replace a sizeof(u8) with a
sizeof() on the actual variable, but blindly replacing sizeof(u8) with 1
sounds like an attempt to make the code harder to read without bringing
any advantage...
> Regards,
> Andi
cu
Adrian
--
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH 3/3] remove explicit memset to memory allocated with k[zc]alloc
2007-12-18 21:17 [PATCH 3/3] remove explicit memset to memory allocated with k[zc]alloc Christophe Jaillet
2007-12-18 22:53 ` Andi Drebes
2007-12-31 0:51 ` [PATCH 3/3] remove explicit memset to memory allocated with Adrian Bunk
@ 2007-12-31 11:29 ` Andi Drebes
2 siblings, 0 replies; 4+ messages in thread
From: Andi Drebes @ 2007-12-31 11:29 UTC (permalink / raw)
To: kernel-janitors
> > There are quite a lot of statements like that in the kernel...
> >
> > $ grep -r "sizeof(u8)" . | wc -l
> > 53
>
> What is the problem you are trying to solve?
> It might in some places be an improvement to replace a sizeof(u8) with a
> sizeof() on the actual variable, but blindly replacing sizeof(u8) with 1
> sounds like an attempt to make the code harder to read without bringing
> any advantage...
Perhaps my comments on the particular patch from Christophe sounded as if
they applied to all sizeof(u8) statements. I was not talking about *blindly*
replacing them. I didn't even say that they *all* should be replaced. What
I wanted to say was: maybe one should have a look at other places in the
kernel aswell. The above grep was just a quick grep through the sources.
Of course, there's no functional problem with sizeof(u8). It should be kept
in places where it makes things clear. But in my eyes, sizeof(u8) in something
like this (as in the lines affected by the patch):
kmalloc(sizeof(u8) * IOP_ADMA_TEST_SIZE, GFP_KERNEL);
isn't very useful. I think it's quite clear that kmalloc takes a number of
bytes as the first argument. So replacing the above code with the following
kmalloc(IOP_ADMA_TEST_SIZE, GFP_KERNEL);
would save some bytes and make it compile faster. And it isn't harder to read.
However, I don't insist on changes like that. I just thought that for
drivers/dma/iop-adma.c it may be included in Christophe's patch.
Andi
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-12-31 11:29 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-18 21:17 [PATCH 3/3] remove explicit memset to memory allocated with k[zc]alloc Christophe Jaillet
2007-12-18 22:53 ` Andi Drebes
2007-12-31 0:51 ` [PATCH 3/3] remove explicit memset to memory allocated with Adrian Bunk
2007-12-31 11:29 ` [PATCH 3/3] remove explicit memset to memory allocated with k[zc]alloc Andi Drebes
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.