Skip to contentSkip to conversation

staging: dgnc: fix compile warning frame size is larger than 1024 bytes

PATCH In review Martin Kepplinger 2 participants 3 messages May 6, 2014 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: dgnc: fix compile warning frame size is larger than 1024 bytes

fix following warning by dynamically allocating memory:
dgnc_tty.c:583:1: warning: the frame size of 1060 bytes is larger than 1024 bytes [-Wframe-larger-than=]

---
This is more of a question. Is this a desired solution to fixing such a frame size warning?

thanks,
martin

 drivers/staging/dgnc/dgnc_tty.c |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/staging/dgnc/dgnc_tty.c +9 -2
index f0b17c3..1c78cc2 100644
@@ -481,8 +481,8 @@ void dgnc_sniff_nowait_nolock(struct channel_t *ch, uchar *text, uchar *buf, int
 	int nbuf;
 	int i;
 	int tmpbuflen;
-	char tmpbuf[TMPBUFLEN];
-	char *p = tmpbuf;
+	char *tmpbuf;
+	char *p;
 	int too_much_data;
 
 	/* Leave if sniff not open */
@@ -492,6 +492,13 @@ void dgnc_sniff_nowait_nolock(struct channel_t *ch, uchar *text, uchar *buf, int
 	do_gettimeofday(&tv);
 
 	/* Create our header for data dump */
+	tmpbuf = kmalloc(TMPBUFLEN, GFP_KERNEL);
+	if (!tmpbuf) {
+		pr_err("dgnc: memory allocation error\n");
+		return;
+	}
+	p = tmpbuf;
+
 	p += sprintf(p, "<%ld %ld><%s><", tv.tv_sec, tv.tv_usec, text);
 	tmpbuflen = p - tmpbuf;
 
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 7 lines · Martin Kepplinger

fix following warning by dynamically allocating memory:
dgnc_tty.c:583:1: warning: the frame size of 1060 bytes is larger than 1024 bytes [-Wframe-larger-than=]

---
This is more of a question. Is this a desired solution to fixing such a frame size warning?

This warning is because the kernel uses an 8k stack so you add up all the stack memory used by each function from the syscall to here. If it adds up to more than 8k then it's a bug. The 1k limit per function is just a hack to spot where people are maybe being reckless.

There are no kfree()s and this function is called with a spin_lock held so this patch introduces a couple bugs.

There may be a better way to allocate this. Like maybe at probe() and then use spinlocks to serialize access to the buffer. But sometimes that's a very bad idea.

It's better if you know the driver a bit and can test things.

regards,
dan carpenter

#2 lore raw

Am 2014-05-06 15:33, schrieb Dan Carpenter:

Quoted 9 lines · Martin Kepplinger
Quoted 7 lines

fix following warning by dynamically allocating memory:
dgnc_tty.c:583:1: warning: the frame size of 1060 bytes is larger than 1024 bytes [-Wframe-larger-than=]

---
This is more of a question. Is this a desired solution to fixing such a frame size warning?

Quoted 4 lines

This warning is because the kernel uses an 8k stack so you add up all the stack memory used by each function from the syscall to here. If it adds up to more than 8k then it's a bug. The 1k limit per function is just a hack to spot where people are maybe being reckless.

nice. thanks.

Quoted 3 lines

There are no kfree()s and this function is called with a spin_lock held so this patch introduces a couple bugs.

I know, it should have been just a question (probably to kernelnewbies' list). Sorry for the noise.

Quoted 16 lines

There may be a better way to allocate this. Like maybe at probe() and then use spinlocks to serialize access to the buffer. But sometimes that's a very bad idea.

It's better if you know the driver a bit and can test things.

regards,
dan carpenter

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/