Re: [PATCH] some kmalloc/memset ->kzalloc (tree wide)

From: yoann padioleau
Date: Sat Jul 07 2007 - 09:39:13 EST



On 7 juil. 07, at 15:07, Tilman Schmidt wrote:

Am 06.07.2007 18:51 schrieb Yoann Padioleau:
@@
expression E1,E2,E3;
@@

- kzalloc(E1 * E2,E3)
+ kcalloc(E1,E2,E3)

This misses the semantic distinction between the first and second
arguments of kcalloc(). The first argument is supposed to be the
number of elements to allocate and the second their size. As a
consequence, the following hunks in your pathc are wrong:

Yes you are right. Andrew Morton fixed the problem in a
subsequent patch.

I should have written a more precise semantic patch such as

@@
expression E;
constant c;
type T;
@@

- kzalloc(sizeof(T) * c, E)
+ kcalloc(c, sizeof(T), E)


Note that sometimes the code is written as kzalloc(c * sizeof(T), E)
as in kzalloc(2 * sizeof(struct resource), GFP_KERNEL) but
our transformation engine can handle the commutativity of '*' and still
performs the right transformation.



diff --git a/arch/arm/mach-iop13xx/pci.c b/arch/arm/mach-iop13xx/ pci.c
index 9d63d7f..b84955f 100644
--- a/arch/arm/mach-iop13xx/pci.c
+++ b/arch/arm/mach-iop13xx/pci.c
@@ -1002,11 +1002,10 @@ int iop13xx_pci_setup(int nr, struct pci
if (nr > 1)
return 0;

- res = kmalloc(sizeof(struct resource) * 2, GFP_KERNEL);
+ res = kcalloc(sizeof(struct resource), 2, GFP_KERNEL);
if (!res)
panic("PCI: unable to alloc resources");

- memset(res, 0, sizeof(struct resource) * 2);

/* 'nr' assumptions:
* ATUX is always 0



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