Source-Changes-HG archive

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

[src/trunk]: src/sys/dev avoid stack usage in match routine



details:   https://anonhg.NetBSD.org/src/rev/d7032983cd94
branches:  trunk
changeset: 973237:d7032983cd94
user:      jdolecek <jdolecek%NetBSD.org@localhost>
date:      Wed Jun 24 19:11:49 2020 +0000

description:
avoid stack usage in match routine

diffstat:

 sys/dev/i2c/lm_i2c.c        |  19 +++++++++++--------
 sys/dev/isa/lm_isa_common.c |  19 +++++++++++--------
 2 files changed, 22 insertions(+), 16 deletions(-)

diffs (107 lines):

diff -r 4bb8ca40e348 -r d7032983cd94 sys/dev/i2c/lm_i2c.c
--- a/sys/dev/i2c/lm_i2c.c      Wed Jun 24 18:49:01 2020 +0000
+++ b/sys/dev/i2c/lm_i2c.c      Wed Jun 24 19:11:49 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lm_i2c.c,v 1.5 2018/06/16 21:22:13 thorpej Exp $       */
+/*     $NetBSD: lm_i2c.c,v 1.6 2020/06/24 19:11:49 jdolecek Exp $      */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -30,13 +30,14 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lm_i2c.c,v 1.5 2018/06/16 21:22:13 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lm_i2c.c,v 1.6 2020/06/24 19:11:49 jdolecek Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/kernel.h>
 #include <sys/device.h>
 #include <sys/conf.h>
+#include <sys/kmem.h>
 
 #include <dev/i2c/i2cvar.h>
 
@@ -65,7 +66,7 @@
 {
        struct i2c_attach_args *ia = aux;
        int rv = 0;
-       struct lm_i2c_softc sc;
+       struct lm_i2c_softc *sc;
 
        /* Must supply an address */
        if (ia->ia_addr < 1)
@@ -74,11 +75,13 @@
        /* XXXJRT filter addresses //at all// please? */
 
        /* Bus independent probe */
-       sc.sc_lmsc.lm_writereg = lm_i2c_writereg;
-       sc.sc_lmsc.lm_readreg = lm_i2c_readreg;
-       sc.sc_tag = ia->ia_tag;
-       sc.sc_addr = ia->ia_addr;
-       rv = lm_match(&sc.sc_lmsc);
+       sc = kmem_zalloc(sizeof(*sc), KM_SLEEP);
+       sc->sc_lmsc.lm_writereg = lm_i2c_writereg;
+       sc->sc_lmsc.lm_readreg = lm_i2c_readreg;
+       sc->sc_tag = ia->ia_tag;
+       sc->sc_addr = ia->ia_addr;
+       rv = lm_match(&sc->sc_lmsc);
+       kmem_free(sc, sizeof(*sc));
 
        return rv ? I2C_MATCH_ADDRESS_AND_PROBE : 0;
 }
diff -r 4bb8ca40e348 -r d7032983cd94 sys/dev/isa/lm_isa_common.c
--- a/sys/dev/isa/lm_isa_common.c       Wed Jun 24 18:49:01 2020 +0000
+++ b/sys/dev/isa/lm_isa_common.c       Wed Jun 24 19:11:49 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lm_isa_common.c,v 1.6 2017/08/18 04:07:51 msaitoh Exp $ */
+/*     $NetBSD: lm_isa_common.c,v 1.7 2020/06/24 19:11:49 jdolecek Exp $ */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lm_isa_common.c,v 1.6 2017/08/18 04:07:51 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lm_isa_common.c,v 1.7 2020/06/24 19:11:49 jdolecek Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -38,6 +38,7 @@
 #include <sys/device.h>
 #include <sys/module.h>
 #include <sys/conf.h>
+#include <sys/kmem.h>
 
 #include <sys/bus.h>
 
@@ -64,7 +65,7 @@
 {
        bus_space_handle_t ioh;
        struct isa_attach_args *ia = aux;
-       struct lm_isa_softc sc;
+       struct lm_isa_softc *sc;
        int rv;
 
        /* Must supply an address */
@@ -81,11 +82,13 @@
                return 0;
 
        /* Bus independent probe */
-       sc.lm_iot = ia->ia_iot;
-       sc.lm_ioh = ioh;
-       sc.lmsc.lm_writereg = lm_isa_writereg;
-       sc.lmsc.lm_readreg = lm_isa_readreg;
-       rv = lm_match(&sc.lmsc);
+       sc = kmem_zalloc(sizeof(*sc), KM_SLEEP);
+       sc->lm_iot = ia->ia_iot;
+       sc->lm_ioh = ioh;
+       sc->lmsc.lm_writereg = lm_isa_writereg;
+       sc->lmsc.lm_readreg = lm_isa_readreg;
+       rv = lm_match(&sc->lmsc);
+       kmem_free(sc, sizeof(*sc));
 
        bus_space_unmap(ia->ia_iot, ioh, 8);
 



Home | Main Index | Thread Index | Old Index