reduce nr of ptr derefs in drivers/pci/hotplug/acpiphp_core.c
PATCH 1/1 reduce nr of ptr derefs in drivers/pci/hotplug/acpiphp_core.c
Here's a small patch to reduce the nr. of pointer dereferences in drivers/pci/hotplug/acpiphp_core.c
Benefits:
- micro speed optimization due to fewer pointer derefs
- generated code is slightly smaller
- better readability
Please consider applying.
Signed-off-by Jesper Juhl <[email protected]>
---
drivers/pci/hotplug/acpiphp_core.c | 44 ++++++++++++++++++++----------------- 1 files changed, 24 insertions(+), 20 deletions(-)
orig:
text data bss dec hex filename
2018 88 16 2122 84a drivers/pci/hotplug/acpiphp_core.o
patched:
text data bss dec hex filename
1967 88 16 2071 817 drivers/pci/hotplug/acpiphp_core.o
drivers/pci/hotplug/acpiphp_core.c +24 -20
@@ -348,6 +348,8 @@ static void release_slot(struct hotplug_static int __init init_slots (void ) {struct slot *slot; +struct hotplug_slot *hotplug_slot; +struct hotplug_slot_info *hotplug_slot_info;int retval = -ENOMEM ;int i;
@@ -360,34 +362,36 @@ static int __init init_slots(void) slot->hotplug_slot =kmalloc (sizeof (struct hotplug_slot ),GFP_KERNEL );if (!slot->hotplug_slot) goto error_slot; -memset (slot->hotplug_slot,0 ,sizeof (struct hotplug_slot )); + hotplug_slot = slot->hotplug_slot; +memset (hotplug_slot,0 ,sizeof (struct hotplug_slot )); - slot->hotplug_slot->info =kmalloc (sizeof (struct hotplug_slot_info ),GFP_KERNEL ); -if (!slot->hotplug_slot->info) + hotplug_slot->info =kmalloc (sizeof (struct hotplug_slot_info ),GFP_KERNEL ); +if (!hotplug_slot->info) goto error_hpslot; -memset (slot->hotplug_slot->info,0 ,sizeof (struct hotplug_slot_info )); + hotplug_slot_info = hotplug_slot->info; +memset (hotplug_slot_info,0 ,sizeof (struct hotplug_slot_info )); - slot->hotplug_slot->name =kmalloc (SLOT_NAME_SIZE ,GFP_KERNEL ); -if (!slot->hotplug_slot->name) + hotplug_slot->name =kmalloc (SLOT_NAME_SIZE ,GFP_KERNEL ); +if (!hotplug_slot->name) goto error_info; slot->number = i; - slot->hotplug_slot->private = slot; - slot->hotplug_slot->release = &release_slot; - slot->hotplug_slot->ops = &acpi_hotplug_slot_ops; + hotplug_slot->private = slot; + hotplug_slot->release = &release_slot; + hotplug_slot->ops = &acpi_hotplug_slot_ops; slot->acpi_slot =get_slot_from_id (i); - slot->hotplug_slot->info->power_status =acpiphp_get_power_status (slot->acpi_slot); - slot->hotplug_slot->info->attention_status =0 ; - slot->hotplug_slot->info->latch_status =acpiphp_get_latch_status (slot->acpi_slot); - slot->hotplug_slot->info->adapter_status =acpiphp_get_adapter_status (slot->acpi_slot); - slot->hotplug_slot->info->max_bus_speed =PCI_SPEED_UNKNOWN ; - slot->hotplug_slot->info->cur_bus_speed =PCI_SPEED_UNKNOWN ; + hotplug_slot_info->power_status =acpiphp_get_power_status (slot->acpi_slot); + hotplug_slot_info->attention_status =0 ; + hotplug_slot_info->latch_status =acpiphp_get_latch_status (slot->acpi_slot); + hotplug_slot_info->adapter_status =acpiphp_get_adapter_status (slot->acpi_slot); + hotplug_slot_info->max_bus_speed =PCI_SPEED_UNKNOWN ; + hotplug_slot_info->cur_bus_speed =PCI_SPEED_UNKNOWN ;make_slot_name (slot); - retval =pci_hp_register (slot->hotplug_slot); + retval =pci_hp_register (hotplug_slot);if (retval) {err ("pci_hp_register failed with error %d\n" , retval); goto error_name;
@@ -395,16 +399,16 @@ static int __init init_slots(void)/* add slot to our internal list */ list_add (&slot->slot_list, &slot_list); -info ("Slot [%s] registered\n" , slot->hotplug_slot->name); +info ("Slot [%s] registered\n" , hotplug_slot->name); }return 0 ; error_name: -kfree (slot->hotplug_slot->name); +kfree (hotplug_slot->name); error_info: -kfree (slot->hotplug_slot->info); +kfree (hotplug_slot_info); error_hpslot: -kfree (slot->hotplug_slot); +kfree (hotplug_slot); error_slot:kfree (slot); error: