Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/sysmon When unregistering a sensor device, make sure...



details:   https://anonhg.NetBSD.org/src/rev/528ccadcc21d
branches:  trunk
changeset: 780206:528ccadcc21d
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Sun Jul 15 17:41:39 2012 +0000

description:
When unregistering a sensor device, make sure we unregister and delete
all the associated events.

diffstat:

 sys/dev/sysmon/sysmon_envsys.c        |   5 +-
 sys/dev/sysmon/sysmon_envsys_events.c |  64 +++++++++++++++++++++++++++++++---
 sys/dev/sysmon/sysmon_envsysvar.h     |   3 +-
 3 files changed, 63 insertions(+), 9 deletions(-)

diffs (154 lines):

diff -r 54823e225182 -r 528ccadcc21d sys/dev/sysmon/sysmon_envsys.c
--- a/sys/dev/sysmon/sysmon_envsys.c    Sun Jul 15 15:49:46 2012 +0000
+++ b/sys/dev/sysmon/sysmon_envsys.c    Sun Jul 15 17:41:39 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sysmon_envsys.c,v 1.118 2012/02/18 01:08:00 matt Exp $ */
+/*     $NetBSD: sysmon_envsys.c,v 1.119 2012/07/15 17:41:39 pgoyette Exp $     */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.118 2012/02/18 01:08:00 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.119 2012/07/15 17:41:39 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -604,6 +604,7 @@
        /*
         * remove it and decrement the sensors count.
         */
+       sme_event_unregister_sensor(sme, edata);
        TAILQ_REMOVE(&sme->sme_sensors_list, edata, sensors_head);
        sme->sme_nsensors--;
        sysmon_envsys_release(sme, true);
diff -r 54823e225182 -r 528ccadcc21d sys/dev/sysmon/sysmon_envsys_events.c
--- a/sys/dev/sysmon/sysmon_envsys_events.c     Sun Jul 15 15:49:46 2012 +0000
+++ b/sys/dev/sysmon/sysmon_envsys_events.c     Sun Jul 15 17:41:39 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.98 2011/06/08 16:14:57 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.99 2012/07/15 17:41:39 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.98 2011/06/08 16:14:57 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.99 2012/07/15 17:41:39 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -77,6 +77,8 @@
 static bool sme_battery_critical(envsys_data_t *);
 static bool sme_acadapter_check(void);
 
+static void sme_remove_event(sme_event_t *, struct sysmon_envsys *);
+
 /*
  * sme_event_register:
  *
@@ -334,11 +336,11 @@
                        break;
 
                if (strcmp(see->see_pes.pes_dvname, sme->sme_name) == 0) {
-                       LIST_REMOVE(see, see_list);
                        DPRINTF(("%s: event %s %d removed (%s)\n", __func__,
                            see->see_pes.pes_sensname, see->see_type,
                            sme->sme_name));
-                       kmem_free(see, sizeof(*see));
+                       sme_remove_event(see, sme);
+
                        evcounter--;
                }
        }
@@ -386,6 +388,58 @@
 
        DPRINTF(("%s: removed dev=%s sensor=%s type=%d\n",
            __func__, see->see_pes.pes_dvname, sensor, type));
+
+       sme_remove_event(see, sme);
+
+       mutex_exit(&sme->sme_mtx);
+       return 0;
+}
+
+/*
+ * sme_event_unregister_sensor:
+ *
+ *     + Unregisters any event associated with a specific sensor
+ *       The caller must already own the sme_mtx.
+ */
+int
+sme_event_unregister_sensor(struct sysmon_envsys *sme, envsys_data_t *edata)
+{
+       sme_event_t *see;
+       bool found = false;
+
+       KASSERT(mutex_owned(&sme->sme_mtx));
+       LIST_FOREACH(see, &sme->sme_events_list, see_list) {
+               if (see->see_edata == edata) {
+                       found = true;
+                       break;
+               }
+       }
+       if (!found)
+               return EINVAL;
+
+       /*
+        * Wait for the event to finish its work, remove from the list
+        * and release resouces.
+        */
+       while (see->see_flags & SEE_EVENT_WORKING)
+               cv_wait(&sme->sme_condvar, &sme->sme_mtx);
+
+       DPRINTF(("%s: removed dev=%s sensor=%s\n",
+           __func__, see->see_pes.pes_dvname, edata->desc));
+
+       sme_remove_event(see, sme);
+
+       return 0;
+}
+
+static void
+sme_remove_event(sme_event_t *see, struct sysmon_envsys *sme)
+{
+
+       KASSERT(mutex_owned(&sme->sme_mtx));
+
+       if (see->see_edata->flags & ENVSYS_FHAS_ENTROPY)
+               rnd_detach_source(&see->see_edata->rnd_src);
        LIST_REMOVE(see, see_list);
        /*
         * So the events list is empty, we'll do the following:
@@ -395,10 +449,8 @@
         */
        if (LIST_EMPTY(&sme->sme_events_list))
                sme_events_destroy(sme);
-       mutex_exit(&sme->sme_mtx);
 
        kmem_free(see, sizeof(*see));
-       return 0;
 }
 
 /*
diff -r 54823e225182 -r 528ccadcc21d sys/dev/sysmon/sysmon_envsysvar.h
--- a/sys/dev/sysmon/sysmon_envsysvar.h Sun Jul 15 15:49:46 2012 +0000
+++ b/sys/dev/sysmon/sysmon_envsysvar.h Sun Jul 15 17:41:39 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsysvar.h,v 1.41 2012/02/18 01:08:00 matt Exp $ */
+/* $NetBSD: sysmon_envsysvar.h,v 1.42 2012/07/15 17:41:39 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -127,6 +127,7 @@
                           struct sysmon_envsys *, sysmon_envsys_lim_t *,
                           uint32_t, int, int);
 int    sme_event_unregister(struct sysmon_envsys *, const char *, int);
+int    sme_event_unregister_sensor(struct sysmon_envsys *, envsys_data_t *);
 void   sme_event_unregister_all(struct sysmon_envsys *);
 void   sme_event_drvadd(void *);
 int    sme_events_init(struct sysmon_envsys *);



Home | Main Index | Thread Index | Old Index