Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/compat/common reduce stack usage in compat_60_ptmget_ioc...



details:   https://anonhg.NetBSD.org/src/rev/0bc26712bcba
branches:  trunk
changeset: 973232:0bc26712bcba
user:      jdolecek <jdolecek%NetBSD.org@localhost>
date:      Wed Jun 24 17:47:52 2020 +0000

description:
reduce stack usage in compat_60_ptmget_ioctl() - allocate struct ptmget
via kmem_alloc()

diffstat:

 sys/compat/common/tty_60.c |  19 +++++++++++++------
 1 files changed, 13 insertions(+), 6 deletions(-)

diffs (55 lines):

diff -r 4300c88b9cb7 -r 0bc26712bcba sys/compat/common/tty_60.c
--- a/sys/compat/common/tty_60.c        Wed Jun 24 17:00:58 2020 +0000
+++ b/sys/compat/common/tty_60.c        Wed Jun 24 17:47:52 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tty_60.c,v 1.9 2019/12/12 02:15:42 pgoyette Exp $      */
+/*     $NetBSD: tty_60.c,v 1.10 2020/06/24 17:47:52 jdolecek Exp $     */
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tty_60.c,v 1.9 2019/12/12 02:15:42 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tty_60.c,v 1.10 2020/06/24 17:47:52 jdolecek Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -42,6 +42,7 @@
 #include <sys/errno.h>
 #include <sys/systm.h>
 #include <sys/compat_stub.h>
+#include <sys/kmem.h>
 
 #include <sys/tty.h>
 
@@ -70,7 +71,7 @@
 {
        int ret;
        u_long newcmd;
-       struct ptmget pg;
+       struct ptmget *pg;
        const struct cdevsw *cd = cdevsw_lookup(dev);
 
        if (cd == NULL || cd->d_ioctl == NULL)
@@ -82,10 +83,16 @@
        default: return ENOTTY;
        }
 
-       ret = (cd->d_ioctl)(dev, newcmd, &pg, flag, l);
+       pg = kmem_alloc(sizeof(*pg), KM_SLEEP);
+
+       ret = (cd->d_ioctl)(dev, newcmd, pg, flag, l);
        if (ret != 0)
-               return ret;
-       ret = ptmget_to_ptmget60(&pg, data);
+               goto out;
+
+       ret = ptmget_to_ptmget60(pg, data);
+
+out:
+       kmem_free(pg, sizeof(*pg));
        return ret;
 }
 



Home | Main Index | Thread Index | Old Index