Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>


authored by

Rolf Eike Beer and committed by
Greg Kroah-Hartman
ac9e9891 adbc2a10

+7 -32
+2 -2
drivers/pci/hotplug/acpiphp.h
··· 62 62 struct slot { 63 63 struct hotplug_slot *hotplug_slot; 64 64 struct acpiphp_slot *acpi_slot; 65 + struct hotplug_slot_info info; 66 + char name[SLOT_NAME_SIZE]; 65 67 }; 66 - 67 - 68 68 69 69 /** 70 70 * struct acpiphp_bridge - PCI bridge information
+5 -30
drivers/pci/hotplug/acpiphp_core.c
··· 312 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 - */ 321 - static 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 316 * release_slot - free up the memory used by a slot 329 317 * @hotplug_slot: slot to free ··· 322 334 323 335 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 324 336 325 - kfree(slot->hotplug_slot->info); 326 - kfree(slot->hotplug_slot->name); 327 337 kfree(slot->hotplug_slot); 328 338 kfree(slot); 329 339 } ··· 330 344 int acpiphp_register_hotplug_slot(struct acpiphp_slot *acpiphp_slot) 331 345 { 332 346 struct slot *slot; 333 - struct hotplug_slot *hotplug_slot; 334 - struct hotplug_slot_info *hotplug_slot_info; 335 347 int retval = -ENOMEM; 336 348 337 349 slot = kzalloc(sizeof(*slot), GFP_KERNEL); 338 350 if (!slot) 339 351 goto error; 340 352 341 - slot->hotplug_slot = kzalloc(sizeof(*hotplug_slot), GFP_KERNEL); 353 + slot->hotplug_slot = kzalloc(sizeof(*slot->hotplug_slot), GFP_KERNEL); 342 354 if (!slot->hotplug_slot) 343 355 goto error_slot; 344 356 345 - slot->hotplug_slot->info = kzalloc(sizeof(*hotplug_slot_info), 346 - GFP_KERNEL); 347 - if (!slot->hotplug_slot->info) 348 - goto error_hpslot; 357 + slot->hotplug_slot->info = &slot->info; 349 358 350 - slot->hotplug_slot->name = kzalloc(SLOT_NAME_SIZE, GFP_KERNEL); 351 - if (!slot->hotplug_slot->name) 352 - goto error_info; 359 + slot->hotplug_slot->name = slot->name; 353 360 354 361 slot->hotplug_slot->private = slot; 355 362 slot->hotplug_slot->release = &release_slot; ··· 357 378 slot->hotplug_slot->info->cur_bus_speed = PCI_SPEED_UNKNOWN; 358 379 359 380 acpiphp_slot->slot = slot; 360 - make_slot_name(slot); 381 + snprintf(slot->name, sizeof(slot->name), "%u", slot->acpi_slot->sun); 361 382 362 383 retval = pci_hp_register(slot->hotplug_slot); 363 384 if (retval) { 364 385 err("pci_hp_register failed with error %d\n", retval); 365 - goto error_name; 386 + goto error_hpslot; 366 387 } 367 388 368 389 info("Slot [%s] registered\n", slot->hotplug_slot->name); 369 390 370 391 return 0; 371 - error_name: 372 - kfree(slot->hotplug_slot->name); 373 - error_info: 374 - kfree(slot->hotplug_slot->info); 375 392 error_hpslot: 376 393 kfree(slot->hotplug_slot); 377 394 error_slot: