diff options
author | Owain Ainsworth <oga@cvs.openbsd.org> | 2008-08-13 19:33:30 +0000 |
---|---|---|
committer | Owain Ainsworth <oga@cvs.openbsd.org> | 2008-08-13 19:33:30 +0000 |
commit | 374ec5ab0b2b7aed2e7475d6e513e01a52625bb5 (patch) | |
tree | 2e9ac29a0f16f700e9da82bb6b3012101de37e7d /sys/dev/pci/drm/drm_auth.c | |
parent | 075f6e881e3d8ef1efe4d1b70a1ff9f0eec77db2 (diff) |
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@.
Diffstat (limited to 'sys/dev/pci/drm/drm_auth.c')
-rw-r--r-- | sys/dev/pci/drm/drm_auth.c | 17 |
1 files changed, 8 insertions, 9 deletions
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; |