diff options
author | Mark Einon <mark.einon@gmail.com> | 2012-11-16 10:47:41 +0000 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-11-21 13:57:28 -0800 |
commit | d959df0a4940e3c07be992279b9439626b23083f (patch) | |
tree | 99c788ea3b59b129e835119042d1c83025c1b9c7 /drivers/staging/et131x | |
parent | 9967bd4842b39eaf632f77028fdd798775fd9686 (diff) | |
download | linux-stable-d959df0a4940e3c07be992279b9439626b23083f.tar.gz linux-stable-d959df0a4940e3c07be992279b9439626b23083f.tar.bz2 linux-stable-d959df0a4940e3c07be992279b9439626b23083f.zip |
staging: et131x: Replace kmem_cache use with plain kmalloc/kfree
The use of a kmem_cache was noted as being unusual in the TODO. Replace
the kmem_cache with kmalloc/kfree so that the code is less suprising.
Also tidy up the mess that was the et131x_init_recv() out of memory
error path.
Signed-off-by: Mark Einon <mark.einon@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/et131x')
-rw-r--r-- | drivers/staging/et131x/README | 1 | ||||
-rw-r--r-- | drivers/staging/et131x/et131x.c | 79 |
2 files changed, 19 insertions, 61 deletions
diff --git a/drivers/staging/et131x/README b/drivers/staging/et131x/README index 474a6f58f8db..38537d4c4e14 100644 --- a/drivers/staging/et131x/README +++ b/drivers/staging/et131x/README @@ -8,7 +8,6 @@ Note, the powermanagement options were removed from the vendor provided driver as they did not build properly at the time. TODO: - - Use of kmem_cache seems a bit unusual - some rx packets have CRC/code/frame errors Please send patches to: diff --git a/drivers/staging/et131x/et131x.c b/drivers/staging/et131x/et131x.c index 703a874996aa..f5f8b1d97398 100644 --- a/drivers/staging/et131x/et131x.c +++ b/drivers/staging/et131x/et131x.c @@ -143,7 +143,6 @@ MODULE_DESCRIPTION("10/100/1000 Base-T Ethernet Driver for the ET1310 by Agere S #define fMP_DEST_BROAD 0x00000002 /* MP_ADAPTER flags */ -#define fMP_ADAPTER_RECV_LOOKASIDE 0x00000004 #define fMP_ADAPTER_INTERRUPT_IN_USE 0x00000008 /* MP_SHARED flags */ @@ -184,7 +183,6 @@ MODULE_DESCRIPTION("10/100/1000 Base-T Ethernet Driver for the ET1310 by Agere S #define NIC_DEFAULT_NUM_RFD 1024 #define NUM_FBRS 2 -#define NIC_MIN_NUM_RFD 64 #define NUM_PACKETS_HANDLED 256 #define ALCATEL_MULTICAST_PKT 0x01000000 @@ -316,9 +314,6 @@ struct rx_ring { u32 num_rfd; bool unfinished_receives; - - /* lookaside lists */ - struct kmem_cache *recv_lookaside; }; /* TX defines */ @@ -2384,21 +2379,6 @@ static int et131x_rx_dma_memory_alloc(struct et131x_adapter *adapter) rx_ring->num_rfd = NIC_DEFAULT_NUM_RFD; pr_info("PRS %llx\n", (unsigned long long)rx_ring->rx_status_bus); - /* Recv - * kmem_cache_create initializes a lookaside list. After successful - * creation, nonpaged fixed-size blocks can be allocated from and - * freed to the lookaside list. - * RFDs will be allocated from this pool. - */ - rx_ring->recv_lookaside = kmem_cache_create(adapter->netdev->name, - sizeof(struct rfd), - 0, - SLAB_CACHE_DMA | - SLAB_HWCACHE_ALIGN, - NULL); - - adapter->flags |= fMP_ADAPTER_RECV_LOOKASIDE; - /* The RFDs are going to be put on lists later on, so initialize the * lists now. */ @@ -2431,7 +2411,7 @@ static void et131x_rx_dma_memory_free(struct et131x_adapter *adapter) list_del(&rfd->list_node); rfd->skb = NULL; - kmem_cache_free(adapter->rx_ring.recv_lookaside, rfd); + kfree(rfd); } /* Free Free Buffer Rings */ @@ -2485,12 +2465,6 @@ static void et131x_rx_dma_memory_free(struct et131x_adapter *adapter) rx_ring->rx_status_block = NULL; } - /* Destroy the lookaside (RFD) pool */ - if (adapter->flags & fMP_ADAPTER_RECV_LOOKASIDE) { - kmem_cache_destroy(rx_ring->recv_lookaside); - adapter->flags &= ~fMP_ADAPTER_RECV_LOOKASIDE; - } - /* Free the FBR Lookup Table */ kfree(rx_ring->fbr[0]); kfree(rx_ring->fbr[1]); @@ -2507,8 +2481,7 @@ static void et131x_rx_dma_memory_free(struct et131x_adapter *adapter) */ static int et131x_init_recv(struct et131x_adapter *adapter) { - int status = -ENOMEM; - struct rfd *rfd = NULL; + struct rfd *rfd; u32 rfdct; u32 numrfd = 0; struct rx_ring *rx_ring; @@ -2518,14 +2491,11 @@ static int et131x_init_recv(struct et131x_adapter *adapter) /* Setup each RFD */ for (rfdct = 0; rfdct < rx_ring->num_rfd; rfdct++) { - rfd = kmem_cache_alloc(rx_ring->recv_lookaside, - GFP_ATOMIC | GFP_DMA); + rfd = kzalloc(sizeof(struct rfd), GFP_ATOMIC | GFP_DMA); if (!rfd) { - dev_err(&adapter->pdev->dev, - "Couldn't alloc RFD out of kmem_cache\n"); - status = -ENOMEM; - continue; + dev_err(&adapter->pdev->dev, "Couldn't alloc RFD\n"); + return -ENOMEM; } rfd->skb = NULL; @@ -2538,17 +2508,7 @@ static int et131x_init_recv(struct et131x_adapter *adapter) numrfd++; } - if (numrfd > NIC_MIN_NUM_RFD) - status = 0; - - rx_ring->num_rfd = numrfd; - - if (status != 0) { - kmem_cache_free(rx_ring->recv_lookaside, rfd); - dev_err(&adapter->pdev->dev, - "Allocation problems in et131x_init_recv\n"); - } - return status; + return 0; } /** @@ -3779,6 +3739,17 @@ static void et131x_error_timer_handler(unsigned long data) } /** + * et131x_adapter_memory_free - Free all memory allocated for use by Tx & Rx + * @adapter: pointer to our private adapter structure + */ +static void et131x_adapter_memory_free(struct et131x_adapter *adapter) +{ + /* Free DMA memory */ + et131x_tx_dma_memory_free(adapter); + et131x_rx_dma_memory_free(adapter); +} + +/** * et131x_adapter_memory_alloc * @adapter: pointer to our private adapter structure * @@ -3808,26 +3779,14 @@ static int et131x_adapter_memory_alloc(struct et131x_adapter *adapter) /* Init receive data structures */ status = et131x_init_recv(adapter); - if (status != 0) { + if (status) { dev_err(&adapter->pdev->dev, "et131x_init_recv FAILED\n"); - et131x_tx_dma_memory_free(adapter); - et131x_rx_dma_memory_free(adapter); + et131x_adapter_memory_free(adapter); } return status; } -/** - * et131x_adapter_memory_free - Free all memory allocated for use by Tx & Rx - * @adapter: pointer to our private adapter structure - */ -static void et131x_adapter_memory_free(struct et131x_adapter *adapter) -{ - /* Free DMA memory */ - et131x_tx_dma_memory_free(adapter); - et131x_rx_dma_memory_free(adapter); -} - static void et131x_adjust_link(struct net_device *netdev) { struct et131x_adapter *adapter = netdev_priv(netdev); |