Skip to content

Commit f7f7739

Browse files
davejiangvinodkoul
authored andcommitted
dmaengine: idxd: use ida for device instance enumeration
The idr is only used for an device id, never to lookup context from that id. Switch to plain ida. Fixes: bfe1d56 ("dmaengine: idxd: Init and probe for Intel data accelerators") Reported-by: Jason Gunthorpe <[email protected]> Signed-off-by: Dave Jiang <[email protected]> Link: https://lore.kernel.org/r/161852984730.2203940.15032482460902003819.stgit@djiang5-desk3.ch.intel.com Signed-off-by: Vinod Koul <[email protected]>
1 parent a39c7cd commit f7f7739

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

drivers/dma/idxd/init.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ MODULE_PARM_DESC(sva, "Toggle SVA support on/off");
3434

3535
bool support_enqcmd;
3636

37-
static struct idr idxd_idrs[IDXD_TYPE_MAX];
38-
static DEFINE_MUTEX(idxd_idr_lock);
37+
static struct ida idxd_idas[IDXD_TYPE_MAX];
3938

4039
static struct pci_device_id idxd_pci_tbl[] = {
4140
/* DSA ver 1.0 platforms */
@@ -348,20 +347,18 @@ static int idxd_probe(struct idxd_device *idxd)
348347

349348
dev_dbg(dev, "IDXD interrupt setup complete.\n");
350349

351-
mutex_lock(&idxd_idr_lock);
352-
idxd->id = idr_alloc(&idxd_idrs[idxd->type], idxd, 0, 0, GFP_KERNEL);
353-
mutex_unlock(&idxd_idr_lock);
350+
idxd->id = ida_alloc(&idxd_idas[idxd->type], GFP_KERNEL);
354351
if (idxd->id < 0) {
355352
rc = -ENOMEM;
356-
goto err_idr_fail;
353+
goto err_ida_fail;
357354
}
358355

359356
idxd->major = idxd_cdev_get_major(idxd);
360357

361358
dev_dbg(dev, "IDXD device %d probed successfully\n", idxd->id);
362359
return 0;
363360

364-
err_idr_fail:
361+
err_ida_fail:
365362
idxd_mask_error_interrupts(idxd);
366363
idxd_mask_msix_vectors(idxd);
367364
err_setup:
@@ -518,9 +515,7 @@ static void idxd_remove(struct pci_dev *pdev)
518515
idxd_shutdown(pdev);
519516
if (device_pasid_enabled(idxd))
520517
idxd_disable_system_pasid(idxd);
521-
mutex_lock(&idxd_idr_lock);
522-
idr_remove(&idxd_idrs[idxd->type], idxd->id);
523-
mutex_unlock(&idxd_idr_lock);
518+
ida_free(&idxd_idas[idxd->type], idxd->id);
524519
}
525520

526521
static struct pci_driver idxd_pci_driver = {
@@ -550,7 +545,7 @@ static int __init idxd_init_module(void)
550545
support_enqcmd = true;
551546

552547
for (i = 0; i < IDXD_TYPE_MAX; i++)
553-
idr_init(&idxd_idrs[i]);
548+
ida_init(&idxd_idas[i]);
554549

555550
err = idxd_register_bus_type();
556551
if (err < 0)

0 commit comments

Comments
 (0)