From bd7fea75f5e9707a40449b21f1a1411132359c03 Mon Sep 17 00:00:00 2001 From: oga Date: Wed, 13 Aug 2008 19:33:29 +0000 Subject: [PATCH] Generate the magic id using idgen32(). While i'm here fix the locking a bit so we don't sleep with a spinlock. ok djm@. --- sys/dev/pci/drm/drmP.h | 2 ++ sys/dev/pci/drm/drm_auth.c | 17 ++++++++--------- sys/dev/pci/drm/drm_drv.c | 1 + 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/sys/dev/pci/drm/drmP.h b/sys/dev/pci/drm/drmP.h index 66766471048..5529ce22b85 100644 --- a/sys/dev/pci/drm/drmP.h +++ b/sys/dev/pci/drm/drmP.h @@ -66,6 +66,7 @@ #include #include #include +#include #include "drm.h" #include "drm_linux_list.h" @@ -634,6 +635,7 @@ struct drm_device { /* Authentication */ drm_file_list_t files; + struct idgen32_ctx magicid; SPLAY_HEAD(drm_magic_tree, drm_magic_entry) magiclist; /* Linked list of mappable regions. Protected by dev_lock */ diff --git a/sys/dev/pci/drm/drm_auth.c b/sys/dev/pci/drm/drm_auth.c index 02568d915cd..4b1e20ca92d 100644 --- a/sys/dev/pci/drm/drm_auth.c +++ b/sys/dev/pci/drm/drm_auth.c @@ -70,7 +70,10 @@ drm_add_magic(struct drm_device *dev, struct drm_file *priv, drm_magic_t magic) DRM_SPINLOCK_ASSERT(&dev->dev_lock); - if ((entry = drm_alloc(sizeof(*entry), DRM_MEM_MAGIC)) == NULL) + DRM_UNLOCK(); + entry = drm_alloc(sizeof(*entry), DRM_MEM_MAGIC); + DRM_LOCK(); + if (entry == NULL) return (ENOMEM); entry->magic = magic; entry->priv = priv; @@ -97,7 +100,9 @@ drm_remove_magic(struct drm_device *dev, drm_magic_t magic) if ((pt = SPLAY_FIND(drm_magic_tree, &dev->magiclist, &key)) == NULL) return (EINVAL); SPLAY_REMOVE(drm_magic_tree, &dev->magiclist, pt); + DRM_UNLOCK(); drm_free(pt, sizeof(*pt), DRM_MEM_MAGIC); + DRM_LOCK(); return (0); } @@ -112,8 +117,7 @@ drm_remove_magic(struct drm_device *dev, drm_magic_t magic) int drm_getmagic(struct drm_device *dev, void *data, struct drm_file *file_priv) { - static drm_magic_t sequence = 0; - drm_auth_t *auth = data; + drm_auth_t *auth = data; /* Find unique magic */ if (file_priv->magic) { @@ -121,12 +125,7 @@ drm_getmagic(struct drm_device *dev, void *data, struct drm_file *file_priv) } else { DRM_LOCK(); do { - int old = sequence; - - auth->magic = ++old; - - if (!atomic_cmpset_int(&sequence, old, auth->magic)) - continue; + auth->magic = idgen32(&dev->magicid); } while (drm_find_file(dev, auth->magic)); file_priv->magic = auth->magic; diff --git a/sys/dev/pci/drm/drm_drv.c b/sys/dev/pci/drm/drm_drv.c index 88fc5316ed8..f5b201e32e1 100644 --- a/sys/dev/pci/drm/drm_drv.c +++ b/sys/dev/pci/drm/drm_drv.c @@ -253,6 +253,7 @@ drm_firstopen(struct drm_device *dev) for ( i = 0 ; i < DRM_ARRAY_SIZE(dev->counts) ; i++ ) atomic_set( &dev->counts[i], 0 ); + idgen32_init(&dev->magicid); SPLAY_INIT(&dev->magiclist); dev->lock.lock_queue = 0; -- 2.20.1