Sat Apr 3 17:54:25 2010 UTC ()
Only unregister the sensors if these were successfully installed;
sysmon_envsys_unregister() does not check for NULL pointers gracefully.


(jruoho)
diff -r1.24 -r1.25 src/sys/dev/pci/arcmsr.c

cvs diff -r1.24 -r1.25 src/sys/dev/pci/arcmsr.c (expand / switch to unified diff)

--- src/sys/dev/pci/arcmsr.c 2010/04/03 14:19:17 1.24
+++ src/sys/dev/pci/arcmsr.c 2010/04/03 17:54:24 1.25
@@ -1,37 +1,37 @@ @@ -1,37 +1,37 @@
1/* $NetBSD: arcmsr.c,v 1.24 2010/04/03 14:19:17 pgoyette Exp $ */ 1/* $NetBSD: arcmsr.c,v 1.25 2010/04/03 17:54:24 jruoho Exp $ */
2/* $OpenBSD: arc.c,v 1.68 2007/10/27 03:28:27 dlg Exp $ */ 2/* $OpenBSD: arc.c,v 1.68 2007/10/27 03:28:27 dlg Exp $ */
3 3
4/* 4/*
5 * Copyright (c) 2007, 2008 Juan Romero Pardines <xtraeme@netbsd.org> 5 * Copyright (c) 2007, 2008 Juan Romero Pardines <xtraeme@netbsd.org>
6 * Copyright (c) 2006 David Gwynne <dlg@openbsd.org> 6 * Copyright (c) 2006 David Gwynne <dlg@openbsd.org>
7 * 7 *
8 * Permission to use, copy, modify, and distribute this software for any 8 * Permission to use, copy, modify, and distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above 9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies. 10 * copyright notice and this permission notice appear in all copies.
11 * 11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 */ 19 */
20 20
21#include "bio.h" 21#include "bio.h"
22 22
23#include <sys/cdefs.h> 23#include <sys/cdefs.h>
24__KERNEL_RCSID(0, "$NetBSD: arcmsr.c,v 1.24 2010/04/03 14:19:17 pgoyette Exp $"); 24__KERNEL_RCSID(0, "$NetBSD: arcmsr.c,v 1.25 2010/04/03 17:54:24 jruoho Exp $");
25 25
26#include <sys/param.h> 26#include <sys/param.h>
27#include <sys/buf.h> 27#include <sys/buf.h>
28#include <sys/kernel.h> 28#include <sys/kernel.h>
29#include <sys/malloc.h> 29#include <sys/malloc.h>
30#include <sys/device.h> 30#include <sys/device.h>
31#include <sys/kmem.h> 31#include <sys/kmem.h>
32#include <sys/kthread.h> 32#include <sys/kthread.h>
33#include <sys/mutex.h> 33#include <sys/mutex.h>
34#include <sys/condvar.h> 34#include <sys/condvar.h>
35#include <sys/rwlock.h> 35#include <sys/rwlock.h>
36 36
37#if NBIO > 0 37#if NBIO > 0
@@ -228,27 +228,29 @@ unmap_pci: @@ -228,27 +228,29 @@ unmap_pci:
228} 228}
229 229
230static int 230static int
231arc_detach(device_t self, int flags) 231arc_detach(device_t self, int flags)
232{ 232{
233 struct arc_softc *sc = device_private(self); 233 struct arc_softc *sc = device_private(self);
234 234
235 if (arc_msg0(sc, ARC_REG_INB_MSG0_STOP_BGRB) != 0) 235 if (arc_msg0(sc, ARC_REG_INB_MSG0_STOP_BGRB) != 0)
236 aprint_error_dev(self, "timeout waiting to stop bg rebuild\n");  236 aprint_error_dev(self, "timeout waiting to stop bg rebuild\n");
237 237
238 if (arc_msg0(sc, ARC_REG_INB_MSG0_FLUSH_CACHE) != 0) 238 if (arc_msg0(sc, ARC_REG_INB_MSG0_FLUSH_CACHE) != 0)
239 aprint_error_dev(self, "timeout waiting to flush cache\n"); 239 aprint_error_dev(self, "timeout waiting to flush cache\n");
240 240
241 sysmon_envsys_unregister(sc->sc_sme); 241 if (sc->sc_sme != NULL)
 242 sysmon_envsys_unregister(sc->sc_sme);
 243
242 return 0; 244 return 0;
243} 245}
244 246
245static bool 247static bool
246arc_shutdown(device_t self, int how) 248arc_shutdown(device_t self, int how)
247{ 249{
248 struct arc_softc *sc = device_private(self); 250 struct arc_softc *sc = device_private(self);
249 251
250 if (arc_msg0(sc, ARC_REG_INB_MSG0_STOP_BGRB) != 0) 252 if (arc_msg0(sc, ARC_REG_INB_MSG0_STOP_BGRB) != 0)
251 aprint_error_dev(self, "timeout waiting to stop bg rebuild\n"); 253 aprint_error_dev(self, "timeout waiting to stop bg rebuild\n");
252 254
253 if (arc_msg0(sc, ARC_REG_INB_MSG0_FLUSH_CACHE) != 0) 255 if (arc_msg0(sc, ARC_REG_INB_MSG0_FLUSH_CACHE) != 0)
254 aprint_error_dev(self, "timeout waiting to flush cache\n"); 256 aprint_error_dev(self, "timeout waiting to flush cache\n");
@@ -1795,28 +1797,32 @@ arc_create_sensors(void *arg) @@ -1795,28 +1797,32 @@ arc_create_sensors(void *arg)
1795 */ 1797 */
1796 sc->sc_sme->sme_name = device_xname(sc->sc_dev); 1798 sc->sc_sme->sme_name = device_xname(sc->sc_dev);
1797 sc->sc_sme->sme_cookie = sc; 1799 sc->sc_sme->sme_cookie = sc;
1798 sc->sc_sme->sme_refresh = arc_refresh_sensors; 1800 sc->sc_sme->sme_refresh = arc_refresh_sensors;
1799 1801
1800 if (sysmon_envsys_register(sc->sc_sme)) { 1802 if (sysmon_envsys_register(sc->sc_sme)) {
1801 aprint_debug("%s: unable to register with sysmon\n", 1803 aprint_debug("%s: unable to register with sysmon\n",
1802 device_xname(sc->sc_dev)); 1804 device_xname(sc->sc_dev));
1803 goto bad; 1805 goto bad;
1804 } 1806 }
1805 kthread_exit(0); 1807 kthread_exit(0);
1806 1808
1807bad: 1809bad:
1808 kmem_free(sc->sc_sensors, slen); 
1809 sysmon_envsys_destroy(sc->sc_sme); 1810 sysmon_envsys_destroy(sc->sc_sme);
 1811 kmem_free(sc->sc_sensors, slen);
 1812
 1813 sc->sc_sme = NULL;
 1814 sc->sc_sensors = NULL;
 1815
1810 kthread_exit(0); 1816 kthread_exit(0);
1811} 1817}
1812 1818
1813static void 1819static void
1814arc_refresh_sensors(struct sysmon_envsys *sme, envsys_data_t *edata) 1820arc_refresh_sensors(struct sysmon_envsys *sme, envsys_data_t *edata)
1815{ 1821{
1816 struct arc_softc *sc = sme->sme_cookie; 1822 struct arc_softc *sc = sme->sme_cookie;
1817 struct bioc_vol bv; 1823 struct bioc_vol bv;
1818 struct bioc_disk bd; 1824 struct bioc_disk bd;
1819 1825
1820 /* sanity check */ 1826 /* sanity check */
1821 if (edata->units != ENVSYS_DRIVE) 1827 if (edata->units != ENVSYS_DRIVE)
1822 return; 1828 return;