Fix a locking nit, and add asserts in some things that should be called
authorEric Anholt <anholt@freebsd.org>
Wed, 12 Nov 2003 20:30:51 +0000 (20:30 +0000)
committerEric Anholt <anholt@freebsd.org>
Wed, 12 Nov 2003 20:30:51 +0000 (20:30 +0000)
    with locks held.

bsd-core/drm_bufs.c
bsd-core/drm_drv.c
bsd-core/drm_fops.c
bsd-core/drm_os_freebsd.h
bsd/drm_bufs.h
bsd/drm_drv.h
bsd/drm_fops.h
bsd/drm_os_freebsd.h

index 0915da8..15d4a3b 100644 (file)
@@ -145,8 +145,8 @@ int DRM(addmap)( DRM_IOCTL_ARGS )
                                DRM(free)(map, sizeof(*map), DRM_MEM_MAPS);
                                return DRM_ERR(EBUSY);
                        }
-                       DRM_UNLOCK();
                        dev->lock.hw_lock = map->handle; /* Pointer to lock */
+                       DRM_UNLOCK();
                }
                break;
 #if __REALLY_HAVE_AGP
index 1083f9f..bf1e2ac 100644 (file)
@@ -417,11 +417,13 @@ const char *DRM(find_description)(int vendor, int device) {
        return NULL;
 }
 
-/* Initialize the DRM on first open.  Called with device's lock held */
+/* Initialize the DRM on first open. */
 static int DRM(setup)( drm_device_t *dev )
 {
        int i;
 
+       DRM_SPINLOCK_ASSERT(&dev->dev_lock);
+
        DRIVER_PRESETUP();
        dev->buf_use = 0;
 
@@ -496,9 +498,7 @@ static int DRM(setup)( drm_device_t *dev )
        return 0;
 }
 
-/* Free resources associated with the DRM on the last close.
- * Called with the device's lock held.
- */
+/* Free resources associated with the DRM on the last close. */
 static int DRM(takedown)( drm_device_t *dev )
 {
        drm_magic_entry_t *pt, *next;
@@ -506,6 +506,8 @@ static int DRM(takedown)( drm_device_t *dev )
        drm_map_list_entry_t *list;
        int i;
 
+       DRM_SPINLOCK_ASSERT(&dev->dev_lock);
+
        DRM_DEBUG( "\n" );
 
        DRIVER_PRETAKEDOWN();
index 55ef8ce..e9c5d7a 100644 (file)
@@ -33,7 +33,6 @@
 
 #include "drmP.h"
 
-/* Requires device lock held */
 drm_file_t *DRM(find_file_by_proc)(drm_device_t *dev, DRM_STRUCTPROC *p)
 {
 #if __FreeBSD_version >= 500021
@@ -45,6 +44,8 @@ drm_file_t *DRM(find_file_by_proc)(drm_device_t *dev, DRM_STRUCTPROC *p)
 #endif
        drm_file_t *priv;
 
+       DRM_SPINLOCK_ASSERT(&dev->dev_lock);
+
        TAILQ_FOREACH(priv, &dev->files, link)
                if (priv->pid == pid && priv->uid == uid)
                        return priv;
@@ -65,7 +66,7 @@ int DRM(open_helper)(dev_t kdev, int flags, int fmt, DRM_STRUCTPROC *p,
        DRM_DEBUG("pid = %d, minor = %d\n", DRM_CURRENTPID, m);
 
        DRM_LOCK();
-       priv = (drm_file_t *) DRM(find_file_by_proc)(dev, p);
+       priv = DRM(find_file_by_proc)(dev, p);
        if (priv) {
                priv->refs++;
        } else {
index 00a4402..31379b6 100644 (file)
 #define DRM_SPINUNINIT(l)      mtx_destroy(&l)
 #define DRM_SPINLOCK(l)                mtx_lock(l)
 #define DRM_SPINUNLOCK(u)      mtx_unlock(u);
+#define DRM_SPINLOCK_ASSERT(l) mtx_assert(l, MA_OWNED)
 #define DRM_CURRENTPID         curthread->td_proc->p_pid
 #define DRM_LOCK()             mtx_lock(&dev->dev_lock)
 #define DRM_UNLOCK()           mtx_unlock(&dev->dev_lock)
 #define DRM_SPINUNINIT(l)
 #define DRM_SPINLOCK(l)
 #define DRM_SPINUNLOCK(u)
+#define DRM_SPINLOCK_ASSERT(l)
 #define DRM_CURRENTPID         curproc->p_pid
 #define DRM_LOCK()
 #define DRM_UNLOCK()
index 0915da8..15d4a3b 100644 (file)
@@ -145,8 +145,8 @@ int DRM(addmap)( DRM_IOCTL_ARGS )
                                DRM(free)(map, sizeof(*map), DRM_MEM_MAPS);
                                return DRM_ERR(EBUSY);
                        }
-                       DRM_UNLOCK();
                        dev->lock.hw_lock = map->handle; /* Pointer to lock */
+                       DRM_UNLOCK();
                }
                break;
 #if __REALLY_HAVE_AGP
index 1083f9f..bf1e2ac 100644 (file)
@@ -417,11 +417,13 @@ const char *DRM(find_description)(int vendor, int device) {
        return NULL;
 }
 
-/* Initialize the DRM on first open.  Called with device's lock held */
+/* Initialize the DRM on first open. */
 static int DRM(setup)( drm_device_t *dev )
 {
        int i;
 
+       DRM_SPINLOCK_ASSERT(&dev->dev_lock);
+
        DRIVER_PRESETUP();
        dev->buf_use = 0;
 
@@ -496,9 +498,7 @@ static int DRM(setup)( drm_device_t *dev )
        return 0;
 }
 
-/* Free resources associated with the DRM on the last close.
- * Called with the device's lock held.
- */
+/* Free resources associated with the DRM on the last close. */
 static int DRM(takedown)( drm_device_t *dev )
 {
        drm_magic_entry_t *pt, *next;
@@ -506,6 +506,8 @@ static int DRM(takedown)( drm_device_t *dev )
        drm_map_list_entry_t *list;
        int i;
 
+       DRM_SPINLOCK_ASSERT(&dev->dev_lock);
+
        DRM_DEBUG( "\n" );
 
        DRIVER_PRETAKEDOWN();
index 55ef8ce..e9c5d7a 100644 (file)
@@ -33,7 +33,6 @@
 
 #include "drmP.h"
 
-/* Requires device lock held */
 drm_file_t *DRM(find_file_by_proc)(drm_device_t *dev, DRM_STRUCTPROC *p)
 {
 #if __FreeBSD_version >= 500021
@@ -45,6 +44,8 @@ drm_file_t *DRM(find_file_by_proc)(drm_device_t *dev, DRM_STRUCTPROC *p)
 #endif
        drm_file_t *priv;
 
+       DRM_SPINLOCK_ASSERT(&dev->dev_lock);
+
        TAILQ_FOREACH(priv, &dev->files, link)
                if (priv->pid == pid && priv->uid == uid)
                        return priv;
@@ -65,7 +66,7 @@ int DRM(open_helper)(dev_t kdev, int flags, int fmt, DRM_STRUCTPROC *p,
        DRM_DEBUG("pid = %d, minor = %d\n", DRM_CURRENTPID, m);
 
        DRM_LOCK();
-       priv = (drm_file_t *) DRM(find_file_by_proc)(dev, p);
+       priv = DRM(find_file_by_proc)(dev, p);
        if (priv) {
                priv->refs++;
        } else {
index 00a4402..31379b6 100644 (file)
 #define DRM_SPINUNINIT(l)      mtx_destroy(&l)
 #define DRM_SPINLOCK(l)                mtx_lock(l)
 #define DRM_SPINUNLOCK(u)      mtx_unlock(u);
+#define DRM_SPINLOCK_ASSERT(l) mtx_assert(l, MA_OWNED)
 #define DRM_CURRENTPID         curthread->td_proc->p_pid
 #define DRM_LOCK()             mtx_lock(&dev->dev_lock)
 #define DRM_UNLOCK()           mtx_unlock(&dev->dev_lock)
 #define DRM_SPINUNINIT(l)
 #define DRM_SPINLOCK(l)
 #define DRM_SPINUNLOCK(u)
+#define DRM_SPINLOCK_ASSERT(l)
 #define DRM_CURRENTPID         curproc->p_pid
 #define DRM_LOCK()
 #define DRM_UNLOCK()