Skip to contentSkip to conversation

mISDN: l1oip - reduce stack memory footprint

PATCH In review Frank Seidel 2 participants 2 messages Feb 25, 2009 – Feb 26, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mISDN: l1oip - reduce stack memory footprint

From: Frank Seidel <[email protected]>

Applying kernel janitors todos (reduce stack
footprint where possible) to l1oip mISDN driver.
(Before 1656 bytes on i386, now 164)

---
 drivers/isdn/mISDN/l1oip_core.c |   21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)
drivers/isdn/mISDN/l1oip_core.c +17 -4
@@ -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 * sizeof(*recvbuf), GFP_KERNEL);
+	if (!recvbuf) {
+		printk(KERN_ERR "%s: Failed to allocate memory.\n", __func__);
+		ret = -ENOMEM;
+		goto out;
+	}
+
 	/* 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 out;
 	}
 
 	/* 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);
@@ -771,6 +781,9 @@ fail:
 	if (debug & DEBUG_L1OIP_SOCKET)
 		printk(KERN_DEBUG "%s: socket thread terminated\n",
 			__func__);
+
+out:
+	kfree(recvbuf);
 	return ret;
 }
 
#1 lore raw
Quoted 16 lines · On Wed, 25 Feb 2009 16:54:56 +0100 Frank Seidel <[email protected]> wrote:

From: Frank Seidel <[email protected]>

Applying kernel janitors todos (reduce stack
footprint where possible) to l1oip mISDN driver.
(Before 1656 bytes on i386, now 164)

---
 drivers/isdn/mISDN/l1oip_core.c |   21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)
drivers/isdn/mISDN/l1oip_core.c +0 -0
@@ -663,18 +663,28 @@ l1oip_socket_thread(void *data)
 	struct iovec iov;
 	mm_segment_t oldfs;

drivers/isdn/mISDN/l1oip_core.c l1oip_socket_thread(void *data) · line 673

Quoted 10 lines
drivers/isdn/mISDN/l1oip_core.c +4 -1
 	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 * sizeof(*recvbuf), GFP_KERNEL);

It's rather pointless to multiply by sizeof(*recvbuf) here

drivers/isdn/mISDN/l1oip_core.c l1oip_socket_thread(void *data) · line 746

Quoted 6 lines
drivers/isdn/mISDN/l1oip_core.c +2 -2
-		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);

but not here.