aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorRolf Eike Beer <eike-hotplug@sf-tec.de>2006-11-13 18:12:45 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2006-12-01 17:36:59 -0500
commitac9e98918776d8fa6dc38bfa6d298a7dbcbac2cb (patch)
tree13f80151fffb5845e8dfc13d9f6d54a81f48daa2 /drivers
parentadbc2a102252994c36102008293b52760613d6c3 (diff)
PCI: Change memory allocation for acpiphp slots
Change memory allocation for acpiphp slots Change the "struct slot" that acpiphp uses for managing it's slots to directly contain the memory for the needed struct hotplug_slot_info and the slot's name. This way we need only two memory allocations per slot instead of four. While we are at it: make_slot_name() is just a wrapper around snprintf() knowing the right arguments to call it. Since the function makes just one function call and is only called from one place I inlined it by hand. Finally this fixes a possible bug waiting for someone to hit it. There were two unused local variables in acpiphp_register_hotplug_slot(). gcc did not find them because they were used in memory allocations with sizeof(*var). They had the same types as the target of the allocation, but nevertheless this was just weird. Signed-off-by: Rolf Eike Beer <eike-hotplug@sf-tec.de> Acked-by: Matthew Wilcox <matthew@wil.cx> Signed-off-by: Kristen Carlson Accardi <kristen.c.accardi@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/pci/hotplug/acpiphp.h4
-rw-r--r--drivers/pci/hotplug/acpiphp_core.c35
2 files changed, 7 insertions, 32 deletions
diff --git a/drivers/pci/hotplug/acpiphp.h b/drivers/pci/hotplug/acpiphp.h
index 59c5b242d86d..ddbadd95387e 100644
--- a/drivers/pci/hotplug/acpiphp.h
+++ b/drivers/pci/hotplug/acpiphp.h
@@ -62,10 +62,10 @@ struct acpiphp_slot;
62struct slot { 62struct slot {
63 struct hotplug_slot *hotplug_slot; 63 struct hotplug_slot *hotplug_slot;
64 struct acpiphp_slot *acpi_slot; 64 struct acpiphp_slot *acpi_slot;
65 struct hotplug_slot_info info;
66 char name[SLOT_NAME_SIZE];
65}; 67};
66 68
67
68
69/** 69/**
70 * struct acpiphp_bridge - PCI bridge information 70 * struct acpiphp_bridge - PCI bridge information
71 * 71 *
diff --git a/drivers/pci/hotplug/acpiphp_core.c b/drivers/pci/hotplug/acpiphp_core.c
index c8b690741149..40c79b03c7ef 100644
--- a/drivers/pci/hotplug/acpiphp_core.c
+++ b/drivers/pci/hotplug/acpiphp_core.c
@@ -312,18 +312,6 @@ static int __init init_acpi(void)
312 return retval; 312 return retval;
313} 313}
314 314
315
316/**
317 * make_slot_name - make a slot name that appears in pcihpfs
318 * @slot: slot to name
319 *
320 */
321static void make_slot_name(struct slot *slot)
322{
323 snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%u",
324 slot->acpi_slot->sun);
325}
326
327/** 315/**
328 * release_slot - free up the memory used by a slot 316 * release_slot - free up the memory used by a slot
329 * @hotplug_slot: slot to free 317 * @hotplug_slot: slot to free
@@ -334,8 +322,6 @@ static void release_slot(struct hotplug_slot *hotplug_slot)
334 322
335 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 323 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
336 324
337 kfree(slot->hotplug_slot->info);
338 kfree(slot->hotplug_slot->name);
339 kfree(slot->hotplug_slot); 325 kfree(slot->hotplug_slot);
340 kfree(slot); 326 kfree(slot);
341} 327}
@@ -344,26 +330,19 @@ static void release_slot(struct hotplug_slot *hotplug_slot)
344int acpiphp_register_hotplug_slot(struct acpiphp_slot *acpiphp_slot) 330int acpiphp_register_hotplug_slot(struct acpiphp_slot *acpiphp_slot)
345{ 331{
346 struct slot *slot; 332 struct slot *slot;
347 struct hotplug_slot *hotplug_slot;
348 struct hotplug_slot_info *hotplug_slot_info;
349 int retval = -ENOMEM; 333 int retval = -ENOMEM;
350 334
351 slot = kzalloc(sizeof(*slot), GFP_KERNEL); 335 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
352 if (!slot) 336 if (!slot)
353 goto error; 337 goto error;
354 338
355 slot->hotplug_slot = kzalloc(sizeof(*hotplug_slot), GFP_KERNEL); 339 slot->hotplug_slot = kzalloc(sizeof(*slot->hotplug_slot), GFP_KERNEL);
356 if (!slot->hotplug_slot) 340 if (!slot->hotplug_slot)
357 goto error_slot; 341 goto error_slot;
358 342
359 slot->hotplug_slot->info = kzalloc(sizeof(*hotplug_slot_info), 343 slot->hotplug_slot->info = &slot->info;
360 GFP_KERNEL);
361 if (!slot->hotplug_slot->info)
362 goto error_hpslot;
363 344
364 slot->hotplug_slot->name = kzalloc(SLOT_NAME_SIZE, GFP_KERNEL); 345 slot->hotplug_slot->name = slot->name;
365 if (!slot->hotplug_slot->name)
366 goto error_info;
367 346
368 slot->hotplug_slot->private = slot; 347 slot->hotplug_slot->private = slot;
369 slot->hotplug_slot->release = &release_slot; 348 slot->hotplug_slot->release = &release_slot;
@@ -378,21 +357,17 @@ int acpiphp_register_hotplug_slot(struct acpiphp_slot *acpiphp_slot)
378 slot->hotplug_slot->info->cur_bus_speed = PCI_SPEED_UNKNOWN; 357 slot->hotplug_slot->info->cur_bus_speed = PCI_SPEED_UNKNOWN;
379 358
380 acpiphp_slot->slot = slot; 359 acpiphp_slot->slot = slot;
381 make_slot_name(slot); 360 snprintf(slot->name, sizeof(slot->name), "%u", slot->acpi_slot->sun);
382 361
383 retval = pci_hp_register(slot->hotplug_slot); 362 retval = pci_hp_register(slot->hotplug_slot);
384 if (retval) { 363 if (retval) {
385 err("pci_hp_register failed with error %d\n", retval); 364 err("pci_hp_register failed with error %d\n", retval);
386 goto error_name; 365 goto error_hpslot;
387 } 366 }
388 367
389 info("Slot [%s] registered\n", slot->hotplug_slot->name); 368 info("Slot [%s] registered\n", slot->hotplug_slot->name);
390 369
391 return 0; 370 return 0;
392error_name:
393 kfree(slot->hotplug_slot->name);
394error_info:
395 kfree(slot->hotplug_slot->info);
396error_hpslot: 371error_hpslot:
397 kfree(slot->hotplug_slot); 372 kfree(slot->hotplug_slot);
398error_slot: 373error_slot: