From: Matthew Wilcox <wi...@infradead.org>

Part of the mass conversion of IDR users to the XArray API.

Signed-off-by: Matthew Wilcox <wi...@infradead.org>
Signed-off-by: Sidhartha Kumar <sidhartha.ku...@oracle.com>
---
 drivers/gpu/drm/drm_auth.c | 18 ++++++++----------
 include/drm/drm_auth.h     |  5 ++---
 2 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/drm_auth.c b/drivers/gpu/drm/drm_auth.c
index 22aa015df387..41aa20144a9d 100644
--- a/drivers/gpu/drm/drm_auth.c
+++ b/drivers/gpu/drm/drm_auth.c
@@ -97,17 +97,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_dbg_core(dev, "%u\n", auth->magic);
 
-       return ret < 0 ? ret : 0;
+       return ret;
 }
 
 int drm_authmagic(struct drm_device *dev, void *data,
@@ -119,10 +118,10 @@ int drm_authmagic(struct drm_device *dev, void *data,
        drm_dbg_core(dev, "%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);
 
@@ -138,7 +137,7 @@ struct drm_master *drm_master_create(struct drm_device *dev)
                return NULL;
 
        kref_init(&master->refcount);
-       idr_init_base(&master->magic_map, 1);
+       xa_init_flags(&master->magic_map, XA_FLAGS_ALLOC1);
        master->dev = dev;
 
        /* initialize the tree of output resource lessees */
@@ -358,7 +357,7 @@ void drm_master_release(struct drm_file *file_priv)
        mutex_lock(&dev->master_mutex);
        master = file_priv->master;
        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_locked(file_priv))
                goto out;
@@ -425,7 +424,6 @@ static void drm_master_destroy(struct kref *kref)
        if (drm_core_check_feature(dev, DRIVER_MODESET))
                drm_lease_destroy(master);
 
-       idr_destroy(&master->magic_map);
        idr_destroy(&master->leases);
        idr_destroy(&master->lessee_idr);
 
diff --git a/include/drm/drm_auth.h b/include/drm/drm_auth.h
index 50131383ed81..3026aedbc205 100644
--- a/include/drm/drm_auth.h
+++ b/include/drm/drm_auth.h
@@ -58,10 +58,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;
 
        /**
-- 
2.43.0

Reply via email to