diff options
author | Jesper Juhl <jesper.juhl@gmail.com> | 2005-12-11 00:41:42 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2006-01-09 15:13:20 -0500 |
commit | 121082e2ab09d5e90ac27e38900c018e6f37bcdf (patch) | |
tree | 341e632ce2fc4e54d34e29e637b531bf419d5576 /drivers/pci/hotplug | |
parent | c2dea6553090a3fd06ffa9ba512a09fdac4d1b6e (diff) |
[PATCH] PCI: Reduce nr of ptr derefs in drivers/pci/hotplug/pciehp_core.c
Here's a small patch to reduce the nr. of pointer dereferences in
drivers/pci/hotplug/pciehp_core.c
Benefits:
- micro speed optimization due to fewer pointer derefs
- generated code is slightly smaller
- small line length cleanup
- better readability
Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/pci/hotplug')
-rw-r--r-- | drivers/pci/hotplug/pciehp_core.c | 90 |
1 files changed, 50 insertions, 40 deletions
diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c index 8df704860348..986e202e0b0b 100644 --- a/drivers/pci/hotplug/pciehp_core.c +++ b/drivers/pci/hotplug/pciehp_core.c | |||
@@ -103,7 +103,10 @@ static void release_slot(struct hotplug_slot *hotplug_slot) | |||
103 | 103 | ||
104 | static int init_slots(struct controller *ctrl) | 104 | static int init_slots(struct controller *ctrl) |
105 | { | 105 | { |
106 | struct slot *new_slot; | 106 | struct slot *slot; |
107 | struct hpc_ops *hpc_ops; | ||
108 | struct hotplug_slot *hotplug_slot; | ||
109 | struct hotplug_slot_info *hotplug_slot_info; | ||
107 | u8 number_of_slots; | 110 | u8 number_of_slots; |
108 | u8 slot_device; | 111 | u8 slot_device; |
109 | u32 slot_number; | 112 | u32 slot_number; |
@@ -114,59 +117,66 @@ static int init_slots(struct controller *ctrl) | |||
114 | slot_number = ctrl->first_slot; | 117 | slot_number = ctrl->first_slot; |
115 | 118 | ||
116 | while (number_of_slots) { | 119 | while (number_of_slots) { |
117 | new_slot = kmalloc(sizeof(*new_slot), GFP_KERNEL); | 120 | slot = kmalloc(sizeof(*slot), GFP_KERNEL); |
118 | if (!new_slot) | 121 | if (!slot) |
119 | goto error; | 122 | goto error; |
120 | 123 | ||
121 | memset(new_slot, 0, sizeof(struct slot)); | 124 | memset(slot, 0, sizeof(struct slot)); |
122 | new_slot->hotplug_slot = | 125 | slot->hotplug_slot = |
123 | kmalloc(sizeof(*(new_slot->hotplug_slot)), | 126 | kmalloc(sizeof(*(slot->hotplug_slot)), |
124 | GFP_KERNEL); | 127 | GFP_KERNEL); |
125 | if (!new_slot->hotplug_slot) | 128 | if (!slot->hotplug_slot) |
126 | goto error_slot; | 129 | goto error_slot; |
127 | memset(new_slot->hotplug_slot, 0, sizeof(struct hotplug_slot)); | 130 | hotplug_slot = slot->hotplug_slot; |
131 | memset(hotplug_slot, 0, sizeof(struct hotplug_slot)); | ||
128 | 132 | ||
129 | new_slot->hotplug_slot->info = | 133 | hotplug_slot->info = |
130 | kmalloc(sizeof(*(new_slot->hotplug_slot->info)), | 134 | kmalloc(sizeof(*(hotplug_slot->info)), |
131 | GFP_KERNEL); | 135 | GFP_KERNEL); |
132 | if (!new_slot->hotplug_slot->info) | 136 | if (!hotplug_slot->info) |
133 | goto error_hpslot; | 137 | goto error_hpslot; |
134 | memset(new_slot->hotplug_slot->info, 0, | 138 | hotplug_slot_info = hotplug_slot->info; |
139 | memset(hotplug_slot_info, 0, | ||
135 | sizeof(struct hotplug_slot_info)); | 140 | sizeof(struct hotplug_slot_info)); |
136 | new_slot->hotplug_slot->name = kmalloc(SLOT_NAME_SIZE, | 141 | hotplug_slot->name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL); |
137 | GFP_KERNEL); | 142 | if (!hotplug_slot->name) |
138 | if (!new_slot->hotplug_slot->name) | ||
139 | goto error_info; | 143 | goto error_info; |
140 | 144 | ||
141 | new_slot->ctrl = ctrl; | 145 | slot->ctrl = ctrl; |
142 | new_slot->bus = ctrl->slot_bus; | 146 | slot->bus = ctrl->slot_bus; |
143 | new_slot->device = slot_device; | 147 | slot->device = slot_device; |
144 | new_slot->hpc_ops = ctrl->hpc_ops; | 148 | slot->hpc_ops = hpc_ops = ctrl->hpc_ops; |
145 | 149 | ||
146 | new_slot->number = ctrl->first_slot; | 150 | slot->number = ctrl->first_slot; |
147 | new_slot->hp_slot = slot_device - ctrl->slot_device_offset; | 151 | slot->hp_slot = slot_device - ctrl->slot_device_offset; |
148 | 152 | ||
149 | /* register this slot with the hotplug pci core */ | 153 | /* register this slot with the hotplug pci core */ |
150 | new_slot->hotplug_slot->private = new_slot; | 154 | hotplug_slot->private = slot; |
151 | new_slot->hotplug_slot->release = &release_slot; | 155 | hotplug_slot->release = &release_slot; |
152 | make_slot_name(new_slot->hotplug_slot->name, SLOT_NAME_SIZE, new_slot); | 156 | make_slot_name(hotplug_slot->name, SLOT_NAME_SIZE, slot); |
153 | new_slot->hotplug_slot->ops = &pciehp_hotplug_slot_ops; | 157 | hotplug_slot->ops = &pciehp_hotplug_slot_ops; |
154 | 158 | ||
155 | new_slot->hpc_ops->get_power_status(new_slot, &(new_slot->hotplug_slot->info->power_status)); | 159 | hpc_ops->get_power_status(slot, |
156 | new_slot->hpc_ops->get_attention_status(new_slot, &(new_slot->hotplug_slot->info->attention_status)); | 160 | &(hotplug_slot_info->power_status)); |
157 | new_slot->hpc_ops->get_latch_status(new_slot, &(new_slot->hotplug_slot->info->latch_status)); | 161 | hpc_ops->get_attention_status(slot, |
158 | new_slot->hpc_ops->get_adapter_status(new_slot, &(new_slot->hotplug_slot->info->adapter_status)); | 162 | &(hotplug_slot_info->attention_status)); |
159 | 163 | hpc_ops->get_latch_status(slot, | |
160 | dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x slot_device_offset=%x\n", | 164 | &(hotplug_slot_info->latch_status)); |
161 | new_slot->bus, new_slot->device, new_slot->hp_slot, new_slot->number, ctrl->slot_device_offset); | 165 | hpc_ops->get_adapter_status(slot, |
162 | result = pci_hp_register (new_slot->hotplug_slot); | 166 | &(hotplug_slot_info->adapter_status)); |
167 | |||
168 | dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x " | ||
169 | "slot_device_offset=%x\n", | ||
170 | slot->bus, slot->device, slot->hp_slot, slot->number, | ||
171 | ctrl->slot_device_offset); | ||
172 | result = pci_hp_register(hotplug_slot); | ||
163 | if (result) { | 173 | if (result) { |
164 | err ("pci_hp_register failed with error %d\n", result); | 174 | err ("pci_hp_register failed with error %d\n", result); |
165 | goto error_name; | 175 | goto error_name; |
166 | } | 176 | } |
167 | 177 | ||
168 | new_slot->next = ctrl->slot; | 178 | slot->next = ctrl->slot; |
169 | ctrl->slot = new_slot; | 179 | ctrl->slot = slot; |
170 | 180 | ||
171 | number_of_slots--; | 181 | number_of_slots--; |
172 | slot_device++; | 182 | slot_device++; |
@@ -176,13 +186,13 @@ static int init_slots(struct controller *ctrl) | |||
176 | return 0; | 186 | return 0; |
177 | 187 | ||
178 | error_name: | 188 | error_name: |
179 | kfree(new_slot->hotplug_slot->name); | 189 | kfree(hotplug_slot->name); |
180 | error_info: | 190 | error_info: |
181 | kfree(new_slot->hotplug_slot->info); | 191 | kfree(hotplug_slot_info); |
182 | error_hpslot: | 192 | error_hpslot: |
183 | kfree(new_slot->hotplug_slot); | 193 | kfree(hotplug_slot); |
184 | error_slot: | 194 | error_slot: |
185 | kfree(new_slot); | 195 | kfree(slot); |
186 | error: | 196 | error: |
187 | return result; | 197 | return result; |
188 | } | 198 | } |