[PATCH 2/2] shpchp: Rename duplicate slot name N as N-1, N-2, N-M...

!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: Tuesday, July 29, 2008 - 10:44 pm

Commit ef0ff95f136f0f2d035667af5d18b824609de320 introduces the
shpchp_slot_with_bus module parameter, which was intended to help
work around broken firmware that assigns the same name to multiple
slots.

Commit b3bd307c628af2f0a581c42d5d7e4bcdbbf64b6a tells the user to
use the above parameter in the event of a name collision.

This approach is sub-optimal because it requires too much work from
the user.

Instead, let's rename the slot on behalf of the user. If firmware
assigns the name N to multiple slots, then:

        The first registered slot is assigned N
        The second registered slot is assigned N-1
        The third registered slot is assigned N-2
        The Mth registered slot becomes N-M

In the event we overflow the slot->name parameter, we report an
error to the user.

Signed-off-by: Alex Chiang <achiang@hp.com>
---
 drivers/pci/hotplug/shpchp_core.c |   34 +++++++++++++++-------------------
 1 files changed, 15 insertions(+), 19 deletions(-)

diff --git a/drivers/pci/hotplug/shpchp_core.c b/drivers/pci/hotplug/shpchp_core.c
index a8cbd03..cc38615 100644
--- a/drivers/pci/hotplug/shpchp_core.c
+++ b/drivers/pci/hotplug/shpchp_core.c
@@ -39,7 +39,6 @@
 int shpchp_debug;
 int shpchp_poll_mode;
 int shpchp_poll_time;
-static int shpchp_slot_with_bus;
 struct workqueue_struct *shpchp_wq;
 
 #define DRIVER_VERSION	"0.4"
@@ -53,11 +52,9 @@ MODULE_LICENSE("GPL");
 module_param(shpchp_debug, bool, 0644);
 module_param(shpchp_poll_mode, bool, 0644);
 module_param(shpchp_poll_time, int, 0644);
-module_param(shpchp_slot_with_bus, bool, 0644);
 MODULE_PARM_DESC(shpchp_debug, "Debugging mode enabled or not");
 MODULE_PARM_DESC(shpchp_poll_mode, "Using polling mechanism for hot-plug events or not");
 MODULE_PARM_DESC(shpchp_poll_time, "Polling mechanism frequency, in seconds");
-MODULE_PARM_DESC(shpchp_slot_with_bus, "Use bus number in the slot name");
 
 #define SHPC_MODULE_NAME "shpchp"
 
@@ -99,23 +96,13 @@ static void release_slot(struct hotplug_slot *hotplug_slot)
 	kfree(slot);
 }
 
-static void make_slot_name(struct slot *slot)
-{
-	if (shpchp_slot_with_bus)
-		snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%04d_%04d",
-			 slot->bus, slot->number);
-	else
-		snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%d",
-			 slot->number);
-}
-
 static int init_slots(struct controller *ctrl)
 {
 	struct slot *slot;
 	struct hotplug_slot *hotplug_slot;
 	struct hotplug_slot_info *info;
 	int retval = -ENOMEM;
-	int i;
+	int i, len, dup = 1;
 
 	for (i = 0; i < ctrl->num_slots; i++) {
 		slot = kzalloc(sizeof(*slot), GFP_KERNEL);
@@ -146,7 +133,7 @@ static int init_slots(struct controller *ctrl)
 		/* register this slot with the hotplug pci core */
 		hotplug_slot->private = slot;
 		hotplug_slot->release = &release_slot;
-		make_slot_name(slot);
+		snprintf(slot->name, SLOT_NAME_SIZE, "%d", slot->number);
 		hotplug_slot->ops = &shpchp_hotplug_slot_ops;
 
 		get_power_status(hotplug_slot, &info->power_status);
@@ -157,14 +144,23 @@ static int init_slots(struct controller *ctrl)
 		dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x "
 		    "slot_device_offset=%x\n", slot->bus, slot->device,
 		    slot->hp_slot, slot->number, ctrl->slot_device_offset);
+duplicate_name:
 		retval = pci_hp_register(slot->hotplug_slot,
 				ctrl->pci_dev->subordinate, slot->device);
 		if (retval) {
+			/*
+			 * If slot N already exists, we'll try to create
+			 * slot N-1, N-2 ... N-M, until we overflow.
+			 */
+			if (retval == -EEXIST) {
+				len = snprintf(slot->name, SLOT_NAME_SIZE,
+					       "%d-%d", slot->number, dup++);
+				if (len < SLOT_NAME_SIZE)
+					goto duplicate_name;
+				else
+					err("duplicate slot name overflow\n");
+			}
 			err("pci_hp_register failed with error %d\n", retval);
-			if (retval == -EEXIST)
-				err("Failed to register slot because of name "
-                                    "collision. Try \'shpchp_slot_with_bus\' "
-				    "module option.\n");
 			goto error_info;
 		}
 
-- 
1.6.0.rc0.g95f8

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

Messages in current thread:
post 2.6.26 requires pciehp_slot_with_bus, Pierre Ossman, (Thu Jul 24, 7:47 am)
Re: post 2.6.26 requires pciehp_slot_with_bus, Kenji Kaneshige, (Thu Jul 24, 8:38 am)
Re: post 2.6.26 requires pciehp_slot_with_bus, Pierre Ossman, (Thu Jul 24, 4:39 pm)
Re: post 2.6.26 requires pciehp_slot_with_bus, Jesse Barnes, (Thu Jul 24, 5:07 pm)
Re: post 2.6.26 requires pciehp_slot_with_bus, Pierre Ossman, (Thu Jul 24, 5:51 pm)
Re: post 2.6.26 requires pciehp_slot_with_bus, Jesse Barnes, (Thu Jul 24, 6:06 pm)
Re: post 2.6.26 requires pciehp_slot_with_bus, Alex Chiang, (Thu Jul 24, 6:29 pm)
Re: post 2.6.26 requires pciehp_slot_with_bus, Pierre Ossman, (Thu Jul 24, 6:49 pm)
Re: post 2.6.26 requires pciehp_slot_with_bus, Alex Chiang, (Thu Jul 24, 7:08 pm)
Re: post 2.6.26 requires pciehp_slot_with_bus, Pierre Ossman, (Thu Jul 24, 7:29 pm)
Re: post 2.6.26 requires pciehp_slot_with_bus, Kenji Kaneshige, (Fri Jul 25, 12:50 am)
Re: post 2.6.26 requires pciehp_slot_with_bus, Jesse Barnes, (Fri Jul 25, 6:18 pm)
Re: post 2.6.26 requires pciehp_slot_with_bus, Kenji Kaneshige, (Mon Jul 28, 4:44 am)
Re: post 2.6.26 requires pciehp_slot_with_bus, Matthew Wilcox, (Mon Jul 28, 12:57 pm)
Re: post 2.6.26 requires pciehp_slot_with_bus, Jesse Barnes, (Mon Jul 28, 12:16 pm)
Re: post 2.6.26 requires pciehp_slot_with_bus, Kenji Kaneshige, (Mon Jul 28, 10:43 pm)
Re: post 2.6.26 requires pciehp_slot_with_bus, Jesse Barnes, (Tue Jul 29, 11:14 am)
Re: post 2.6.26 requires pciehp_slot_with_bus, Kenji Kaneshige, (Tue Jul 29, 10:44 pm)
Re: post 2.6.26 requires pciehp_slot_with_bus, Matthew Wilcox, (Fri Jul 25, 9:16 pm)
Re: post 2.6.26 requires pciehp_slot_with_bus, Kenji Kaneshige, (Mon Jul 28, 4:58 am)
Re: post 2.6.26 requires pciehp_slot_with_bus, Matthew Wilcox, (Thu Jul 24, 11:29 pm)
Re: post 2.6.26 requires pciehp_slot_with_bus, Kenji Kaneshige, (Fri Jul 25, 4:53 am)
Re: post 2.6.26 requires pciehp_slot_with_bus, Matthew Wilcox, (Fri Jul 25, 7:40 am)
Re: post 2.6.26 requires pciehp_slot_with_bus, Kenji Kaneshige, (Mon Jul 28, 3:21 am)
Re: post 2.6.26 requires pciehp_slot_with_bus, Kenji Kaneshige, (Fri Jul 25, 12:57 am)
Re: post 2.6.26 requires pciehp_slot_with_bus, Alex Chiang, (Tue Jul 29, 10:38 pm)
Re: post 2.6.26 requires pciehp_slot_with_bus, Kenji Kaneshige, (Thu Jul 31, 6:31 am)
Re: post 2.6.26 requires pciehp_slot_with_bus, Alex Chiang, (Thu Jul 31, 11:47 am)
Re: post 2.6.26 requires pciehp_slot_with_bus, Kenji Kaneshige, (Fri Aug 1, 4:43 am)
[PATCH 2/2] shpchp: Rename duplicate slot name N as N-1, N-2..., Alex Chiang, (Tue Jul 29, 10:44 pm)
Re: post 2.6.26 requires pciehp_slot_with_bus, Alex Chiang, (Fri Jul 25, 12:42 am)
Re: post 2.6.26 requires pciehp_slot_with_bus, Greg KH, (Mon Jul 28, 2:05 pm)
Re: post 2.6.26 requires pciehp_slot_with_bus, Kenji Kaneshige, (Fri Jul 25, 1:38 am)
Re: post 2.6.26 requires pciehp_slot_with_bus, Matthew Wilcox, (Fri Jul 25, 7:18 am)