[PATCH 6/7] pci_slot: convert to a kmalloc'ed slot name

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Kenji Kaneshige <kaneshige.kenji@...>, Matthew Wilcox <matthew@...>, Pierre Ossman <drzeus-list@...>, Jesse Barnes <jbarnes@...>, LKML <linux-kernel@...>, <linux-pci@...>
Date: Wednesday, August 6, 2008 - 1:12 am

Callers of pci_create_slot() need to be converted from a
char name[] to a char *name.

This change allows pci_create_slot() to dynamically rename the
sysfs name of the slot in the event of a name collision.

Signed-off-by: Alex Chiang <achiang@hp.com>
---
 drivers/acpi/pci_slot.c |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/acpi/pci_slot.c b/drivers/acpi/pci_slot.c
index d5b4ef8..b146b72 100644
--- a/drivers/acpi/pci_slot.c
+++ b/drivers/acpi/pci_slot.c
@@ -133,7 +133,7 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
 {
 	int device;
 	unsigned long sun;
-	char name[SLOT_NAME_SIZE];
+	char *name;
 	struct acpi_pci_slot *slot;
 	struct pci_slot *pci_slot;
 	struct callback_args *parent_context = context;
@@ -149,10 +149,18 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
 		return AE_OK;
 	}
 
-	snprintf(name, sizeof(name), "%u", (u32)sun);
+	name = kzalloc(SLOT_NAME_SIZE, GFP_KERNEL);
+	if (!name) {
+		err("%s: cannot allocate memory for name\n", __func__);
+		kfree(slot);
+		return AE_OK;
+	}
+
+	snprintf(name, SLOT_NAME_SIZE, "%u", (u32)sun);
 	pci_slot = pci_create_slot(pci_bus, device, name);
 	if (IS_ERR(pci_slot)) {
 		err("pci_create_slot returned %ld\n", PTR_ERR(pci_slot));
+		kfree(name);
 		kfree(slot);
 		return AE_OK;
 	}
@@ -167,6 +175,8 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
 	dbg("pci_slot: %p, pci_bus: %x, device: %d, name: %s\n",
 		pci_slot, pci_bus->number, device, name);
 
+	kfree(name);
+
 	return AE_OK;
 }
 
-- 
1.6.0.rc0.g95f8

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 0/7] Fixups for duplicate slot names, Alex Chiang, (Wed Aug 6, 1:07 am)
Re: [PATCH 0/7] Fixups for duplicate slot names, Kenji Kaneshige, (Thu Aug 7, 4:43 am)
Re: [PATCH 0/7] Fixups for duplicate slot names, Alex Chiang, (Thu Aug 7, 1:25 pm)
Re: [PATCH 0/7] Fixups for duplicate slot names, Kenji Kaneshige, (Sun Aug 10, 9:19 pm)
[PATCH 6/7] pci_slot: convert to a kmalloc'ed slot name, Alex Chiang, (Wed Aug 6, 1:12 am)