diff options
Diffstat (limited to 'bsd-core/drm_auth.c')
-rw-r--r-- | bsd-core/drm_auth.c | 17 |
1 files changed, 6 insertions, 11 deletions
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); |