[PATCH] reduce nr of ptr derefs in drivers/pci/hotplug/acpiphp_core.c

From: Jesper Juhl
Date: Sun Dec 11 2005 - 00:40:08 EST


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 <jesper.juhl@xxxxxxxxx>
---

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

--- linux-2.6.15-rc5-git1-orig/drivers/pci/hotplug/acpiphp_core.c 2005-10-28 02:02:08.000000000 +0200
+++ linux-2.6.15-rc5-git1/drivers/pci/hotplug/acpiphp_core.c 2005-12-11 03:35:53.000000000 +0100
@@ -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:



-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/