diff options
author | Jesper Juhl <jesper.juhl@gmail.com> | 2005-12-11 00:42:18 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2006-01-09 15:13:19 -0500 |
commit | efbf62e9f4d93c3716a4d6d3221d537c71e299a2 (patch) | |
tree | f2f6a85b7faa0f81cbaee66f34c5494c6a6a0492 | |
parent | 5d135dff536f30022674d463ce3119bb28e045df (diff) |
[PATCH] PCI: Reduce nr of ptr derefs in drivers/pci/hotplug/cpqphp_core.c
Here's a small patch to reduce the nr of pointer dereferences in
drivers/pci/hotplug/cpqphp_core.c
Benefits of this patch:
- micro speed optimization due to fewer pointer derefs
- generated code is slightly smaller
- tiny line length and whitespace cleanup
- better readability
Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r-- | drivers/pci/hotplug/cpqphp_core.c | 121 |
1 files changed, 67 insertions, 54 deletions
diff --git a/drivers/pci/hotplug/cpqphp_core.c b/drivers/pci/hotplug/cpqphp_core.c index 9aed8efe6a11..d3644709a035 100644 --- a/drivers/pci/hotplug/cpqphp_core.c +++ b/drivers/pci/hotplug/cpqphp_core.c | |||
@@ -327,7 +327,9 @@ static int ctrl_slot_setup(struct controller *ctrl, | |||
327 | void __iomem *smbios_start, | 327 | void __iomem *smbios_start, |
328 | void __iomem *smbios_table) | 328 | void __iomem *smbios_table) |
329 | { | 329 | { |
330 | struct slot *new_slot; | 330 | struct slot *slot; |
331 | struct hotplug_slot *hotplug_slot; | ||
332 | struct hotplug_slot_info *hotplug_slot_info; | ||
331 | u8 number_of_slots; | 333 | u8 number_of_slots; |
332 | u8 slot_device; | 334 | u8 slot_device; |
333 | u8 slot_number; | 335 | u8 slot_number; |
@@ -345,93 +347,105 @@ static int ctrl_slot_setup(struct controller *ctrl, | |||
345 | slot_number = ctrl->first_slot; | 347 | slot_number = ctrl->first_slot; |
346 | 348 | ||
347 | while (number_of_slots) { | 349 | while (number_of_slots) { |
348 | new_slot = kmalloc(sizeof(*new_slot), GFP_KERNEL); | 350 | slot = kmalloc(sizeof(*slot), GFP_KERNEL); |
349 | if (!new_slot) | 351 | if (!slot) |
350 | goto error; | 352 | goto error; |
351 | 353 | ||
352 | memset(new_slot, 0, sizeof(struct slot)); | 354 | memset(slot, 0, sizeof(struct slot)); |
353 | new_slot->hotplug_slot = kmalloc(sizeof(*(new_slot->hotplug_slot)), | 355 | slot->hotplug_slot = kmalloc(sizeof(*(slot->hotplug_slot)), |
354 | GFP_KERNEL); | 356 | GFP_KERNEL); |
355 | if (!new_slot->hotplug_slot) | 357 | if (!slot->hotplug_slot) |
356 | goto error_slot; | 358 | goto error_slot; |
357 | memset(new_slot->hotplug_slot, 0, sizeof(struct hotplug_slot)); | 359 | hotplug_slot = slot->hotplug_slot; |
360 | memset(hotplug_slot, 0, sizeof(struct hotplug_slot)); | ||
358 | 361 | ||
359 | new_slot->hotplug_slot->info = | 362 | hotplug_slot->info = |
360 | kmalloc(sizeof(*(new_slot->hotplug_slot->info)), | 363 | kmalloc(sizeof(*(hotplug_slot->info)), |
361 | GFP_KERNEL); | 364 | GFP_KERNEL); |
362 | if (!new_slot->hotplug_slot->info) | 365 | if (!hotplug_slot->info) |
363 | goto error_hpslot; | 366 | goto error_hpslot; |
364 | memset(new_slot->hotplug_slot->info, 0, | 367 | hotplug_slot_info = hotplug_slot->info; |
368 | memset(hotplug_slot_info, 0, | ||
365 | sizeof(struct hotplug_slot_info)); | 369 | sizeof(struct hotplug_slot_info)); |
366 | new_slot->hotplug_slot->name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL); | 370 | hotplug_slot->name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL); |
367 | if (!new_slot->hotplug_slot->name) | 371 | |
372 | if (!hotplug_slot->name) | ||
368 | goto error_info; | 373 | goto error_info; |
369 | 374 | ||
370 | new_slot->ctrl = ctrl; | 375 | slot->ctrl = ctrl; |
371 | new_slot->bus = ctrl->bus; | 376 | slot->bus = ctrl->bus; |
372 | new_slot->device = slot_device; | 377 | slot->device = slot_device; |
373 | new_slot->number = slot_number; | 378 | slot->number = slot_number; |
374 | dbg("slot->number = %d\n",new_slot->number); | 379 | dbg("slot->number = %d\n", slot->number); |
375 | 380 | ||
376 | slot_entry = get_SMBIOS_entry(smbios_start, smbios_table, 9, | 381 | slot_entry = get_SMBIOS_entry(smbios_start, smbios_table, 9, |
377 | slot_entry); | 382 | slot_entry); |
378 | 383 | ||
379 | while (slot_entry && (readw(slot_entry + SMBIOS_SLOT_NUMBER) != new_slot->number)) { | 384 | while (slot_entry && (readw(slot_entry + SMBIOS_SLOT_NUMBER) != |
385 | slot->number)) { | ||
380 | slot_entry = get_SMBIOS_entry(smbios_start, | 386 | slot_entry = get_SMBIOS_entry(smbios_start, |
381 | smbios_table, 9, slot_entry); | 387 | smbios_table, 9, slot_entry); |
382 | } | 388 | } |
383 | 389 | ||
384 | new_slot->p_sm_slot = slot_entry; | 390 | slot->p_sm_slot = slot_entry; |
385 | 391 | ||
386 | init_timer(&new_slot->task_event); | 392 | init_timer(&slot->task_event); |
387 | new_slot->task_event.expires = jiffies + 5 * HZ; | 393 | slot->task_event.expires = jiffies + 5 * HZ; |
388 | new_slot->task_event.function = cpqhp_pushbutton_thread; | 394 | slot->task_event.function = cpqhp_pushbutton_thread; |
389 | 395 | ||
390 | //FIXME: these capabilities aren't used but if they are | 396 | //FIXME: these capabilities aren't used but if they are |
391 | // they need to be correctly implemented | 397 | // they need to be correctly implemented |
392 | new_slot->capabilities |= PCISLOT_REPLACE_SUPPORTED; | 398 | slot->capabilities |= PCISLOT_REPLACE_SUPPORTED; |
393 | new_slot->capabilities |= PCISLOT_INTERLOCK_SUPPORTED; | 399 | slot->capabilities |= PCISLOT_INTERLOCK_SUPPORTED; |
394 | 400 | ||
395 | if (is_slot64bit(new_slot)) | 401 | if (is_slot64bit(slot)) |
396 | new_slot->capabilities |= PCISLOT_64_BIT_SUPPORTED; | 402 | slot->capabilities |= PCISLOT_64_BIT_SUPPORTED; |
397 | if (is_slot66mhz(new_slot)) | 403 | if (is_slot66mhz(slot)) |
398 | new_slot->capabilities |= PCISLOT_66_MHZ_SUPPORTED; | 404 | slot->capabilities |= PCISLOT_66_MHZ_SUPPORTED; |
399 | if (ctrl->speed == PCI_SPEED_66MHz) | 405 | if (ctrl->speed == PCI_SPEED_66MHz) |
400 | new_slot->capabilities |= PCISLOT_66_MHZ_OPERATION; | 406 | slot->capabilities |= PCISLOT_66_MHZ_OPERATION; |
401 | 407 | ||
402 | ctrl_slot = slot_device - (readb(ctrl->hpc_reg + SLOT_MASK) >> 4); | 408 | ctrl_slot = |
409 | slot_device - (readb(ctrl->hpc_reg + SLOT_MASK) >> 4); | ||
403 | 410 | ||
404 | // Check presence | 411 | // Check presence |
405 | new_slot->capabilities |= ((((~tempdword) >> 23) | ((~tempdword) >> 15)) >> ctrl_slot) & 0x02; | 412 | slot->capabilities |= |
413 | ((((~tempdword) >> 23) | | ||
414 | ((~tempdword) >> 15)) >> ctrl_slot) & 0x02; | ||
406 | // Check the switch state | 415 | // Check the switch state |
407 | new_slot->capabilities |= ((~tempdword & 0xFF) >> ctrl_slot) & 0x01; | 416 | slot->capabilities |= |
417 | ((~tempdword & 0xFF) >> ctrl_slot) & 0x01; | ||
408 | // Check the slot enable | 418 | // Check the slot enable |
409 | new_slot->capabilities |= ((read_slot_enable(ctrl) << 2) >> ctrl_slot) & 0x04; | 419 | slot->capabilities |= |
420 | ((read_slot_enable(ctrl) << 2) >> ctrl_slot) & 0x04; | ||
410 | 421 | ||
411 | /* register this slot with the hotplug pci core */ | 422 | /* register this slot with the hotplug pci core */ |
412 | new_slot->hotplug_slot->release = &release_slot; | 423 | hotplug_slot->release = &release_slot; |
413 | new_slot->hotplug_slot->private = new_slot; | 424 | hotplug_slot->private = slot; |
414 | make_slot_name(new_slot->hotplug_slot->name, SLOT_NAME_SIZE, new_slot); | 425 | make_slot_name(hotplug_slot->name, SLOT_NAME_SIZE, slot); |
415 | new_slot->hotplug_slot->ops = &cpqphp_hotplug_slot_ops; | 426 | hotplug_slot->ops = &cpqphp_hotplug_slot_ops; |
416 | 427 | ||
417 | new_slot->hotplug_slot->info->power_status = get_slot_enabled(ctrl, new_slot); | 428 | hotplug_slot_info->power_status = get_slot_enabled(ctrl, slot); |
418 | new_slot->hotplug_slot->info->attention_status = cpq_get_attention_status(ctrl, new_slot); | 429 | hotplug_slot_info->attention_status = |
419 | new_slot->hotplug_slot->info->latch_status = cpq_get_latch_status(ctrl, new_slot); | 430 | cpq_get_attention_status(ctrl, slot); |
420 | new_slot->hotplug_slot->info->adapter_status = get_presence_status(ctrl, new_slot); | 431 | hotplug_slot_info->latch_status = |
432 | cpq_get_latch_status(ctrl, slot); | ||
433 | hotplug_slot_info->adapter_status = | ||
434 | get_presence_status(ctrl, slot); | ||
421 | 435 | ||
422 | dbg ("registering bus %d, dev %d, number %d, " | 436 | dbg("registering bus %d, dev %d, number %d, " |
423 | "ctrl->slot_device_offset %d, slot %d\n", | 437 | "ctrl->slot_device_offset %d, slot %d\n", |
424 | new_slot->bus, new_slot->device, | 438 | slot->bus, slot->device, |
425 | new_slot->number, ctrl->slot_device_offset, | 439 | slot->number, ctrl->slot_device_offset, |
426 | slot_number); | 440 | slot_number); |
427 | result = pci_hp_register (new_slot->hotplug_slot); | 441 | result = pci_hp_register(hotplug_slot); |
428 | if (result) { | 442 | if (result) { |
429 | err ("pci_hp_register failed with error %d\n", result); | 443 | err("pci_hp_register failed with error %d\n", result); |
430 | goto error_name; | 444 | goto error_name; |
431 | } | 445 | } |
432 | 446 | ||
433 | new_slot->next = ctrl->slot; | 447 | slot->next = ctrl->slot; |
434 | ctrl->slot = new_slot; | 448 | ctrl->slot = slot; |
435 | 449 | ||
436 | number_of_slots--; | 450 | number_of_slots--; |
437 | slot_device++; | 451 | slot_device++; |
@@ -439,15 +453,14 @@ static int ctrl_slot_setup(struct controller *ctrl, | |||
439 | } | 453 | } |
440 | 454 | ||
441 | return 0; | 455 | return 0; |
442 | |||
443 | error_name: | 456 | error_name: |
444 | kfree(new_slot->hotplug_slot->name); | 457 | kfree(hotplug_slot->name); |
445 | error_info: | 458 | error_info: |
446 | kfree(new_slot->hotplug_slot->info); | 459 | kfree(hotplug_slot_info); |
447 | error_hpslot: | 460 | error_hpslot: |
448 | kfree(new_slot->hotplug_slot); | 461 | kfree(hotplug_slot); |
449 | error_slot: | 462 | error_slot: |
450 | kfree(new_slot); | 463 | kfree(slot); |
451 | error: | 464 | error: |
452 | return result; | 465 | return result; |
453 | } | 466 | } |