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/e0292abef807
branches:  trunk
changeset: 1021724:e0292abef807
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 3bda176900f8 -r e0292abef807 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 @@
        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 3bda176900f8 -r e0292abef807 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 @@
 
        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 @@
 
 out:
        sysmon_envsys_destroy(sc->sc_sme);
+       sc->sc_sme = NULL;
 }
 
 static int
diff -r 3bda176900f8 -r e0292abef807 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 @@
                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 @@
 
        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 3bda176900f8 -r e0292abef807 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 @@
        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