Skip to content

Commit a870a02

Browse files
arndbdavem330
authored andcommitted
pktgen: use dynamic allocation for debug print buffer
After the removal of the VLA, we get a harmless warning about a large stack frame: net/core/pktgen.c: In function 'pktgen_if_write': net/core/pktgen.c:1710:1: error: the frame size of 1076 bytes is larger than 1024 bytes [-Werror=frame-larger-than=] The function was previously shown to be safe despite hitting the 1024 bye warning level. To get rid of the annoyging warning, while keeping it readable, this changes it to use strndup_user(). Obviously this is not a fast path, so the kmalloc() overhead can be disregarded. Fixes: 3595139 ("pktgen: Remove VLA usage") Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent be9fc09 commit a870a02

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

net/core/pktgen.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -906,13 +906,14 @@ static ssize_t pktgen_if_write(struct file *file,
906906
i += len;
907907

908908
if (debug) {
909-
size_t copy = min_t(size_t, count, 1023);
910-
char tb[1024];
911-
if (copy_from_user(tb, user_buffer, copy))
912-
return -EFAULT;
913-
tb[copy] = 0;
914-
pr_debug("%s,%lu buffer -:%s:-\n",
915-
name, (unsigned long)count, tb);
909+
size_t copy = min_t(size_t, count + 1, 1024);
910+
char *tp = strndup_user(user_buffer, copy);
911+
912+
if (IS_ERR(tp))
913+
return PTR_ERR(tp);
914+
915+
pr_debug("%s,%zu buffer -:%s:-\n", name, count, tp);
916+
kfree(buf);
916917
}
917918

918919
if (!strcmp(name, "min_pkt_size")) {

0 commit comments

Comments
 (0)