linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][trivial] mISDN: l1oip - reduce stack memory footprint
@ 2009-02-25 15:54 Frank Seidel
  2009-02-26 22:16 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Frank Seidel @ 2009-02-25 15:54 UTC (permalink / raw)
  To: linux kernel
  Cc: akpm, linux-isdn, Frank Seidel, Frank Seidel, jolly, kkeil,
	smurf, andreas, hannes

From: Frank Seidel <frank@f-seidel.de>

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

Signed-off-by: Frank Seidel <frank@f-seidel.de>
---
 drivers/isdn/mISDN/l1oip_core.c |   21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

--- a/drivers/isdn/mISDN/l1oip_core.c
+++ b/drivers/isdn/mISDN/l1oip_core.c
@@ -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;
 }
 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH][trivial] mISDN: l1oip - reduce stack memory footprint
  2009-02-25 15:54 [PATCH][trivial] mISDN: l1oip - reduce stack memory footprint Frank Seidel
@ 2009-02-26 22:16 ` Andrew Morton
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2009-02-26 22:16 UTC (permalink / raw)
  To: Frank Seidel
  Cc: linux-kernel, linux-isdn, fseidel, frank, jolly, kkeil, smurf,
	andreas, hannes

On Wed, 25 Feb 2009 16:54:56 +0100
Frank Seidel <fseidel@suse.de> wrote:

> From: Frank Seidel <frank@f-seidel.de>
> 
> Applying kernel janitors todos (reduce stack
> footprint where possible) to l1oip mISDN driver.
> (Before 1656 bytes on i386, now 164)
> 
> Signed-off-by: Frank Seidel <frank@f-seidel.de>
> ---
>  drivers/isdn/mISDN/l1oip_core.c |   21 +++++++++++++++++----
>  1 file changed, 17 insertions(+), 4 deletions(-)
> 
> --- a/drivers/isdn/mISDN/l1oip_core.c
> +++ b/drivers/isdn/mISDN/l1oip_core.c
> @@ -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);

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

> -		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.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH][trivial] mISDN: l1oip - reduce stack memory footprint
@ 2009-02-25 16:20 Karsten Keil
  0 siblings, 0 replies; 3+ messages in thread
From: Karsten Keil @ 2009-02-25 16:20 UTC (permalink / raw)
  To: Frank Seidel
  Cc: linux kernel, akpm, linux-isdn, Frank Seidel, jolly, kkeil,
	smurf, andreas, hannes

From: Frank Seidel <frank@f-seidel.de>

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

Signed-off-by: Frank Seidel <frank@f-seidel.de>
Acked-by: Karsten Keil <kkeil@suse.de>
---
 drivers/isdn/mISDN/l1oip_core.c |   21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

--- a/drivers/isdn/mISDN/l1oip_core.c
+++ b/drivers/isdn/mISDN/l1oip_core.c
@@ -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;
 }
 


-- 
Karsten Keil
SuSE Labs
ISDN and VOIP development
SUSE LINUX Products GmbH, Maxfeldstr.5 90409 Nuernberg, GF: Markus Rex, HRB 16746 (AG Nuernberg)

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-02-26 22:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-25 15:54 [PATCH][trivial] mISDN: l1oip - reduce stack memory footprint Frank Seidel
2009-02-26 22:16 ` Andrew Morton
2009-02-25 16:20 Karsten Keil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).