Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jbarnes/pci-2.6

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jbarnes/pci-2.6:
PCI: fix reference leak in pci_get_dev_by_id()
PCI: shpchp: Rename duplicate slot name N as N-1, N-2, N-M...
PCI: pciehp: Rename duplicate slot name N as N-1, N-2, N-M...

+32 -37
-1
drivers/pci/hotplug/pciehp.h
··· 43 extern int pciehp_poll_time; 44 extern int pciehp_debug; 45 extern int pciehp_force; 46 - extern int pciehp_slot_with_bus; 47 extern struct workqueue_struct *pciehp_wq; 48 49 #define dbg(format, arg...) \
··· 43 extern int pciehp_poll_time; 44 extern int pciehp_debug; 45 extern int pciehp_force; 46 extern struct workqueue_struct *pciehp_wq; 47 48 #define dbg(format, arg...) \
+14 -7
drivers/pci/hotplug/pciehp_core.c
··· 41 int pciehp_poll_mode; 42 int pciehp_poll_time; 43 int pciehp_force; 44 - int pciehp_slot_with_bus; 45 struct workqueue_struct *pciehp_wq; 46 47 #define DRIVER_VERSION "0.4" ··· 55 module_param(pciehp_poll_mode, bool, 0644); 56 module_param(pciehp_poll_time, int, 0644); 57 module_param(pciehp_force, bool, 0644); 58 - module_param(pciehp_slot_with_bus, bool, 0644); 59 MODULE_PARM_DESC(pciehp_debug, "Debugging mode enabled or not"); 60 MODULE_PARM_DESC(pciehp_poll_mode, "Using polling mechanism for hot-plug events or not"); 61 MODULE_PARM_DESC(pciehp_poll_time, "Polling mechanism frequency, in seconds"); 62 MODULE_PARM_DESC(pciehp_force, "Force pciehp, even if _OSC and OSHP are missing"); 63 - MODULE_PARM_DESC(pciehp_slot_with_bus, "Use bus number in the slot name"); 64 65 #define PCIE_MODULE_NAME "pciehp" 66 ··· 191 struct slot *slot; 192 struct hotplug_slot *hotplug_slot; 193 struct hotplug_slot_info *info; 194 int retval = -ENOMEM; 195 196 list_for_each_entry(slot, &ctrl->slot_list, slot_list) { ··· 218 dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x " 219 "slot_device_offset=%x\n", slot->bus, slot->device, 220 slot->hp_slot, slot->number, ctrl->slot_device_offset); 221 retval = pci_hp_register(hotplug_slot, 222 ctrl->pci_dev->subordinate, 223 slot->device); 224 if (retval) { 225 err("pci_hp_register failed with error %d\n", retval); 226 - if (retval == -EEXIST) 227 - err("Failed to register slot because of name " 228 - "collision. Try \'pciehp_slot_with_bus\' " 229 - "module option.\n"); 230 goto error_info; 231 } 232 /* create additional sysfs entries */
··· 41 int pciehp_poll_mode; 42 int pciehp_poll_time; 43 int pciehp_force; 44 struct workqueue_struct *pciehp_wq; 45 46 #define DRIVER_VERSION "0.4" ··· 56 module_param(pciehp_poll_mode, bool, 0644); 57 module_param(pciehp_poll_time, int, 0644); 58 module_param(pciehp_force, bool, 0644); 59 MODULE_PARM_DESC(pciehp_debug, "Debugging mode enabled or not"); 60 MODULE_PARM_DESC(pciehp_poll_mode, "Using polling mechanism for hot-plug events or not"); 61 MODULE_PARM_DESC(pciehp_poll_time, "Polling mechanism frequency, in seconds"); 62 MODULE_PARM_DESC(pciehp_force, "Force pciehp, even if _OSC and OSHP are missing"); 63 64 #define PCIE_MODULE_NAME "pciehp" 65 ··· 194 struct slot *slot; 195 struct hotplug_slot *hotplug_slot; 196 struct hotplug_slot_info *info; 197 + int len, dup = 1; 198 int retval = -ENOMEM; 199 200 list_for_each_entry(slot, &ctrl->slot_list, slot_list) { ··· 220 dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x " 221 "slot_device_offset=%x\n", slot->bus, slot->device, 222 slot->hp_slot, slot->number, ctrl->slot_device_offset); 223 + duplicate_name: 224 retval = pci_hp_register(hotplug_slot, 225 ctrl->pci_dev->subordinate, 226 slot->device); 227 if (retval) { 228 + /* 229 + * If slot N already exists, we'll try to create 230 + * slot N-1, N-2 ... N-M, until we overflow. 231 + */ 232 + if (retval == -EEXIST) { 233 + len = snprintf(slot->name, SLOT_NAME_SIZE, 234 + "%d-%d", slot->number, dup++); 235 + if (len < SLOT_NAME_SIZE) 236 + goto duplicate_name; 237 + else 238 + err("duplicate slot name overflow\n"); 239 + } 240 err("pci_hp_register failed with error %d\n", retval); 241 goto error_info; 242 } 243 /* create additional sysfs entries */
+1 -10
drivers/pci/hotplug/pciehp_hpc.c
··· 1030 pciehp_free_irq(ctrl); 1031 } 1032 1033 - static void make_slot_name(struct slot *slot) 1034 - { 1035 - if (pciehp_slot_with_bus) 1036 - snprintf(slot->name, SLOT_NAME_SIZE, "%04d_%04d", 1037 - slot->bus, slot->number); 1038 - else 1039 - snprintf(slot->name, SLOT_NAME_SIZE, "%d", slot->number); 1040 - } 1041 - 1042 static int pcie_init_slot(struct controller *ctrl) 1043 { 1044 struct slot *slot; ··· 1044 slot->device = ctrl->slot_device_offset + slot->hp_slot; 1045 slot->hpc_ops = ctrl->hpc_ops; 1046 slot->number = ctrl->first_slot; 1047 - make_slot_name(slot); 1048 mutex_init(&slot->lock); 1049 INIT_DELAYED_WORK(&slot->work, pciehp_queue_pushbutton_work); 1050 list_add(&slot->slot_list, &ctrl->slot_list);
··· 1030 pciehp_free_irq(ctrl); 1031 } 1032 1033 static int pcie_init_slot(struct controller *ctrl) 1034 { 1035 struct slot *slot; ··· 1053 slot->device = ctrl->slot_device_offset + slot->hp_slot; 1054 slot->hpc_ops = ctrl->hpc_ops; 1055 slot->number = ctrl->first_slot; 1056 + snprintf(slot->name, SLOT_NAME_SIZE, "%d", slot->number); 1057 mutex_init(&slot->lock); 1058 INIT_DELAYED_WORK(&slot->work, pciehp_queue_pushbutton_work); 1059 list_add(&slot->slot_list, &ctrl->slot_list);
+15 -19
drivers/pci/hotplug/shpchp_core.c
··· 39 int shpchp_debug; 40 int shpchp_poll_mode; 41 int shpchp_poll_time; 42 - static int shpchp_slot_with_bus; 43 struct workqueue_struct *shpchp_wq; 44 45 #define DRIVER_VERSION "0.4" ··· 52 module_param(shpchp_debug, bool, 0644); 53 module_param(shpchp_poll_mode, bool, 0644); 54 module_param(shpchp_poll_time, int, 0644); 55 - module_param(shpchp_slot_with_bus, bool, 0644); 56 MODULE_PARM_DESC(shpchp_debug, "Debugging mode enabled or not"); 57 MODULE_PARM_DESC(shpchp_poll_mode, "Using polling mechanism for hot-plug events or not"); 58 MODULE_PARM_DESC(shpchp_poll_time, "Polling mechanism frequency, in seconds"); 59 - MODULE_PARM_DESC(shpchp_slot_with_bus, "Use bus number in the slot name"); 60 61 #define SHPC_MODULE_NAME "shpchp" 62 ··· 96 kfree(slot); 97 } 98 99 - static void make_slot_name(struct slot *slot) 100 - { 101 - if (shpchp_slot_with_bus) 102 - snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%04d_%04d", 103 - slot->bus, slot->number); 104 - else 105 - snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%d", 106 - slot->number); 107 - } 108 - 109 static int init_slots(struct controller *ctrl) 110 { 111 struct slot *slot; 112 struct hotplug_slot *hotplug_slot; 113 struct hotplug_slot_info *info; 114 int retval = -ENOMEM; 115 - int i; 116 117 for (i = 0; i < ctrl->num_slots; i++) { 118 slot = kzalloc(sizeof(*slot), GFP_KERNEL); ··· 133 /* register this slot with the hotplug pci core */ 134 hotplug_slot->private = slot; 135 hotplug_slot->release = &release_slot; 136 - make_slot_name(slot); 137 hotplug_slot->ops = &shpchp_hotplug_slot_ops; 138 139 get_power_status(hotplug_slot, &info->power_status); ··· 144 dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x " 145 "slot_device_offset=%x\n", slot->bus, slot->device, 146 slot->hp_slot, slot->number, ctrl->slot_device_offset); 147 retval = pci_hp_register(slot->hotplug_slot, 148 ctrl->pci_dev->subordinate, slot->device); 149 if (retval) { 150 err("pci_hp_register failed with error %d\n", retval); 151 - if (retval == -EEXIST) 152 - err("Failed to register slot because of name " 153 - "collision. Try \'shpchp_slot_with_bus\' " 154 - "module option.\n"); 155 goto error_info; 156 } 157
··· 39 int shpchp_debug; 40 int shpchp_poll_mode; 41 int shpchp_poll_time; 42 struct workqueue_struct *shpchp_wq; 43 44 #define DRIVER_VERSION "0.4" ··· 53 module_param(shpchp_debug, bool, 0644); 54 module_param(shpchp_poll_mode, bool, 0644); 55 module_param(shpchp_poll_time, int, 0644); 56 MODULE_PARM_DESC(shpchp_debug, "Debugging mode enabled or not"); 57 MODULE_PARM_DESC(shpchp_poll_mode, "Using polling mechanism for hot-plug events or not"); 58 MODULE_PARM_DESC(shpchp_poll_time, "Polling mechanism frequency, in seconds"); 59 60 #define SHPC_MODULE_NAME "shpchp" 61 ··· 99 kfree(slot); 100 } 101 102 static int init_slots(struct controller *ctrl) 103 { 104 struct slot *slot; 105 struct hotplug_slot *hotplug_slot; 106 struct hotplug_slot_info *info; 107 int retval = -ENOMEM; 108 + int i, len, dup = 1; 109 110 for (i = 0; i < ctrl->num_slots; i++) { 111 slot = kzalloc(sizeof(*slot), GFP_KERNEL); ··· 146 /* register this slot with the hotplug pci core */ 147 hotplug_slot->private = slot; 148 hotplug_slot->release = &release_slot; 149 + snprintf(slot->name, SLOT_NAME_SIZE, "%d", slot->number); 150 hotplug_slot->ops = &shpchp_hotplug_slot_ops; 151 152 get_power_status(hotplug_slot, &info->power_status); ··· 157 dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x " 158 "slot_device_offset=%x\n", slot->bus, slot->device, 159 slot->hp_slot, slot->number, ctrl->slot_device_offset); 160 + duplicate_name: 161 retval = pci_hp_register(slot->hotplug_slot, 162 ctrl->pci_dev->subordinate, slot->device); 163 if (retval) { 164 + /* 165 + * If slot N already exists, we'll try to create 166 + * slot N-1, N-2 ... N-M, until we overflow. 167 + */ 168 + if (retval == -EEXIST) { 169 + len = snprintf(slot->name, SLOT_NAME_SIZE, 170 + "%d-%d", slot->number, dup++); 171 + if (len < SLOT_NAME_SIZE) 172 + goto duplicate_name; 173 + else 174 + err("duplicate slot name overflow\n"); 175 + } 176 err("pci_hp_register failed with error %d\n", retval); 177 goto error_info; 178 } 179
+2
drivers/pci/search.c
··· 280 match_pci_dev_by_id); 281 if (dev) 282 pdev = to_pci_dev(dev); 283 return pdev; 284 } 285
··· 280 match_pci_dev_by_id); 281 if (dev) 282 pdev = to_pci_dev(dev); 283 + if (from) 284 + pci_dev_put(from); 285 return pdev; 286 } 287