Skip to contentSkip to conversation

arch/x86/pci: use kasprintf

tip:x86/urgent tip-bot for Julia Lawall 1 participant 1 message May 24, 2010 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Commit-ID:  b46fc5f235be04a7f77fb2af1d8cb809889c25c1
Gitweb:     http://git.kernel.org/tip/b46fc5f235be04a7f77fb2af1d8cb809889c25c1
Author:     Julia Lawall <[email protected]>
AuthorDate: Mon, 24 May 2010 12:13:16 -0700
Committer:  H. Peter Anvin <[email protected]>
CommitDate: Mon, 24 May 2010 13:31:45 -0700

arch/x86/pci: use kasprintf

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>

LKML-Reference: <[email protected]>

---
 arch/x86/pci/acpi.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
arch/x86/pci/acpi.c +1 -2
index 31930fd..7c0ad63 100644
@@ -207,10 +207,9 @@ get_current_resources(struct acpi_device *device, int busnum,
 	if (!info.res)
 		goto res_alloc_fail;
 
-	info.name = kmalloc(16, GFP_KERNEL);
+	info.name = kasprintf(GFP_KERNEL, "PCI Bus %04x:%02x", domain, busnum);
 	if (!info.name)
 		goto name_alloc_fail;
-	sprintf(info.name, "PCI Bus %04x:%02x", domain, busnum);
 
 	info.res_num = 0;
 	acpi_walk_resources(device->handle, METHOD_NAME__CRS, setup_resource,