Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/i2c avoid double-free



details:   https://anonhg.NetBSD.org/src/rev/892ff727fb7e
branches:  trunk
changeset: 379693:892ff727fb7e
user:      mlelstv <mlelstv%NetBSD.org@localhost>
date:      Tue Jun 15 04:39:49 2021 +0000

description:
avoid double-free

diffstat:

 sys/dev/i2c/am2315.c |  8 +++-----
 sys/dev/i2c/dbcool.c |  9 +++++----
 sys/dev/i2c/hytp14.c |  7 +++----
 sys/dev/i2c/si70xx.c |  8 +++-----
 4 files changed, 14 insertions(+), 18 deletions(-)

diffs (132 lines):

diff -r 617823c7a10c -r 892ff727fb7e sys/dev/i2c/am2315.c
--- a/sys/dev/i2c/am2315.c      Tue Jun 15 00:20:33 2021 +0000
+++ b/sys/dev/i2c/am2315.c      Tue Jun 15 04:39:49 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: am2315.c,v 1.5 2018/06/17 01:08:15 thorpej Exp $       */
+/*     $NetBSD: am2315.c,v 1.6 2021/06/15 04:40:13 mlelstv Exp $       */
 
 /*
  * Copyright (c) 2017 Brad Spencer <brad%anduin.eldar.org@localhost>
@@ -17,7 +17,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: am2315.c,v 1.5 2018/06/17 01:08:15 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: am2315.c,v 1.6 2021/06/15 04:40:13 mlelstv Exp $");
 
 /*
  * Driver for the Aosong AM2315
@@ -458,10 +458,8 @@ am2315_detach(device_t self, int flags)
        mutex_enter(&sc->sc_mutex);
 
        /* Remove the sensors */
-       if (sc->sc_sme != NULL) {
+       if (sc->sc_sme != NULL)
                sysmon_envsys_unregister(sc->sc_sme);
-               sc->sc_sme = NULL;
-       }
        mutex_exit(&sc->sc_mutex);
 
        /* Destroy the wait cond */
diff -r 617823c7a10c -r 892ff727fb7e sys/dev/i2c/dbcool.c
--- a/sys/dev/i2c/dbcool.c      Tue Jun 15 00:20:33 2021 +0000
+++ b/sys/dev/i2c/dbcool.c      Tue Jun 15 04:39:49 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dbcool.c,v 1.60 2021/01/30 01:22:06 thorpej Exp $ */
+/*     $NetBSD: dbcool.c,v 1.61 2021/06/15 04:39:49 mlelstv Exp $ */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -50,7 +50,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.60 2021/01/30 01:22:06 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.61 2021/06/15 04:39:49 mlelstv Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -819,11 +819,11 @@ dbcool_detach(device_t self, int flags)
 
        pmf_device_deregister(self);
 
-       sysmon_envsys_unregister(sc->sc_sme);
+       if (sc->sc_sme != NULL)
+               sysmon_envsys_unregister(sc->sc_sme);
 
        sysctl_teardown(&sc->sc_sysctl_log);
 
-       sc->sc_sme = NULL;
        return 0;
 }
 
@@ -1600,6 +1600,7 @@ dbcool_setup(device_t self)
 
 out:
        sysmon_envsys_destroy(sc->sc_sme);
+       sc->sc_sme = NULL;
 }
 
 static int
diff -r 617823c7a10c -r 892ff727fb7e sys/dev/i2c/hytp14.c
--- a/sys/dev/i2c/hytp14.c      Tue Jun 15 00:20:33 2021 +0000
+++ b/sys/dev/i2c/hytp14.c      Tue Jun 15 04:39:49 2021 +0000
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hytp14.c,v 1.13 2021/01/27 02:29:48 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hytp14.c,v 1.14 2021/06/15 04:39:49 mlelstv Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -204,6 +204,7 @@ hytp14_attach(device_t parent, device_t 
                aprint_error_dev(sc->sc_dev,
                    "unable to register with sysmon\n");
                sysmon_envsys_destroy(sc->sc_sme);
+               sc->sc_sme = NULL;
                return;
        }
 
@@ -244,10 +245,8 @@ hytp14_detach(device_t self, int flags)
 
        sc = device_private(self);
 
-       if (sc->sc_sme != NULL) {
+       if (sc->sc_sme != NULL)
                sysmon_envsys_unregister(sc->sc_sme);
-               sc->sc_sme = NULL;
-       }
 
        /* stop measurement thread */
        mutex_enter(&sc->sc_mutex);
diff -r 617823c7a10c -r 892ff727fb7e sys/dev/i2c/si70xx.c
--- a/sys/dev/i2c/si70xx.c      Tue Jun 15 00:20:33 2021 +0000
+++ b/sys/dev/i2c/si70xx.c      Tue Jun 15 04:39:49 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: si70xx.c,v 1.6 2020/12/05 14:50:33 jdc Exp $   */
+/*     $NetBSD: si70xx.c,v 1.7 2021/06/15 04:39:49 mlelstv Exp $       */
 
 /*
  * Copyright (c) 2017 Brad Spencer <brad%anduin.eldar.org@localhost>
@@ -17,7 +17,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: si70xx.c,v 1.6 2020/12/05 14:50:33 jdc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: si70xx.c,v 1.7 2021/06/15 04:39:49 mlelstv Exp $");
 
 /*
   Driver for the Silicon Labs SI7013/SI7020/SI7021
@@ -968,10 +968,8 @@ si70xx_detach(device_t self, int flags)
        mutex_enter(&sc->sc_mutex);
 
        /* Remove the sensors */
-       if (sc->sc_sme != NULL) {
+       if (sc->sc_sme != NULL)
                sysmon_envsys_unregister(sc->sc_sme);
-               sc->sc_sme = NULL;
-       }
        mutex_exit(&sc->sc_mutex);
 
        /* Remove the sysctl tree */



Home | Main Index | Thread Index | Old Index