From: Matthew Wilcox <willy@infradead.org>
Remove aux_idr_mutex by converting aux_idr to an XArray.
Signed-off-by: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
---
drivers/gpu/drm/display/drm_dp_aux_dev.c | 38 ++++++++++--------------
1 file changed, 15 insertions(+), 23 deletions(-)
diff --git a/drivers/gpu/drm/display/drm_dp_aux_dev.c b/drivers/gpu/drm/display/drm_dp_aux_dev.c
index 29555b9f03c8..edecfea44da8 100644
--- a/drivers/gpu/drm/display/drm_dp_aux_dev.c
+++ b/drivers/gpu/drm/display/drm_dp_aux_dev.c
@@ -52,8 +52,7 @@ struct drm_dp_aux_dev {
#define DRM_AUX_MINORS 256
#define AUX_MAX_OFFSET (1 << 20)
-static DEFINE_IDR(aux_idr);
-static DEFINE_MUTEX(aux_idr_mutex);
+static DEFINE_XARRAY_ALLOC(aux_xa);
static struct class *drm_dp_aux_dev_class;
static int drm_dev_major = -1;
@@ -61,11 +60,11 @@ static struct drm_dp_aux_dev *drm_dp_aux_dev_get_by_minor(unsigned index)
{
struct drm_dp_aux_dev *aux_dev = NULL;
- mutex_lock(&aux_idr_mutex);
- aux_dev = idr_find(&aux_idr, index);
+ xa_lock(&aux_xa);
+ aux_dev = xa_load(&aux_xa, index);
if (aux_dev && !kref_get_unless_zero(&aux_dev->refcount))
aux_dev = NULL;
- mutex_unlock(&aux_idr_mutex);
+ xa_unlock(&aux_xa);
return aux_dev;
}
@@ -73,7 +72,7 @@ static struct drm_dp_aux_dev *drm_dp_aux_dev_get_by_minor(unsigned index)
static struct drm_dp_aux_dev *alloc_drm_dp_aux_dev(struct drm_dp_aux *aux)
{
struct drm_dp_aux_dev *aux_dev;
- int index;
+ int err;
aux_dev = kzalloc(sizeof(*aux_dev), GFP_KERNEL);
if (!aux_dev)
@@ -82,14 +81,12 @@ static struct drm_dp_aux_dev *alloc_drm_dp_aux_dev(struct drm_dp_aux *aux)
atomic_set(&aux_dev->usecount, 1);
kref_init(&aux_dev->refcount);
- mutex_lock(&aux_idr_mutex);
- index = idr_alloc(&aux_idr, aux_dev, 0, DRM_AUX_MINORS, GFP_KERNEL);
- mutex_unlock(&aux_idr_mutex);
- if (index < 0) {
+ err = xa_alloc(&aux_xa, &aux_dev->index,
+ XA_LIMIT(0, DRM_AUX_MINORS - 1), aux_dev, GFP_KERNEL);
+ if (err < 0) {
kfree(aux_dev);
- return ERR_PTR(index);
+ return ERR_PTR(err);
}
- aux_dev->index = index;
return aux_dev;
}
@@ -250,22 +247,19 @@ static const struct file_operations auxdev_fops = {
static struct drm_dp_aux_dev *drm_dp_aux_dev_get_by_aux(struct drm_dp_aux *aux)
{
- struct drm_dp_aux_dev *iter, *aux_dev = NULL;
- int id;
+ struct drm_dp_aux_dev *aux_dev;
+ unsigned long id;
/* don't increase kref count here because this function should only be
* used by drm_dp_aux_unregister_devnode. Thus, it will always have at
* least one reference - the one that drm_dp_aux_register_devnode
* created
*/
- mutex_lock(&aux_idr_mutex);
- idr_for_each_entry(&aux_idr, iter, id) {
- if (iter->aux == aux) {
- aux_dev = iter;
+ xa_for_each(&aux_xa, id, aux_dev) {
+ if (aux_dev->aux == aux)
break;
- }
}
- mutex_unlock(&aux_idr_mutex);
+
return aux_dev;
}
@@ -284,9 +278,7 @@ void drm_dp_aux_unregister_devnode(struct drm_dp_aux *aux)
*/
aux->drm_dev = NULL;
- mutex_lock(&aux_idr_mutex);
- idr_remove(&aux_idr, aux_dev->index);
- mutex_unlock(&aux_idr_mutex);
+ xa_erase(&aux_xa, aux_dev->index);
atomic_dec(&aux_dev->usecount);
wait_var_event(&aux_dev->usecount, !atomic_read(&aux_dev->usecount));
--
2.43.0
Hi Sidhartha, kernel test robot noticed the following build errors: [auto build test ERROR on v6.16] [also build test ERROR on next-20250819] [cannot apply to drm-exynos/exynos-drm-next linus/master v6.17-rc2 v6.17-rc1] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Sidhartha-Kumar/drm-Convert-aux_idr-to-XArray/20250819-031755 base: v6.16 patch link: https://lore.kernel.org/r/20250818190046.157962-2-sidhartha.kumar%40oracle.com patch subject: [PATCH 1/6] drm: Convert aux_idr to XArray config: x86_64-buildonly-randconfig-002-20250819 (https://download.01.org/0day-ci/archive/20250819/202508191844.VZB7euYb-lkp@intel.com/config) compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250819/202508191844.VZB7euYb-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202508191844.VZB7euYb-lkp@intel.com/ All errors (new ones prefixed by >>): >> drivers/gpu/drm/display/drm_dp_aux_dev.c:85:5: error: passing 'struct xa_limit' to parameter of incompatible type 'void *' 85 | XA_LIMIT(0, DRM_AUX_MINORS - 1), aux_dev, GFP_KERNEL); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/xarray.h:248:30: note: expanded from macro 'XA_LIMIT' 248 | #define XA_LIMIT(_min, _max) (struct xa_limit) { .min = _min, .max = _max } | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/xarray.h:872:9: note: passing argument to parameter 'entry' here 872 | void *entry, struct xa_limit limit, gfp_t gfp) | ^ 1 error generated. vim +85 drivers/gpu/drm/display/drm_dp_aux_dev.c 71 72 static struct drm_dp_aux_dev *alloc_drm_dp_aux_dev(struct drm_dp_aux *aux) 73 { 74 struct drm_dp_aux_dev *aux_dev; 75 int err; 76 77 aux_dev = kzalloc(sizeof(*aux_dev), GFP_KERNEL); 78 if (!aux_dev) 79 return ERR_PTR(-ENOMEM); 80 aux_dev->aux = aux; 81 atomic_set(&aux_dev->usecount, 1); 82 kref_init(&aux_dev->refcount); 83 84 err = xa_alloc(&aux_xa, &aux_dev->index, > 85 XA_LIMIT(0, DRM_AUX_MINORS - 1), aux_dev, GFP_KERNEL); 86 if (err < 0) { 87 kfree(aux_dev); 88 return ERR_PTR(err); 89 } 90 91 return aux_dev; 92 } 93 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
© 2016 - 2025 Red Hat, Inc.