Skip to content

Commit

Permalink
PCI: Change memory allocation for acpiphp slots
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Rolf Eike Beer authored and Greg Kroah-Hartman committed Dec 1, 2006
1 parent adbc2a1 commit ac9e989
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 32 deletions.
4 changes: 2 additions & 2 deletions drivers/pci/hotplug/acpiphp.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ struct acpiphp_slot;
struct slot {
struct hotplug_slot *hotplug_slot;
struct acpiphp_slot *acpi_slot;
struct hotplug_slot_info info;
char name[SLOT_NAME_SIZE];
};



/**
* struct acpiphp_bridge - PCI bridge information
*
Expand Down
35 changes: 5 additions & 30 deletions drivers/pci/hotplug/acpiphp_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,18 +312,6 @@ static int __init init_acpi(void)
return retval;
}


/**
* make_slot_name - make a slot name that appears in pcihpfs
* @slot: slot to name
*
*/
static void make_slot_name(struct slot *slot)
{
snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%u",
slot->acpi_slot->sun);
}

/**
* release_slot - free up the memory used by a slot
* @hotplug_slot: slot to free
Expand All @@ -334,8 +322,6 @@ static void release_slot(struct hotplug_slot *hotplug_slot)

dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);

kfree(slot->hotplug_slot->info);
kfree(slot->hotplug_slot->name);
kfree(slot->hotplug_slot);
kfree(slot);
}
Expand All @@ -344,26 +330,19 @@ static void release_slot(struct hotplug_slot *hotplug_slot)
int acpiphp_register_hotplug_slot(struct acpiphp_slot *acpiphp_slot)
{
struct slot *slot;
struct hotplug_slot *hotplug_slot;
struct hotplug_slot_info *hotplug_slot_info;
int retval = -ENOMEM;

slot = kzalloc(sizeof(*slot), GFP_KERNEL);
if (!slot)
goto error;

slot->hotplug_slot = kzalloc(sizeof(*hotplug_slot), GFP_KERNEL);
slot->hotplug_slot = kzalloc(sizeof(*slot->hotplug_slot), GFP_KERNEL);
if (!slot->hotplug_slot)
goto error_slot;

slot->hotplug_slot->info = kzalloc(sizeof(*hotplug_slot_info),
GFP_KERNEL);
if (!slot->hotplug_slot->info)
goto error_hpslot;
slot->hotplug_slot->info = &slot->info;

slot->hotplug_slot->name = kzalloc(SLOT_NAME_SIZE, GFP_KERNEL);
if (!slot->hotplug_slot->name)
goto error_info;
slot->hotplug_slot->name = slot->name;

slot->hotplug_slot->private = slot;
slot->hotplug_slot->release = &release_slot;
Expand All @@ -378,21 +357,17 @@ int acpiphp_register_hotplug_slot(struct acpiphp_slot *acpiphp_slot)
slot->hotplug_slot->info->cur_bus_speed = PCI_SPEED_UNKNOWN;

acpiphp_slot->slot = slot;
make_slot_name(slot);
snprintf(slot->name, sizeof(slot->name), "%u", slot->acpi_slot->sun);

retval = pci_hp_register(slot->hotplug_slot);
if (retval) {
err("pci_hp_register failed with error %d\n", retval);
goto error_name;
goto error_hpslot;
}

info("Slot [%s] registered\n", slot->hotplug_slot->name);

return 0;
error_name:
kfree(slot->hotplug_slot->name);
error_info:
kfree(slot->hotplug_slot->info);
error_hpslot:
kfree(slot->hotplug_slot);
error_slot:
Expand Down

0 comments on commit ac9e989

Please sign in to comment.