mISDN: Add allocation of recvbuf[1500] at run time to reduce stack size
authorFrank Seidel <frank@f-seidel.de>
Fri, 22 May 2009 11:04:51 +0000 (11:04 +0000)
committerDavid S. Miller <davem@davemloft.net>
Mon, 25 May 2009 07:55:28 +0000 (00:55 -0700)
Before: 1656 bytes on i386, now 164.
Modified by Andreas Eversberg <andreas@eversberg.eu>

Signed-off-by: Frank Seidel <frank@f-seidel.de>
Signed-off-by: Andreas Eversberg <andreas@eversberg.eu>
Signed-off-by: Karsten Keil <keil@b1-systems.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/isdn/mISDN/l1oip_core.c

index abe574989572098bac2b9e0899c99ee9d08e6dd7..ea3c3aa2004baf93e9f62e4bc253552c6faf7de0 100644 (file)
@@ -663,18 +663,28 @@ l1oip_socket_thread(void *data)
        struct iovec iov;
        mm_segment_t oldfs;
        struct sockaddr_in sin_rx;
-       unsigned char recvbuf[1500];
+       unsigned char *recvbuf;
+       size_t recvbuf_size = 1500;
        int recvlen;
        struct socket *socket = NULL;
        DECLARE_COMPLETION(wait);
 
+       /* allocate buffer memory */
+       recvbuf = kmalloc(recvbuf_size, GFP_KERNEL);
+       if (!recvbuf) {
+               printk(KERN_ERR "%s: Failed to alloc recvbuf.\n", __func__);
+               ret = -ENOMEM;
+               goto fail;
+       }
+
        /* make daemon */
        allow_signal(SIGTERM);
 
        /* create socket */
        if (sock_create(PF_INET, SOCK_DGRAM, IPPROTO_UDP, &socket)) {
                printk(KERN_ERR "%s: Failed to create socket.\n", __func__);
-               return -EIO;
+               ret = -EIO;
+               goto fail;
        }
 
        /* set incoming address */
@@ -730,10 +740,10 @@ l1oip_socket_thread(void *data)
                        __func__);
        while (!signal_pending(current)) {
                iov.iov_base = recvbuf;
-               iov.iov_len = sizeof(recvbuf);
+               iov.iov_len = recvbuf_size;
                oldfs = get_fs();
                set_fs(KERNEL_DS);
-               recvlen = sock_recvmsg(socket, &msg, sizeof(recvbuf), 0);
+               recvlen = sock_recvmsg(socket, &msg, recvbuf_size, 0);
                set_fs(oldfs);
                if (recvlen > 0) {
                        l1oip_socket_parse(hc, &sin_rx, recvbuf, recvlen);
@@ -760,6 +770,9 @@ l1oip_socket_thread(void *data)
                        __func__);
 
 fail:
+       /* free recvbuf */
+       kfree(recvbuf);
+
        /* close socket */
        if (socket)
                sock_release(socket);