Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[PATCH 1/6] arch/powerpc/platforms/pseries: Use kasprintf

0 views
Skip to first unread message

Julia Lawall

unread,
Mar 10, 2010, 4:20:03 PM3/10/10
to
From: Julia Lawall <ju...@diku.dk>

kasprintf combines kmalloc and sprintf, and takes care of the size
calculation itself.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression a,flag;
expression list args;
statement S;
@@

a =
- \(kmalloc\|kzalloc\)(...,flag)
+ kasprintf(flag,args)
<... when != a
if (a == NULL || ...) S
...>
- sprintf(a,args);
// </smpl>

Signed-off-by: Julia Lawall <ju...@diku.dk>

---
arch/powerpc/platforms/pseries/dlpar.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)

diff -u -p a/arch/powerpc/platforms/pseries/dlpar.c b/arch/powerpc/platforms/pseries/dlpar.c
--- a/arch/powerpc/platforms/pseries/dlpar.c
+++ b/arch/powerpc/platforms/pseries/dlpar.c
@@ -78,13 +78,12 @@ static struct device_node *dlpar_parse_c
* prepend this to the full_name.
*/
name = (char *)ccwa + ccwa->name_offset;
- dn->full_name = kmalloc(strlen(name) + 2, GFP_KERNEL);
+ dn->full_name = kasprintf(GFP_KERNEL, "/%s", name);
if (!dn->full_name) {
kfree(dn);
return NULL;
}

- sprintf(dn->full_name, "/%s", name);
return dn;
}

@@ -409,15 +408,13 @@ static ssize_t dlpar_cpu_probe(const cha
* directory of the device tree. CPUs actually live in the
* cpus directory so we need to fixup the full_name.
*/
- cpu_name = kzalloc(strlen(dn->full_name) + strlen("/cpus") + 1,
- GFP_KERNEL);
+ cpu_name = kasprintf(GFP_KERNEL, "/cpus%s", dn->full_name);
if (!cpu_name) {
dlpar_free_cc_nodes(dn);
rc = -ENOMEM;
goto out;
}

- sprintf(cpu_name, "/cpus%s", dn->full_name);
kfree(dn->full_name);
dn->full_name = cpu_name;

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

Nathan Fontenot

unread,
Mar 11, 2010, 10:20:01 AM3/11/10
to
Julia Lawall wrote:
> From: Julia Lawall <ju...@diku.dk>
>
> kasprintf combines kmalloc and sprintf, and takes care of the size
> calculation itself.
>
> The semantic patch that makes this change is as follows:
> (http://coccinelle.lip6.fr/)
>
> // <smpl>
> @@
> expression a,flag;
> expression list args;
> statement S;
> @@
>
> a =
> - \(kmalloc\|kzalloc\)(...,flag)
> + kasprintf(flag,args)
> <... when != a
> if (a == NULL || ...) S
> ...>
> - sprintf(a,args);
> // </smpl>
>

Looks good, thanks.

> Signed-off-by: Julia Lawall <ju...@diku.dk>
Acked-by: Nathan Fontenot <nf...@austin.ibm.com>

> _______________________________________________
> Linuxppc-dev mailing list
> Linuxp...@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/linuxppc-dev

0 new messages