]> www.infradead.org Git - users/willy/xarray.git/commitdiff
drm: Convert magic_map to XArray
authorMatthew Wilcox <willy@infradead.org>
Wed, 13 Feb 2019 14:39:17 +0000 (09:39 -0500)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Thu, 8 Aug 2019 03:39:30 +0000 (23:39 -0400)
Part of the mass conversion of IDR users to the XArray API.

Signed-off-by: Matthew Wilcox <willy@infradead.org>
drivers/gpu/drm/drm_auth.c
include/drm/drm_auth.h

index cc9acd986c68f68c79add713e4b7dfd66a967b35..89e72ff32b629c1968f48e97895df2a48ae0627e 100644 (file)
@@ -68,17 +68,16 @@ int drm_getmagic(struct drm_device *dev, void *data, struct drm_file *file_priv)
 
        mutex_lock(&dev->master_mutex);
        if (!file_priv->magic) {
-               ret = idr_alloc(&file_priv->master->magic_map, file_priv,
-                               1, 0, GFP_KERNEL);
-               if (ret >= 0)
-                       file_priv->magic = ret;
+               ret = xa_alloc(&file_priv->master->magic_map,
+                               &file_priv->magic, file_priv,
+                               xa_limit_31b, GFP_KERNEL);
        }
        auth->magic = file_priv->magic;
        mutex_unlock(&dev->master_mutex);
 
        DRM_DEBUG("%u\n", auth->magic);
 
-       return ret < 0 ? ret : 0;
+       return ret;
 }
 
 int drm_authmagic(struct drm_device *dev, void *data,
@@ -90,10 +89,10 @@ int drm_authmagic(struct drm_device *dev, void *data,
        DRM_DEBUG("%u\n", auth->magic);
 
        mutex_lock(&dev->master_mutex);
-       file = idr_find(&file_priv->master->magic_map, auth->magic);
+       file = xa_load(&file_priv->master->magic_map, auth->magic);
        if (file) {
                file->authenticated = 1;
-               idr_replace(&file_priv->master->magic_map, NULL, auth->magic);
+               xa_store(&file_priv->master->magic_map, auth->magic, NULL, 0);
        }
        mutex_unlock(&dev->master_mutex);
 
@@ -110,7 +109,7 @@ struct drm_master *drm_master_create(struct drm_device *dev)
 
        kref_init(&master->refcount);
        drm_master_legacy_init(master);
-       idr_init(&master->magic_map);
+       xa_init_flags(&master->magic_map, XA_FLAGS_ALLOC1);
        master->dev = dev;
 
        /* initialize the tree of output resource lessees */
@@ -272,7 +271,7 @@ void drm_master_release(struct drm_file *file_priv)
 
        mutex_lock(&dev->master_mutex);
        if (file_priv->magic)
-               idr_remove(&file_priv->master->magic_map, file_priv->magic);
+               xa_erase(&file_priv->master->magic_map, file_priv->magic);
 
        if (!drm_is_current_master(file_priv))
                goto out;
@@ -337,7 +336,6 @@ static void drm_master_destroy(struct kref *kref)
 
        drm_legacy_master_rmmaps(dev, master);
 
-       idr_destroy(&master->magic_map);
        idr_destroy(&master->leases);
        idr_destroy(&master->lessee_idr);
 
index 6bf8b2b789919870afe5a1194554a831b0127815..28f94e7ccf822d9d88500a629d7f6c121837be50 100644 (file)
@@ -82,10 +82,9 @@ struct drm_master {
         */
        int unique_len;
        /**
-        * @magic_map: Map of used authentication tokens. Protected by
-        * &drm_device.master_mutex.
+        * @magic_map: Map of used authentication tokens.
         */
-       struct idr magic_map;
+       struct xarray magic_map;
        void *driver_priv;
 
        /* Tree of display resource leases, each of which is a drm_master struct