From e21ce7019cc3b9495be8678ef2c41569cc03021e Mon Sep 17 00:00:00 2001 From: merge Date: Wed, 26 Nov 2008 21:18:18 +0000 Subject: MERGE-via-balaji-tracking-hist-MERGE-via-stable-tracking-hist-ar6k-break-down-insane-allocat balaji-tracking-hist top was MERGE-via-stable-tracking-hist-ar6k-break-down-insane-allocat / 6a9c6db399ca60d371ec6b42986608e8bc4a636f ... parent commitmessage: From: merge MERGE-via-stable-tracking-hist-ar6k-break-down-insane-allocat stable-tracking-hist top was ar6k-break-down-insane-allocat / ac6b4c5fae9b497401eeb3e47cc21932839c18a2 ... parent commitmessage: From: Werner Almesberger ar6k-break-down-insane-allocation.patch The Atheros WLAN stack kmallocs almost 64kB of contiguous kernel memory for a structure containing almost entirely buffers. As is commonly known , this kind of large allocation has a very high risk of failing as kernel memory fragments during the life of a system. This patch allocates the buffers indiviudually, thus shrinking the structure to a size below 4kB. Note: this is untested. These buffers are only used with Atheros' raw interface, which none of the code we have, including wmiconfig, even seems to know about. This may fix bug #2133. Code follows Atheros' style, so checkpatch hates it. Signed-off-by: Werner Almesberger --- drivers/ar6000/ar6000/ar6000_drv.c | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'drivers/ar6000/ar6000/ar6000_drv.c') diff --git a/drivers/ar6000/ar6000/ar6000_drv.c b/drivers/ar6000/ar6000/ar6000_drv.c index 5dd16517f1e..77730b2a3ac 100644 --- a/drivers/ar6000/ar6000/ar6000_drv.c +++ b/drivers/ar6000/ar6000/ar6000_drv.c @@ -659,6 +659,40 @@ A_STATUS ar6000_SetHTCBlockSize(AR_SOFTC_T *ar) return status; } +static void free_raw_buffers(AR_SOFTC_T *ar) +{ + int i, j; + + for (i = 0; i != HTC_RAW_STREAM_NUM_MAX; i++) { + for (j = 0; j != RAW_HTC_READ_BUFFERS_NUM; j++) + kfree(ar->raw_htc_read_buffer[i][j]); + for (j = 0; j != RAW_HTC_WRITE_BUFFERS_NUM; j++) + kfree(ar->raw_htc_write_buffer[i][j]); + } +} + +static int alloc_raw_buffers(AR_SOFTC_T *ar) +{ + int i, j; + raw_htc_buffer *b; + + for (i = 0; i != HTC_RAW_STREAM_NUM_MAX; i++) { + for (j = 0; j != RAW_HTC_READ_BUFFERS_NUM; j++) { + b = kzalloc(sizeof(*b), GFP_KERNEL); + if (!b) + return -ENOMEM; + ar->raw_htc_read_buffer[i][j] = b; + } + for (j = 0; j != RAW_HTC_WRITE_BUFFERS_NUM; j++) { + b = kzalloc(sizeof(*b), GFP_KERNEL); + if (!b) + return -ENOMEM; + ar->raw_htc_write_buffer[i][j] = b; + } + } + return 0; +} + /* * HTC Event handlers */ @@ -723,6 +757,15 @@ ar6000_avail_ev(HTC_HANDLE HTCHandle) init_waitqueue_head(&arEvent); sema_init(&ar->arSem, 1); + if (alloc_raw_buffers(ar)) { + free_raw_buffers(ar); + /* + * @@@ Clean up our own mess, but for anything else, cheerfully mimick + * the beautiful error non-handling of the rest of this function. + */ + return; + } + #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL A_INIT_TIMER(&aptcTimer, aptcTimerHandler, ar); #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */ @@ -1004,6 +1047,9 @@ ar6000_destroy(struct net_device *dev, unsigned int unregister) /* Free up the device data structure */ if (unregister) unregister_netdev(dev); + + free_raw_buffers(ar); + #ifndef free_netdev kfree(dev); #else -- cgit v1.2.3