From c0368d5441d90c6a2ac0583d7d2144c6d6baab8c Mon Sep 17 00:00:00 2001 From: Ben Skeggs Date: Sun, 10 Aug 2014 04:10:21 +1000 Subject: lib: silence some issues reported by valgrind --- bin/nv_rdfunc.h | 1 + lib/intr.c | 40 ++++++++++++++++++++++------------------ lib/main.c | 10 +++++++--- lib/priv.h | 3 --- 4 files changed, 30 insertions(+), 24 deletions(-) diff --git a/bin/nv_rdfunc.h b/bin/nv_rdfunc.h index 5ace077bd..d840ddd3e 100644 --- a/bin/nv_rdfunc.h +++ b/bin/nv_rdfunc.h @@ -139,5 +139,6 @@ main(int argc, char **argv) return 1; } + free(data); return 0; } diff --git a/lib/intr.c b/lib/intr.c index 5563c372b..fee9c5b2b 100644 --- a/lib/intr.c +++ b/lib/intr.c @@ -26,15 +26,27 @@ #include #include "priv.h" -pthread_t os_intr_thread; struct os_intr { struct list_head head; + pthread_t thread; irq_handler_t handler; int irq; void *dev; }; +static DEFINE_MUTEX(os_intr_mutex); static LIST_HEAD(os_intr_list); +static void * +os_intr(void *arg) +{ + struct os_intr *intr = arg; + while (1) { + intr->handler(intr->irq, intr->dev); + usleep(10000); + } + return NULL; +} + int os_intr_init(unsigned int irq, irq_handler_t handler, unsigned long flags, const char *name, void *dev) @@ -45,7 +57,10 @@ os_intr_init(unsigned int irq, irq_handler_t handler, unsigned long flags, intr->handler = handler; intr->irq = irq; intr->dev = dev; + mutex_lock(&os_intr_mutex); list_add(&intr->head, &os_intr_list); + mutex_unlock(&os_intr_mutex); + pthread_create(&intr->thread, NULL, os_intr, intr); return 0; } @@ -54,27 +69,16 @@ os_intr_free(unsigned int irq, void *dev) { struct os_intr *intr; + mutex_lock(&os_intr_mutex); list_for_each_entry(intr, &os_intr_list, head) { if (intr->irq == irq && intr->dev == dev) { + pthread_cancel(intr->thread); + pthread_join(intr->thread, NULL); list_del(&intr->head); + mutex_unlock(&os_intr_mutex); free(intr); - break; + return; } } -} - -void * -os_intr(void *arg) -{ - struct os_intr *intr; - - while (1) { - list_for_each_entry(intr, &os_intr_list, head) { - intr->handler(intr->irq, intr->dev); - } - - usleep(10000); - } - - return NULL; + mutex_unlock(&os_intr_mutex); } diff --git a/lib/main.c b/lib/main.c index c82d21408..0c62049bd 100644 --- a/lib/main.c +++ b/lib/main.c @@ -205,8 +205,8 @@ os_init(char *cfg, char *dbg, bool init) os_init_device(pdev, handle, cfg, dbg); } - - return pthread_create(&os_intr_thread, NULL, os_intr, NULL); + pci_iterator_destroy(iter); + return 0; } static void @@ -215,13 +215,17 @@ os_fini(void) struct os_device *odev, *temp; list_for_each_entry_safe(odev, temp, &os_device_list, head) { + struct pci_dev *ldev = odev->base.pdev; char *name = odev->name; char *cfg = odev->cfg; char *dbg = odev->dbg; list_del(&odev->head); nouveau_object_ref(NULL, (struct nouveau_object **)&odev); - free(dbg); free(cfg); free(name); + free(dbg); free(cfg); free(name); free(ldev); } + + nouveau_object_debug(); + pci_system_cleanup(); } int diff --git a/lib/priv.h b/lib/priv.h index f6d7bfd4b..161e23dd3 100644 --- a/lib/priv.h +++ b/lib/priv.h @@ -20,7 +20,4 @@ struct os_client { struct list_head head; }; -extern pthread_t os_intr_thread; -void *os_intr(void *arg); - #endif -- cgit v1.2.1