diff options
author | Sreenivasa Honnur <sreenivasa.honnur@neterion.com> | 2007-11-14 04:41:06 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2007-11-14 04:41:06 -0500 |
commit | 18b2b7bd09811779309592a10080fe9ffb93144d (patch) | |
tree | 12d3b9b5ece4a93a477755f9c1878f72db9cb559 /drivers/net/s2io.c | |
parent | 8cbdeec637c1ce87bf329c5c19a9964e36bdf9fb (diff) |
[S2IO]: Fixed memory leak when MSI-X vector allocation fails
- Fixed memory leak by freeing MSI-X local entry memories when vector allocation
fails in s2io_add_isr.
- Added two utility functions remove_msix_isr and remove_inta_isr to eliminate
code duplication.
- Incorporated following review comments from Jeff
- Removed redundant stats->mem_freed and synchronize_irq call
- do_rem_msix_isr is renamed as remove_msix_isr
- do_rem_inta_isr is renamed as remove_inta_isr
Signed-off-by: Sreenivasa Honnur <sreenivasa.honnur@neterion.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/s2io.c')
-rw-r--r-- | drivers/net/s2io.c | 110 |
1 files changed, 51 insertions, 59 deletions
diff --git a/drivers/net/s2io.c b/drivers/net/s2io.c index b8c0e7b4ca1c..632666706247 100644 --- a/drivers/net/s2io.c +++ b/drivers/net/s2io.c | |||
@@ -84,7 +84,7 @@ | |||
84 | #include "s2io.h" | 84 | #include "s2io.h" |
85 | #include "s2io-regs.h" | 85 | #include "s2io-regs.h" |
86 | 86 | ||
87 | #define DRV_VERSION "2.0.26.5" | 87 | #define DRV_VERSION "2.0.26.6" |
88 | 88 | ||
89 | /* S2io Driver name & version. */ | 89 | /* S2io Driver name & version. */ |
90 | static char s2io_driver_name[] = "Neterion"; | 90 | static char s2io_driver_name[] = "Neterion"; |
@@ -3775,6 +3775,40 @@ static int __devinit s2io_test_msi(struct s2io_nic *sp) | |||
3775 | 3775 | ||
3776 | return err; | 3776 | return err; |
3777 | } | 3777 | } |
3778 | |||
3779 | static void remove_msix_isr(struct s2io_nic *sp) | ||
3780 | { | ||
3781 | int i; | ||
3782 | u16 msi_control; | ||
3783 | |||
3784 | for (i = 0; i < MAX_REQUESTED_MSI_X; i++) { | ||
3785 | if (sp->s2io_entries[i].in_use == | ||
3786 | MSIX_REGISTERED_SUCCESS) { | ||
3787 | int vector = sp->entries[i].vector; | ||
3788 | void *arg = sp->s2io_entries[i].arg; | ||
3789 | free_irq(vector, arg); | ||
3790 | } | ||
3791 | } | ||
3792 | |||
3793 | kfree(sp->entries); | ||
3794 | kfree(sp->s2io_entries); | ||
3795 | sp->entries = NULL; | ||
3796 | sp->s2io_entries = NULL; | ||
3797 | |||
3798 | pci_read_config_word(sp->pdev, 0x42, &msi_control); | ||
3799 | msi_control &= 0xFFFE; /* Disable MSI */ | ||
3800 | pci_write_config_word(sp->pdev, 0x42, msi_control); | ||
3801 | |||
3802 | pci_disable_msix(sp->pdev); | ||
3803 | } | ||
3804 | |||
3805 | static void remove_inta_isr(struct s2io_nic *sp) | ||
3806 | { | ||
3807 | struct net_device *dev = sp->dev; | ||
3808 | |||
3809 | free_irq(sp->pdev->irq, dev); | ||
3810 | } | ||
3811 | |||
3778 | /* ********************************************************* * | 3812 | /* ********************************************************* * |
3779 | * Functions defined below concern the OS part of the driver * | 3813 | * Functions defined below concern the OS part of the driver * |
3780 | * ********************************************************* */ | 3814 | * ********************************************************* */ |
@@ -3809,28 +3843,9 @@ static int s2io_open(struct net_device *dev) | |||
3809 | int ret = s2io_enable_msi_x(sp); | 3843 | int ret = s2io_enable_msi_x(sp); |
3810 | 3844 | ||
3811 | if (!ret) { | 3845 | if (!ret) { |
3812 | u16 msi_control; | ||
3813 | |||
3814 | ret = s2io_test_msi(sp); | 3846 | ret = s2io_test_msi(sp); |
3815 | |||
3816 | /* rollback MSI-X, will re-enable during add_isr() */ | 3847 | /* rollback MSI-X, will re-enable during add_isr() */ |
3817 | kfree(sp->entries); | 3848 | remove_msix_isr(sp); |
3818 | sp->mac_control.stats_info->sw_stat.mem_freed += | ||
3819 | (MAX_REQUESTED_MSI_X * | ||
3820 | sizeof(struct msix_entry)); | ||
3821 | kfree(sp->s2io_entries); | ||
3822 | sp->mac_control.stats_info->sw_stat.mem_freed += | ||
3823 | (MAX_REQUESTED_MSI_X * | ||
3824 | sizeof(struct s2io_msix_entry)); | ||
3825 | sp->entries = NULL; | ||
3826 | sp->s2io_entries = NULL; | ||
3827 | |||
3828 | pci_read_config_word(sp->pdev, 0x42, &msi_control); | ||
3829 | msi_control &= 0xFFFE; /* Disable MSI */ | ||
3830 | pci_write_config_word(sp->pdev, 0x42, msi_control); | ||
3831 | |||
3832 | pci_disable_msix(sp->pdev); | ||
3833 | |||
3834 | } | 3849 | } |
3835 | if (ret) { | 3850 | if (ret) { |
3836 | 3851 | ||
@@ -6719,15 +6734,22 @@ static int s2io_add_isr(struct s2io_nic * sp) | |||
6719 | } | 6734 | } |
6720 | } | 6735 | } |
6721 | if (err) { | 6736 | if (err) { |
6737 | remove_msix_isr(sp); | ||
6722 | DBG_PRINT(ERR_DBG,"%s:MSI-X-%d registration " | 6738 | DBG_PRINT(ERR_DBG,"%s:MSI-X-%d registration " |
6723 | "failed\n", dev->name, i); | 6739 | "failed\n", dev->name, i); |
6724 | DBG_PRINT(ERR_DBG, "Returned: %d\n", err); | 6740 | DBG_PRINT(ERR_DBG, "%s: defaulting to INTA\n", |
6725 | return -1; | 6741 | dev->name); |
6742 | sp->config.intr_type = INTA; | ||
6743 | break; | ||
6726 | } | 6744 | } |
6727 | sp->s2io_entries[i].in_use = MSIX_REGISTERED_SUCCESS; | 6745 | sp->s2io_entries[i].in_use = MSIX_REGISTERED_SUCCESS; |
6728 | } | 6746 | } |
6729 | printk("MSI-X-TX %d entries enabled\n",msix_tx_cnt); | 6747 | if (!err) { |
6730 | printk("MSI-X-RX %d entries enabled\n",msix_rx_cnt); | 6748 | printk(KERN_INFO "MSI-X-TX %d entries enabled\n", |
6749 | msix_tx_cnt); | ||
6750 | printk(KERN_INFO "MSI-X-RX %d entries enabled\n", | ||
6751 | msix_rx_cnt); | ||
6752 | } | ||
6731 | } | 6753 | } |
6732 | if (sp->config.intr_type == INTA) { | 6754 | if (sp->config.intr_type == INTA) { |
6733 | err = request_irq((int) sp->pdev->irq, s2io_isr, IRQF_SHARED, | 6755 | err = request_irq((int) sp->pdev->irq, s2io_isr, IRQF_SHARED, |
@@ -6742,40 +6764,10 @@ static int s2io_add_isr(struct s2io_nic * sp) | |||
6742 | } | 6764 | } |
6743 | static void s2io_rem_isr(struct s2io_nic * sp) | 6765 | static void s2io_rem_isr(struct s2io_nic * sp) |
6744 | { | 6766 | { |
6745 | struct net_device *dev = sp->dev; | 6767 | if (sp->config.intr_type == MSI_X) |
6746 | struct swStat *stats = &sp->mac_control.stats_info->sw_stat; | 6768 | remove_msix_isr(sp); |
6747 | 6769 | else | |
6748 | if (sp->config.intr_type == MSI_X) { | 6770 | remove_inta_isr(sp); |
6749 | int i; | ||
6750 | u16 msi_control; | ||
6751 | |||
6752 | for (i=1; (sp->s2io_entries[i].in_use == | ||
6753 | MSIX_REGISTERED_SUCCESS); i++) { | ||
6754 | int vector = sp->entries[i].vector; | ||
6755 | void *arg = sp->s2io_entries[i].arg; | ||
6756 | |||
6757 | synchronize_irq(vector); | ||
6758 | free_irq(vector, arg); | ||
6759 | } | ||
6760 | |||
6761 | kfree(sp->entries); | ||
6762 | stats->mem_freed += | ||
6763 | (MAX_REQUESTED_MSI_X * sizeof(struct msix_entry)); | ||
6764 | kfree(sp->s2io_entries); | ||
6765 | stats->mem_freed += | ||
6766 | (MAX_REQUESTED_MSI_X * sizeof(struct s2io_msix_entry)); | ||
6767 | sp->entries = NULL; | ||
6768 | sp->s2io_entries = NULL; | ||
6769 | |||
6770 | pci_read_config_word(sp->pdev, 0x42, &msi_control); | ||
6771 | msi_control &= 0xFFFE; /* Disable MSI */ | ||
6772 | pci_write_config_word(sp->pdev, 0x42, msi_control); | ||
6773 | |||
6774 | pci_disable_msix(sp->pdev); | ||
6775 | } else { | ||
6776 | synchronize_irq(sp->pdev->irq); | ||
6777 | free_irq(sp->pdev->irq, dev); | ||
6778 | } | ||
6779 | } | 6771 | } |
6780 | 6772 | ||
6781 | static void do_s2io_card_down(struct s2io_nic * sp, int do_io) | 6773 | static void do_s2io_card_down(struct s2io_nic * sp, int do_io) |