X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=drivers%2Fpci%2Fhotplug%2Fpciehp_core.c;h=b31ccbcea9990e8e65b2e9c3b92ad981186e9263;hb=9213980e6a70d8473e0ffd4b39ab5b6caaba9ff5;hp=1f9b7e1556b85b0dff56cf3b4b7ee1f0c1c3380b;hpb=c449269f45c2cdf53af08c8d0af37472f66539d9;p=linux-2.6.git diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c index 1f9b7e155..b31ccbcea 100644 --- a/drivers/pci/hotplug/pciehp_core.c +++ b/drivers/pci/hotplug/pciehp_core.c @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -45,7 +46,7 @@ int pciehp_debug; int pciehp_poll_mode; int pciehp_poll_time; -struct controller *pciehp_ctrl_list; /* = NULL */ +struct controller *pciehp_ctrl_list; struct pci_func *pciehp_slot_list[256]; #define DRIVER_VERSION "0.4" @@ -56,9 +57,9 @@ MODULE_AUTHOR(DRIVER_AUTHOR); MODULE_DESCRIPTION(DRIVER_DESC); MODULE_LICENSE("GPL"); -MODULE_PARM(pciehp_debug, "i"); -MODULE_PARM(pciehp_poll_mode, "i"); -MODULE_PARM(pciehp_poll_time, "i"); +module_param(pciehp_debug, bool, 644); +module_param(pciehp_poll_mode, bool, 644); +module_param(pciehp_poll_time, int, 644); MODULE_PARM_DESC(pciehp_debug, "Debugging mode enabled or not"); MODULE_PARM_DESC(pciehp_poll_mode, "Using polling mechanism for hot-plug events or not"); MODULE_PARM_DESC(pciehp_poll_time, "Polling mechanism frequency, in seconds"); @@ -69,7 +70,6 @@ static int pcie_start_thread (void); static int set_attention_status (struct hotplug_slot *slot, u8 value); static int enable_slot (struct hotplug_slot *slot); static int disable_slot (struct hotplug_slot *slot); -static int hardware_test (struct hotplug_slot *slot, u32 value); static int get_power_status (struct hotplug_slot *slot, u8 *value); static int get_attention_status (struct hotplug_slot *slot, u8 *value); static int get_latch_status (struct hotplug_slot *slot, u8 *value); @@ -82,7 +82,6 @@ static struct hotplug_slot_ops pciehp_hotplug_slot_ops = { .set_attention_status = set_attention_status, .enable_slot = enable_slot, .disable_slot = disable_slot, - .hardware_test = hardware_test, .get_power_status = get_power_status, .get_attention_status = get_attention_status, .get_latch_status = get_latch_status, @@ -97,7 +96,7 @@ static int init_slots(struct controller *ctrl) u8 number_of_slots; u8 slot_device; u32 slot_number; - int result; + int result = -ENOMEM; dbg("%s\n",__FUNCTION__); @@ -106,34 +105,30 @@ static int init_slots(struct controller *ctrl) slot_number = ctrl->first_slot; while (number_of_slots) { - new_slot = (struct slot *) kmalloc(sizeof(struct slot), GFP_KERNEL); + new_slot = kmalloc(sizeof(*new_slot), GFP_KERNEL); if (!new_slot) - return -ENOMEM; + goto error; memset(new_slot, 0, sizeof(struct slot)); - new_slot->hotplug_slot = kmalloc (sizeof (struct hotplug_slot), GFP_KERNEL); - if (!new_slot->hotplug_slot) { - kfree (new_slot); - return -ENOMEM; - } - memset(new_slot->hotplug_slot, 0, sizeof (struct hotplug_slot)); - - new_slot->hotplug_slot->info = kmalloc (sizeof (struct hotplug_slot_info), GFP_KERNEL); - if (!new_slot->hotplug_slot->info) { - kfree (new_slot->hotplug_slot); - kfree (new_slot); - return -ENOMEM; - } - memset(new_slot->hotplug_slot->info, 0, sizeof (struct hotplug_slot_info)); - new_slot->hotplug_slot->name = kmalloc (SLOT_NAME_SIZE, GFP_KERNEL); - if (!new_slot->hotplug_slot->name) { - kfree (new_slot->hotplug_slot->info); - kfree (new_slot->hotplug_slot); - kfree (new_slot); - return -ENOMEM; - } + new_slot->hotplug_slot = + kmalloc(sizeof(*(new_slot->hotplug_slot)), + GFP_KERNEL); + if (!new_slot->hotplug_slot) + goto error_slot; + memset(new_slot->hotplug_slot, 0, sizeof(struct hotplug_slot)); + + new_slot->hotplug_slot->info = + kmalloc(sizeof(*(new_slot->hotplug_slot->info)), + GFP_KERNEL); + if (!new_slot->hotplug_slot->info) + goto error_hpslot; + memset(new_slot->hotplug_slot->info, 0, + sizeof(struct hotplug_slot_info)); + new_slot->hotplug_slot->name = kmalloc(SLOT_NAME_SIZE, + GFP_KERNEL); + if (!new_slot->hotplug_slot->name) + goto error_info; - new_slot->magic = SLOT_MAGIC; new_slot->ctrl = ctrl; new_slot->bus = ctrl->slot_bus; new_slot->device = slot_device; @@ -157,11 +152,7 @@ static int init_slots(struct controller *ctrl) result = pci_hp_register (new_slot->hotplug_slot); if (result) { err ("pci_hp_register failed with error %d\n", result); - kfree (new_slot->hotplug_slot->info); - kfree (new_slot->hotplug_slot->name); - kfree (new_slot->hotplug_slot); - kfree (new_slot); - return result; + goto error_name; } new_slot->next = ctrl->slot; @@ -172,7 +163,18 @@ static int init_slots(struct controller *ctrl) slot_number += ctrl->slot_num_inc; } - return(0); + return 0; + +error_name: + kfree(new_slot->hotplug_slot->name); +error_info: + kfree(new_slot->hotplug_slot->info); +error_hpslot: + kfree(new_slot->hotplug_slot); +error_slot: + kfree(new_slot); +error: + return result; } @@ -228,13 +230,10 @@ static int get_ctlr_slot_config(struct controller *ctrl) /* * set_attention_status - Turns the Amber LED for a slot on, off or blink */ -static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status) +static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 status) { - struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); + struct slot *slot = hotplug_slot->private; - if (slot == NULL) - return -ENODEV; - dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); hotplug_slot->info->attention_status = status; @@ -244,12 +243,9 @@ static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status) } -static int enable_slot (struct hotplug_slot *hotplug_slot) +static int enable_slot(struct hotplug_slot *hotplug_slot) { - struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); - - if (slot == NULL) - return -ENODEV; + struct slot *slot = hotplug_slot->private; dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); @@ -257,33 +253,20 @@ static int enable_slot (struct hotplug_slot *hotplug_slot) } -static int disable_slot (struct hotplug_slot *hotplug_slot) +static int disable_slot(struct hotplug_slot *hotplug_slot) { - struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); - - if (slot == NULL) - return -ENODEV; + struct slot *slot = hotplug_slot->private; dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); return pciehp_disable_slot(slot); } - -static int hardware_test (struct hotplug_slot *hotplug_slot, u32 value) +static int get_power_status(struct hotplug_slot *hotplug_slot, u8 *value) { - return 0; -} - - -static int get_power_status (struct hotplug_slot *hotplug_slot, u8 *value) -{ - struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); + struct slot *slot = hotplug_slot->private; int retval; - - if (slot == NULL) - return -ENODEV; - + dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); retval = slot->hpc_ops->get_power_status(slot, value); @@ -293,14 +276,11 @@ static int get_power_status (struct hotplug_slot *hotplug_slot, u8 *value) return 0; } -static int get_attention_status (struct hotplug_slot *hotplug_slot, u8 *value) +static int get_attention_status(struct hotplug_slot *hotplug_slot, u8 *value) { - struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); + struct slot *slot = hotplug_slot->private; int retval; - - if (slot == NULL) - return -ENODEV; - + dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); retval = slot->hpc_ops->get_attention_status(slot, value); @@ -310,14 +290,11 @@ static int get_attention_status (struct hotplug_slot *hotplug_slot, u8 *value) return 0; } -static int get_latch_status (struct hotplug_slot *hotplug_slot, u8 *value) +static int get_latch_status(struct hotplug_slot *hotplug_slot, u8 *value) { - struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); + struct slot *slot = hotplug_slot->private; int retval; - - if (slot == NULL) - return -ENODEV; - + dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); retval = slot->hpc_ops->get_latch_status(slot, value); @@ -327,31 +304,24 @@ static int get_latch_status (struct hotplug_slot *hotplug_slot, u8 *value) return 0; } -static int get_adapter_status (struct hotplug_slot *hotplug_slot, u8 *value) +static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value) { - struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); + struct slot *slot = hotplug_slot->private; int retval; - - if (slot == NULL) - return -ENODEV; dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); retval = slot->hpc_ops->get_adapter_status(slot, value); - if (retval < 0) *value = hotplug_slot->info->adapter_status; return 0; } -static int get_max_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value) +static int get_max_bus_speed(struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value) { - struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); + struct slot *slot = hotplug_slot->private; int retval; - - if (slot == NULL) - return -ENODEV; dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); @@ -362,13 +332,10 @@ static int get_max_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_sp return 0; } -static int get_cur_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value) +static int get_cur_bus_speed(struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value) { - struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); + struct slot *slot = hotplug_slot->private; int retval; - - if (slot == NULL) - return -ENODEV; dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); @@ -388,7 +355,7 @@ static int pcie_probe(struct pci_dev *pdev, const struct pci_device_id *ent) int num_ctlr_slots; /* number of slots supported by this HPC */ u8 value; - ctrl = (struct controller *) kmalloc(sizeof(struct controller), GFP_KERNEL); + ctrl = kmalloc(sizeof(*ctrl), GFP_KERNEL); if (!ctrl) { err("%s : out of memory\n", __FUNCTION__); goto err_out_none; @@ -411,7 +378,7 @@ static int pcie_probe(struct pci_dev *pdev, const struct pci_device_id *ent) pci_set_drvdata(pdev, ctrl); - ctrl->pci_bus = kmalloc (sizeof (*ctrl->pci_bus), GFP_KERNEL); + ctrl->pci_bus = kmalloc(sizeof(*ctrl->pci_bus), GFP_KERNEL); if (!ctrl->pci_bus) { err("%s: out of memory\n", __FUNCTION__); rc = -ENOMEM; @@ -535,49 +502,35 @@ static int pcie_start_thread(void) return retval; } +static inline void __exit +free_pciehp_res(struct pci_resource *res) +{ + struct pci_resource *tres; + + while (res) { + tres = res; + res = res->next; + kfree(tres); + } +} -static void unload_pciehpd(void) +static void __exit unload_pciehpd(void) { struct pci_func *next; struct pci_func *TempSlot; int loop; struct controller *ctrl; struct controller *tctrl; - struct pci_resource *res; - struct pci_resource *tres; ctrl = pciehp_ctrl_list; while (ctrl) { cleanup_slots(ctrl); - res = ctrl->io_head; - while (res) { - tres = res; - res = res->next; - kfree(tres); - } - - res = ctrl->mem_head; - while (res) { - tres = res; - res = res->next; - kfree(tres); - } - - res = ctrl->p_mem_head; - while (res) { - tres = res; - res = res->next; - kfree(tres); - } - - res = ctrl->bus_head; - while (res) { - tres = res; - res = res->next; - kfree(tres); - } + free_pciehp_res(ctrl->io_head); + free_pciehp_res(ctrl->mem_head); + free_pciehp_res(ctrl->p_mem_head); + free_pciehp_res(ctrl->bus_head); kfree (ctrl->pci_bus); @@ -592,33 +545,10 @@ static void unload_pciehpd(void) for (loop = 0; loop < 256; loop++) { next = pciehp_slot_list[loop]; while (next != NULL) { - res = next->io_head; - while (res) { - tres = res; - res = res->next; - kfree(tres); - } - - res = next->mem_head; - while (res) { - tres = res; - res = res->next; - kfree(tres); - } - - res = next->p_mem_head; - while (res) { - tres = res; - res = res->next; - kfree(tres); - } - - res = next->bus_head; - while (res) { - tres = res; - res = res->next; - kfree(tres); - } + free_pciehp_res(next->io_head); + free_pciehp_res(next->mem_head); + free_pciehp_res(next->p_mem_head); + free_pciehp_res(next->bus_head); TempSlot = next; next = next->next; @@ -700,8 +630,5 @@ static void __exit pcied_cleanup(void) info(DRIVER_DESC " version: " DRIVER_VERSION " unloaded\n"); } - module_init(pcied_init); module_exit(pcied_cleanup); - -