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

pciehp: cleanup init_slot()

This patch cleans up init_slots() in pciehp_core.c based on
pcihp_skeleton.c. This has no functional change.
Signed-off-by: default avatarKenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
Signed-off-by: default avatarKristen Carlson Accardi <kristen.c.accardi@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 429538ad
...@@ -50,7 +50,7 @@ extern int pciehp_force; ...@@ -50,7 +50,7 @@ extern int pciehp_force;
#define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME , ## arg) #define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME , ## arg)
#define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME , ## arg) #define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME , ## arg)
#define SLOT_NAME_SIZE 10
struct slot { struct slot {
struct slot *next; struct slot *next;
u8 bus; u8 bus;
...@@ -63,6 +63,7 @@ struct slot { ...@@ -63,6 +63,7 @@ struct slot {
struct hpc_ops *hpc_ops; struct hpc_ops *hpc_ops;
struct hotplug_slot *hotplug_slot; struct hotplug_slot *hotplug_slot;
struct list_head slot_list; struct list_head slot_list;
char name[SLOT_NAME_SIZE];
}; };
struct event_info { struct event_info {
...@@ -233,13 +234,6 @@ static inline int wait_for_ctrl_irq(struct controller *ctrl) ...@@ -233,13 +234,6 @@ static inline int wait_for_ctrl_irq(struct controller *ctrl)
return retval; return retval;
} }
#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,
......
...@@ -98,101 +98,81 @@ static void release_slot(struct hotplug_slot *hotplug_slot) ...@@ -98,101 +98,81 @@ static void release_slot(struct hotplug_slot *hotplug_slot)
dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
kfree(slot->hotplug_slot->info); kfree(slot->hotplug_slot->info);
kfree(slot->hotplug_slot->name);
kfree(slot->hotplug_slot); kfree(slot->hotplug_slot);
kfree(slot); kfree(slot);
} }
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 *slot; struct slot *slot;
struct hpc_ops *hpc_ops;
struct hotplug_slot *hotplug_slot; struct hotplug_slot *hotplug_slot;
struct hotplug_slot_info *hotplug_slot_info; struct hotplug_slot_info *info;
u8 number_of_slots; int retval = -ENOMEM;
u8 slot_device; int i;
u32 slot_number;
int result = -ENOMEM;
number_of_slots = ctrl->num_slots; for (i = 0; i < ctrl->num_slots; i++) {
slot_device = ctrl->slot_device_offset;
slot_number = ctrl->first_slot;
while (number_of_slots) {
slot = kzalloc(sizeof(*slot), GFP_KERNEL); slot = kzalloc(sizeof(*slot), GFP_KERNEL);
if (!slot) if (!slot)
goto error; goto error;
slot->hotplug_slot = hotplug_slot = kzalloc(sizeof(*hotplug_slot), GFP_KERNEL);
kzalloc(sizeof(*(slot->hotplug_slot)), if (!hotplug_slot)
GFP_KERNEL);
if (!slot->hotplug_slot)
goto error_slot; goto error_slot;
hotplug_slot = slot->hotplug_slot; slot->hotplug_slot = hotplug_slot;
hotplug_slot->info = info = kzalloc(sizeof(*info), GFP_KERNEL);
kzalloc(sizeof(*(hotplug_slot->info)), if (!info)
GFP_KERNEL);
if (!hotplug_slot->info)
goto error_hpslot; goto error_hpslot;
hotplug_slot_info = hotplug_slot->info; hotplug_slot->info = info;
hotplug_slot->name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL);
if (!hotplug_slot->name)
goto error_info;
slot->ctrl = ctrl; hotplug_slot->name = slot->name;
slot->bus = ctrl->slot_bus;
slot->device = slot_device;
slot->hpc_ops = hpc_ops = ctrl->hpc_ops;
slot->hp_slot = i;
slot->ctrl = ctrl;
slot->bus = ctrl->pci_dev->subordinate->number;
slot->device = ctrl->slot_device_offset + i;
slot->hpc_ops = ctrl->hpc_ops;
slot->number = ctrl->first_slot; slot->number = ctrl->first_slot;
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 */
hotplug_slot->private = slot; hotplug_slot->private = slot;
hotplug_slot->release = &release_slot; hotplug_slot->release = &release_slot;
make_slot_name(hotplug_slot->name, SLOT_NAME_SIZE, slot); make_slot_name(slot);
hotplug_slot->ops = &pciehp_hotplug_slot_ops; hotplug_slot->ops = &pciehp_hotplug_slot_ops;
hpc_ops->get_power_status(slot, get_power_status(hotplug_slot, &info->power_status);
&(hotplug_slot_info->power_status)); get_attention_status(hotplug_slot, &info->attention_status);
hpc_ops->get_attention_status(slot, get_latch_status(hotplug_slot, &info->latch_status);
&(hotplug_slot_info->attention_status)); get_adapter_status(hotplug_slot, &info->adapter_status);
hpc_ops->get_latch_status(slot,
&(hotplug_slot_info->latch_status));
hpc_ops->get_adapter_status(slot,
&(hotplug_slot_info->adapter_status));
dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x " dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x "
"slot_device_offset=%x\n", "slot_device_offset=%x\n", slot->bus, slot->device,
slot->bus, slot->device, slot->hp_slot, slot->number, slot->hp_slot, slot->number, ctrl->slot_device_offset);
ctrl->slot_device_offset); retval = pci_hp_register(hotplug_slot);
result = pci_hp_register(hotplug_slot); if (retval) {
if (result) { err ("pci_hp_register failed with error %d\n", retval);
err ("pci_hp_register failed with error %d\n", result); goto error_info;
goto error_name;
} }
slot->next = ctrl->slot; slot->next = ctrl->slot;
ctrl->slot = slot; ctrl->slot = slot;
number_of_slots--;
slot_device++;
slot_number += ctrl->slot_num_inc;
} }
return 0; return 0;
error_name:
kfree(hotplug_slot->name);
error_info: error_info:
kfree(hotplug_slot_info); kfree(info);
error_hpslot: error_hpslot:
kfree(hotplug_slot); kfree(hotplug_slot);
error_slot: error_slot:
kfree(slot); kfree(slot);
error: error:
return result; return retval;
} }
......
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