Sat Dec 5 14:50:33 2020 UTC ()
Make sure that we set sc->sc_sme to NULL in failure cases in order to avoid
calling sysmon_envsys_unregister() with an invalid struct when we detach.


(jdc)
diff -r1.9 -r1.10 src/sys/dev/i2c/hytp14.c
diff -r1.5 -r1.6 src/sys/dev/i2c/si70xx.c

cvs diff -r1.9 -r1.10 src/sys/dev/i2c/hytp14.c (expand / switch to unified diff)

--- src/sys/dev/i2c/hytp14.c 2019/10/08 21:16:11 1.9
+++ src/sys/dev/i2c/hytp14.c 2020/12/05 14:50:33 1.10
@@ -51,27 +51,27 @@ @@ -51,27 +51,27 @@
51 * compatible = "ist-ag,i2c-hytp14"; 51 * compatible = "ist-ag,i2c-hytp14";
52 * reg = <0x28>; 52 * reg = <0x28>;
53 * status = "okay"; 53 * status = "okay";
54 * }; 54 * };
55 * hythygtemp@29 {  55 * hythygtemp@29 {
56 * compatible = "ist-ag,i2c-hytp14"; 56 * compatible = "ist-ag,i2c-hytp14";
57 * reg = <0x29>; 57 * reg = <0x29>;
58 * status = "okay"; 58 * status = "okay";
59 * }; 59 * };
60 * }; 60 * };
61 */ 61 */
62 62
63#include <sys/cdefs.h> 63#include <sys/cdefs.h>
64__KERNEL_RCSID(0, "$NetBSD: hytp14.c,v 1.9 2019/10/08 21:16:11 kardel Exp $"); 64__KERNEL_RCSID(0, "$NetBSD: hytp14.c,v 1.10 2020/12/05 14:50:33 jdc Exp $");
65 65
66#include <sys/param.h> 66#include <sys/param.h>
67#include <sys/systm.h> 67#include <sys/systm.h>
68#include <sys/kernel.h> 68#include <sys/kernel.h>
69#include <sys/device.h> 69#include <sys/device.h>
70#include <sys/module.h> 70#include <sys/module.h>
71#include <sys/sysctl.h> 71#include <sys/sysctl.h>
72#include <sys/mutex.h> 72#include <sys/mutex.h>
73#include <sys/condvar.h> 73#include <sys/condvar.h>
74#include <sys/kthread.h> 74#include <sys/kthread.h>
75 75
76#include <dev/sysmon/sysmonvar.h> 76#include <dev/sysmon/sysmonvar.h>
77#include <dev/i2c/i2cvar.h> 77#include <dev/i2c/i2cvar.h>
@@ -179,26 +179,27 @@ hytp14_attach(device_t parent, device_t  @@ -179,26 +179,27 @@ hytp14_attach(device_t parent, device_t
179 hytp14_sensors[i].desc, 179 hytp14_sensors[i].desc,
180 sizeof sc->sc_sensors[i].desc); 180 sizeof sc->sc_sensors[i].desc);
181  181
182 sc->sc_sensors[i].units = hytp14_sensors[i].type; 182 sc->sc_sensors[i].units = hytp14_sensors[i].type;
183 sc->sc_sensors[i].state = ENVSYS_SINVALID; 183 sc->sc_sensors[i].state = ENVSYS_SINVALID;
184  184
185 DPRINTF(2, ("hytp14_attach: registering sensor %d (%s)\n", i, 185 DPRINTF(2, ("hytp14_attach: registering sensor %d (%s)\n", i,
186 sc->sc_sensors[i].desc)); 186 sc->sc_sensors[i].desc));
187  187
188 if (sysmon_envsys_sensor_attach(sc->sc_sme, &sc->sc_sensors[i])) { 188 if (sysmon_envsys_sensor_attach(sc->sc_sme, &sc->sc_sensors[i])) {
189 aprint_error_dev(sc->sc_dev, 189 aprint_error_dev(sc->sc_dev,
190 "unable to attach sensor\n"); 190 "unable to attach sensor\n");
191 sysmon_envsys_destroy(sc->sc_sme); 191 sysmon_envsys_destroy(sc->sc_sme);
 192 sc->sc_sme = NULL;
192 return; 193 return;
193 } 194 }
194 } 195 }
195 196
196 sc->sc_sme->sme_name = device_xname(sc->sc_dev); 197 sc->sc_sme->sme_name = device_xname(sc->sc_dev);
197 sc->sc_sme->sme_cookie = sc; 198 sc->sc_sme->sme_cookie = sc;
198 sc->sc_sme->sme_refresh = hytp14_refresh; 199 sc->sc_sme->sme_refresh = hytp14_refresh;
199 200
200 DPRINTF(2, ("hytp14_attach: registering with envsys\n")); 201 DPRINTF(2, ("hytp14_attach: registering with envsys\n"));
201 202
202 if (sysmon_envsys_register(sc->sc_sme)) { 203 if (sysmon_envsys_register(sc->sc_sme)) {
203 aprint_error_dev(sc->sc_dev, 204 aprint_error_dev(sc->sc_dev,
204 "unable to register with sysmon\n"); 205 "unable to register with sysmon\n");

cvs diff -r1.5 -r1.6 src/sys/dev/i2c/si70xx.c (expand / switch to unified diff)

--- src/sys/dev/i2c/si70xx.c 2019/02/03 12:18:21 1.5
+++ src/sys/dev/i2c/si70xx.c 2020/12/05 14:50:33 1.6
@@ -1,33 +1,33 @@ @@ -1,33 +1,33 @@
1/* $NetBSD: si70xx.c,v 1.5 2019/02/03 12:18:21 mrg Exp $ */ 1/* $NetBSD: si70xx.c,v 1.6 2020/12/05 14:50:33 jdc Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2017 Brad Spencer <brad@anduin.eldar.org> 4 * Copyright (c) 2017 Brad Spencer <brad@anduin.eldar.org>
5 * 5 *
6 * Permission to use, copy, modify, and distribute this software for any 6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above 7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies. 8 * copyright notice and this permission notice appear in all copies.
9 * 9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */ 17 */
18 18
19#include <sys/cdefs.h> 19#include <sys/cdefs.h>
20__KERNEL_RCSID(0, "$NetBSD: si70xx.c,v 1.5 2019/02/03 12:18:21 mrg Exp $"); 20__KERNEL_RCSID(0, "$NetBSD: si70xx.c,v 1.6 2020/12/05 14:50:33 jdc Exp $");
21 21
22/* 22/*
23 Driver for the Silicon Labs SI7013/SI7020/SI7021 23 Driver for the Silicon Labs SI7013/SI7020/SI7021
24*/ 24*/
25 25
26#include <sys/param.h> 26#include <sys/param.h>
27#include <sys/systm.h> 27#include <sys/systm.h>
28#include <sys/kernel.h> 28#include <sys/kernel.h>
29#include <sys/device.h> 29#include <sys/device.h>
30#include <sys/module.h> 30#include <sys/module.h>
31#include <sys/sysctl.h> 31#include <sys/sysctl.h>
32#include <sys/mutex.h> 32#include <sys/mutex.h>
33 33
@@ -708,26 +708,27 @@ si70xx_attach(device_t parent, device_t  @@ -708,26 +708,27 @@ si70xx_attach(device_t parent, device_t
708 sizeof(sc->sc_sensors[i].desc)); 708 sizeof(sc->sc_sensors[i].desc));
709 709
710 sc->sc_sensors[i].units = si70xx_sensors[i].type; 710 sc->sc_sensors[i].units = si70xx_sensors[i].type;
711 sc->sc_sensors[i].state = ENVSYS_SINVALID; 711 sc->sc_sensors[i].state = ENVSYS_SINVALID;
712 712
713 DPRINTF(sc, 2, ("%s: registering sensor %d (%s)\n", __func__, i, 713 DPRINTF(sc, 2, ("%s: registering sensor %d (%s)\n", __func__, i,
714 sc->sc_sensors[i].desc)); 714 sc->sc_sensors[i].desc));
715 715
716 error = sysmon_envsys_sensor_attach(sc->sc_sme, 716 error = sysmon_envsys_sensor_attach(sc->sc_sme,
717 &sc->sc_sensors[i]); 717 &sc->sc_sensors[i]);
718 if (error) { 718 if (error) {
719 aprint_error_dev(self, 719 aprint_error_dev(self,
720 "Unable to attach sensor %d: %d\n", i, error); 720 "Unable to attach sensor %d: %d\n", i, error);
 721 sc->sc_sme = NULL;
721 goto out; 722 goto out;
722 } 723 }
723 } 724 }
724 725
725 sc->sc_sme->sme_name = device_xname(sc->sc_dev); 726 sc->sc_sme->sme_name = device_xname(sc->sc_dev);
726 sc->sc_sme->sme_cookie = sc; 727 sc->sc_sme->sme_cookie = sc;
727 sc->sc_sme->sme_refresh = si70xx_refresh; 728 sc->sc_sme->sme_refresh = si70xx_refresh;
728 729
729 DPRINTF(sc, 2, ("si70xx_attach: registering with envsys\n")); 730 DPRINTF(sc, 2, ("si70xx_attach: registering with envsys\n"));
730 731
731 if (sysmon_envsys_register(sc->sc_sme)) { 732 if (sysmon_envsys_register(sc->sc_sme)) {
732 aprint_error_dev(self, 733 aprint_error_dev(self,
733 "unable to register with sysmon\n"); 734 "unable to register with sysmon\n");