diff options
author | Eric Anholt <anholt@freebsd.org> | 2003-02-08 03:22:28 +0000 |
---|---|---|
committer | Eric Anholt <anholt@freebsd.org> | 2003-02-08 03:22:28 +0000 |
commit | 6e37c2064796742b9a2f56aae99fe32f8f160a30 (patch) | |
tree | d2af074439166e1eb7d8159021e90406a097587b | |
parent | 6f79735e8a9dc8ae13e6c336c6bd96f43214e011 (diff) |
Unitialize mutexes on cleanup, fixes panics on 5.0 with WITNESS.
-rw-r--r-- | bsd-core/drmP.h | 1 | ||||
-rw-r--r-- | bsd-core/drm_auth.c | 17 | ||||
-rw-r--r-- | bsd-core/drm_drv.c | 2 | ||||
-rw-r--r-- | bsd-core/drm_memory.c | 5 | ||||
-rw-r--r-- | bsd-core/drm_os_freebsd.h | 2 | ||||
-rw-r--r-- | bsd-core/drm_os_netbsd.h | 7 | ||||
-rw-r--r-- | bsd/drmP.h | 1 | ||||
-rw-r--r-- | bsd/drm_auth.h | 17 | ||||
-rw-r--r-- | bsd/drm_drv.h | 2 | ||||
-rw-r--r-- | bsd/drm_lists.h | 5 | ||||
-rw-r--r-- | bsd/drm_memory.h | 5 | ||||
-rw-r--r-- | bsd/drm_os_freebsd.h | 2 | ||||
-rw-r--r-- | bsd/drm_os_netbsd.h | 7 |
13 files changed, 44 insertions, 29 deletions
diff --git a/bsd-core/drmP.h b/bsd-core/drmP.h index 00c1a9ea..4c6f5085 100644 --- a/bsd-core/drmP.h +++ b/bsd-core/drmP.h @@ -520,6 +520,7 @@ extern int DRM(write_string)(drm_device_t *dev, const char *s); /* Memory management support (drm_memory.h) */ extern void DRM(mem_init)(void); +extern void DRM(mem_uninit)(void); extern void *DRM(alloc)(size_t size, int area); extern void *DRM(realloc)(void *oldpt, size_t oldsize, size_t size, int area); diff --git a/bsd-core/drm_auth.c b/bsd-core/drm_auth.c index 0b411d14..a03cc918 100644 --- a/bsd-core/drm_auth.c +++ b/bsd-core/drm_auth.c @@ -116,25 +116,20 @@ int DRM(getmagic)(DRM_IOCTL_ARGS) { static drm_magic_t sequence = 0; drm_auth_t auth; - static DRM_SPINTYPE lock; - static int first = 1; DRM_DEVICE; DRM_PRIV; - if (first) { - DRM_SPININIT(lock, "drm getmagic"); - first = 0; - } - /* Find unique magic */ if (priv->magic) { auth.magic = priv->magic; } else { do { - DRM_SPINLOCK(&lock); - if (!sequence) ++sequence; /* reserve 0 */ - auth.magic = sequence++; - DRM_SPINUNLOCK(&lock); + int old = sequence; + + auth.magic = old+1; + + if (!atomic_cmpset_int(&sequence, old, auth.magic)) + continue; } while (DRM(find_file)(dev, auth.magic)); priv->magic = auth.magic; DRM(add_magic)(dev, priv, auth.magic); diff --git a/bsd-core/drm_drv.c b/bsd-core/drm_drv.c index 4a6fc15f..2fdc1796 100644 --- a/bsd-core/drm_drv.c +++ b/bsd-core/drm_drv.c @@ -814,6 +814,8 @@ static void DRM(cleanup)(drm_device_t *dev) } #endif DRIVER_POSTCLEANUP(); + DRM(mem_uninit)(); + DRM_SPINUNINIT(dev->count_lock); } diff --git a/bsd-core/drm_memory.c b/bsd-core/drm_memory.c index f7dc547a..a4e74d9f 100644 --- a/bsd-core/drm_memory.c +++ b/bsd-core/drm_memory.c @@ -95,6 +95,11 @@ void DRM(mem_init)(void) DRM(ram_used) = 0; } +void DRM(mem_uninit)(void) +{ + DRM_SPINUNINIT(DRM(mem_lock)); +} + #ifdef __FreeBSD__ /* drm_mem_info is called whenever a process reads /dev/drm/mem. */ static int DRM(_mem_info) DRM_SYSCTL_HANDLER_ARGS diff --git a/bsd-core/drm_os_freebsd.h b/bsd-core/drm_os_freebsd.h index 730d66f4..1d8ae681 100644 --- a/bsd-core/drm_os_freebsd.h +++ b/bsd-core/drm_os_freebsd.h @@ -79,6 +79,7 @@ #define DRM_STRUCTPROC struct thread #define DRM_SPINTYPE struct mtx #define DRM_SPININIT(l,name) mtx_init(&l, name, NULL, MTX_DEF) +#define DRM_SPINUNINIT(l) mtx_destroy(&l) #define DRM_SPINLOCK(l) mtx_lock(l) #define DRM_SPINUNLOCK(u) mtx_unlock(u); #define DRM_CURRENTPID curthread->td_proc->p_pid @@ -87,6 +88,7 @@ #define DRM_STRUCTPROC struct proc #define DRM_SPINTYPE struct simplelock #define DRM_SPININIT(l,name) simple_lock_init(&l) +#define DRM_SPINUNINIT(l,name) #define DRM_SPINLOCK(l) simple_lock(l) #define DRM_SPINUNLOCK(u) simple_unlock(u); #define DRM_CURRENTPID curproc->p_pid diff --git a/bsd-core/drm_os_netbsd.h b/bsd-core/drm_os_netbsd.h index 2082c047..605b6a2c 100644 --- a/bsd-core/drm_os_netbsd.h +++ b/bsd-core/drm_os_netbsd.h @@ -60,12 +60,13 @@ extern struct cfdriver DRM(_cd); #define CDEV_MAJOR 90 #define DRM_CURPROC curproc -#define DRM_STRUCTPROC struct proc +#define DRM_STRUCTPROC struct proc #define DRM_SPINTYPE struct simplelock #define DRM_SPININIT(l,name) simple_lock_init(&l) -#define DRM_SPINLOCK(l) simple_lock(l) +#define DRM_SPINUNINIT(l) +#define DRM_SPINLOCK(l) simple_lock(l) #define DRM_SPINUNLOCK(u) simple_unlock(u); -#define DRM_CURRENTPID curproc->p_pid +#define DRM_CURRENTPID curproc->p_pid #define DRM_IOCTL_ARGS dev_t kdev, u_long cmd, caddr_t data, int flags, DRM_STRUCTPROC *p #define DRM_LOCK lockmgr(&dev->dev_lock, LK_EXCLUSIVE, NULL) @@ -520,6 +520,7 @@ extern int DRM(write_string)(drm_device_t *dev, const char *s); /* Memory management support (drm_memory.h) */ extern void DRM(mem_init)(void); +extern void DRM(mem_uninit)(void); extern void *DRM(alloc)(size_t size, int area); extern void *DRM(realloc)(void *oldpt, size_t oldsize, size_t size, int area); diff --git a/bsd/drm_auth.h b/bsd/drm_auth.h index 0b411d14..a03cc918 100644 --- a/bsd/drm_auth.h +++ b/bsd/drm_auth.h @@ -116,25 +116,20 @@ int DRM(getmagic)(DRM_IOCTL_ARGS) { static drm_magic_t sequence = 0; drm_auth_t auth; - static DRM_SPINTYPE lock; - static int first = 1; DRM_DEVICE; DRM_PRIV; - if (first) { - DRM_SPININIT(lock, "drm getmagic"); - first = 0; - } - /* Find unique magic */ if (priv->magic) { auth.magic = priv->magic; } else { do { - DRM_SPINLOCK(&lock); - if (!sequence) ++sequence; /* reserve 0 */ - auth.magic = sequence++; - DRM_SPINUNLOCK(&lock); + int old = sequence; + + auth.magic = old+1; + + if (!atomic_cmpset_int(&sequence, old, auth.magic)) + continue; } while (DRM(find_file)(dev, auth.magic)); priv->magic = auth.magic; DRM(add_magic)(dev, priv, auth.magic); diff --git a/bsd/drm_drv.h b/bsd/drm_drv.h index 4a6fc15f..2fdc1796 100644 --- a/bsd/drm_drv.h +++ b/bsd/drm_drv.h @@ -814,6 +814,8 @@ static void DRM(cleanup)(drm_device_t *dev) } #endif DRIVER_POSTCLEANUP(); + DRM(mem_uninit)(); + DRM_SPINUNINIT(dev->count_lock); } diff --git a/bsd/drm_lists.h b/bsd/drm_lists.h index 1ab55f90..198ee7ee 100644 --- a/bsd/drm_lists.h +++ b/bsd/drm_lists.h @@ -43,7 +43,7 @@ int DRM(waitlist_create)(drm_waitlist_t *bl, int count) if(!bl->bufs) return DRM_ERR(ENOMEM); - memset(bl->bufs, 0, sizeof(*bl->bufs)); + bzero(bl->bufs, sizeof(*bl->bufs)); bl->count = count; bl->rp = bl->bufs; @@ -66,6 +66,8 @@ int DRM(waitlist_destroy)(drm_waitlist_t *bl) bl->rp = NULL; bl->wp = NULL; bl->end = NULL; + DRM_SPINUNINIT( bl->write_lock ); + DRM_SPINUNINIT( bl->read_lock ); return 0; } @@ -137,6 +139,7 @@ int DRM(freelist_destroy)(drm_freelist_t *bl) { atomic_set(&bl->count, 0); bl->next = NULL; + DRM_SPINUNINIT( bl->lock ); return 0; } diff --git a/bsd/drm_memory.h b/bsd/drm_memory.h index f7dc547a..a4e74d9f 100644 --- a/bsd/drm_memory.h +++ b/bsd/drm_memory.h @@ -95,6 +95,11 @@ void DRM(mem_init)(void) DRM(ram_used) = 0; } +void DRM(mem_uninit)(void) +{ + DRM_SPINUNINIT(DRM(mem_lock)); +} + #ifdef __FreeBSD__ /* drm_mem_info is called whenever a process reads /dev/drm/mem. */ static int DRM(_mem_info) DRM_SYSCTL_HANDLER_ARGS diff --git a/bsd/drm_os_freebsd.h b/bsd/drm_os_freebsd.h index 730d66f4..1d8ae681 100644 --- a/bsd/drm_os_freebsd.h +++ b/bsd/drm_os_freebsd.h @@ -79,6 +79,7 @@ #define DRM_STRUCTPROC struct thread #define DRM_SPINTYPE struct mtx #define DRM_SPININIT(l,name) mtx_init(&l, name, NULL, MTX_DEF) +#define DRM_SPINUNINIT(l) mtx_destroy(&l) #define DRM_SPINLOCK(l) mtx_lock(l) #define DRM_SPINUNLOCK(u) mtx_unlock(u); #define DRM_CURRENTPID curthread->td_proc->p_pid @@ -87,6 +88,7 @@ #define DRM_STRUCTPROC struct proc #define DRM_SPINTYPE struct simplelock #define DRM_SPININIT(l,name) simple_lock_init(&l) +#define DRM_SPINUNINIT(l,name) #define DRM_SPINLOCK(l) simple_lock(l) #define DRM_SPINUNLOCK(u) simple_unlock(u); #define DRM_CURRENTPID curproc->p_pid diff --git a/bsd/drm_os_netbsd.h b/bsd/drm_os_netbsd.h index 2082c047..605b6a2c 100644 --- a/bsd/drm_os_netbsd.h +++ b/bsd/drm_os_netbsd.h @@ -60,12 +60,13 @@ extern struct cfdriver DRM(_cd); #define CDEV_MAJOR 90 #define DRM_CURPROC curproc -#define DRM_STRUCTPROC struct proc +#define DRM_STRUCTPROC struct proc #define DRM_SPINTYPE struct simplelock #define DRM_SPININIT(l,name) simple_lock_init(&l) -#define DRM_SPINLOCK(l) simple_lock(l) +#define DRM_SPINUNINIT(l) +#define DRM_SPINLOCK(l) simple_lock(l) #define DRM_SPINUNLOCK(u) simple_unlock(u); -#define DRM_CURRENTPID curproc->p_pid +#define DRM_CURRENTPID curproc->p_pid #define DRM_IOCTL_ARGS dev_t kdev, u_long cmd, caddr_t data, int flags, DRM_STRUCTPROC *p #define DRM_LOCK lockmgr(&dev->dev_lock, LK_EXCLUSIVE, NULL) |