Commit 926030f6 authored by Kenji Kaneshige's avatar Kenji Kaneshige Committed by Greg Kroah-Hartman

[PATCH] shpchp - cleanup init_slots()

This patch cleanups init_slots() function of SHPCHP driver based on
pcihp_skelton.c. This patch has no functional change.
Signed-off-by: default avatarKenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 6aa4cdd0
...@@ -428,13 +428,6 @@ static inline void amd_pogo_errata_restore_misc_reg(struct slot *p_slot) ...@@ -428,13 +428,6 @@ static inline void amd_pogo_errata_restore_misc_reg(struct slot *p_slot)
pci_write_config_dword(p_slot->ctrl->pci_dev, PCIX_MISCII_OFFSET, pcix_misc2_temp); pci_write_config_dword(p_slot->ctrl->pci_dev, PCIX_MISCII_OFFSET, pcix_misc2_temp);
} }
#define SLOT_NAME_SIZE 10
static inline void make_slot_name(char *buffer, int buffer_size, struct slot *slot)
{
snprintf(buffer, buffer_size, "%04d_%04d", slot->bus, slot->number);
}
enum php_ctlr_type { enum php_ctlr_type {
PCI, PCI,
ISA, ISA,
......
...@@ -99,89 +99,95 @@ static void release_slot(struct hotplug_slot *hotplug_slot) ...@@ -99,89 +99,95 @@ static void release_slot(struct hotplug_slot *hotplug_slot)
kfree(slot); kfree(slot);
} }
#define SLOT_NAME_SIZE 10
static void make_slot_name(struct slot *slot)
{
snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%04d_%04d",
slot->bus, slot->number);
}
static int init_slots(struct controller *ctrl) static int init_slots(struct controller *ctrl)
{ {
struct slot *new_slot; struct slot *slot;
u8 number_of_slots; struct hotplug_slot *hotplug_slot;
u8 slot_device; struct hotplug_slot_info *info;
u32 slot_number, sun; char *name;
int result = -ENOMEM; int retval = -ENOMEM;
int i;
number_of_slots = ctrl->num_slots; u32 sun;
slot_device = ctrl->slot_device_offset;
slot_number = ctrl->first_slot; for (i = 0; i < ctrl->num_slots; i++) {
slot = kmalloc(sizeof(struct slot), GFP_KERNEL);
while (number_of_slots) { if (!slot)
new_slot = (struct slot *) kmalloc(sizeof(struct slot), GFP_KERNEL);
if (!new_slot)
goto error; goto error;
memset(slot, 0, sizeof(struct slot));
memset(new_slot, 0, sizeof(struct slot)); hotplug_slot = kmalloc(sizeof(struct hotplug_slot),
new_slot->hotplug_slot = kmalloc (sizeof (struct hotplug_slot), GFP_KERNEL); GFP_KERNEL);
if (!new_slot->hotplug_slot) if (!hotplug_slot)
goto error_slot; goto error_slot;
memset(new_slot->hotplug_slot, 0, sizeof (struct hotplug_slot)); memset(hotplug_slot, 0, sizeof(struct hotplug_slot));
slot->hotplug_slot = hotplug_slot;
new_slot->hotplug_slot->info = kmalloc (sizeof (struct hotplug_slot_info), GFP_KERNEL); info = kmalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL);
if (!new_slot->hotplug_slot->info) if (!info)
goto error_hpslot; goto error_hpslot;
memset(new_slot->hotplug_slot->info, 0, sizeof (struct hotplug_slot_info)); memset(info, 0, sizeof (struct hotplug_slot_info));
new_slot->hotplug_slot->name = kmalloc (SLOT_NAME_SIZE, GFP_KERNEL); hotplug_slot->info = info;
if (!new_slot->hotplug_slot->name)
name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL);
if (!name)
goto error_info; goto error_info;
hotplug_slot->name = name;
new_slot->magic = SLOT_MAGIC; slot->hp_slot = i;
new_slot->ctrl = ctrl; slot->magic = SLOT_MAGIC;
new_slot->bus = ctrl->slot_bus; slot->ctrl = ctrl;
new_slot->device = slot_device; slot->bus = ctrl->slot_bus;
new_slot->hpc_ops = ctrl->hpc_ops; slot->device = ctrl->slot_device_offset + i;
slot->hpc_ops = ctrl->hpc_ops;
if (shpchprm_get_physical_slot_number(ctrl, &sun, if (shpchprm_get_physical_slot_number(ctrl, &sun,
new_slot->bus, new_slot->device)) slot->bus, slot->device))
goto error_name; goto error_name;
new_slot->number = sun; slot->number = sun;
new_slot->hp_slot = slot_device - ctrl->slot_device_offset;
/* register this slot with the hotplug pci core */ /* register this slot with the hotplug pci core */
new_slot->hotplug_slot->private = new_slot; hotplug_slot->private = slot;
new_slot->hotplug_slot->release = &release_slot; hotplug_slot->release = &release_slot;
make_slot_name(new_slot->hotplug_slot->name, SLOT_NAME_SIZE, new_slot); make_slot_name(slot);
new_slot->hotplug_slot->ops = &shpchp_hotplug_slot_ops; hotplug_slot->ops = &shpchp_hotplug_slot_ops;
new_slot->hpc_ops->get_power_status(new_slot, &(new_slot->hotplug_slot->info->power_status)); get_power_status(hotplug_slot, &info->power_status);
new_slot->hpc_ops->get_attention_status(new_slot, &(new_slot->hotplug_slot->info->attention_status)); get_attention_status(hotplug_slot, &info->attention_status);
new_slot->hpc_ops->get_latch_status(new_slot, &(new_slot->hotplug_slot->info->latch_status)); get_latch_status(hotplug_slot, &info->latch_status);
new_slot->hpc_ops->get_adapter_status(new_slot, &(new_slot->hotplug_slot->info->adapter_status)); get_adapter_status(hotplug_slot, &info->adapter_status);
dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x slot_device_offset=%x\n", new_slot->bus, dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x "
new_slot->device, new_slot->hp_slot, new_slot->number, ctrl->slot_device_offset); "slot_device_offset=%x\n", slot->bus, slot->device,
result = pci_hp_register (new_slot->hotplug_slot); slot->hp_slot, slot->number, ctrl->slot_device_offset);
if (result) { retval = pci_hp_register(slot->hotplug_slot);
err ("pci_hp_register failed with error %d\n", result); if (retval) {
err("pci_hp_register failed with error %d\n", retval);
goto error_name; goto error_name;
} }
new_slot->next = ctrl->slot; slot->next = ctrl->slot;
ctrl->slot = new_slot; ctrl->slot = slot;
number_of_slots--;
slot_device++;
slot_number += ctrl->slot_num_inc;
} }
return 0; return 0;
error_name: error_name:
kfree(new_slot->hotplug_slot->name); kfree(name);
error_info: error_info:
kfree(new_slot->hotplug_slot->info); kfree(info);
error_hpslot: error_hpslot:
kfree(new_slot->hotplug_slot); kfree(hotplug_slot);
error_slot: error_slot:
kfree(new_slot); kfree(slot);
error: error:
return result; return retval;
} }
static void cleanup_slots(struct controller *ctrl) static void cleanup_slots(struct controller *ctrl)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment