dmaengine: Convert ID allocation to an IDA
dmaengine currently uses an IDR to allocate DMA IDs, but it only needs to know whether IDs are in use or not; the ID to pointer functionality of the IDR is unused. That means it can use the more space-efficient IDA. Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
This commit is contained in:
parent
0c744ea4f7
commit
adc064cd9f
|
@ -65,7 +65,7 @@
|
||||||
#include <linux/mempool.h>
|
#include <linux/mempool.h>
|
||||||
|
|
||||||
static DEFINE_MUTEX(dma_list_mutex);
|
static DEFINE_MUTEX(dma_list_mutex);
|
||||||
static DEFINE_IDR(dma_idr);
|
static DEFINE_IDA(dma_ida);
|
||||||
static LIST_HEAD(dma_device_list);
|
static LIST_HEAD(dma_device_list);
|
||||||
static long dmaengine_ref_count;
|
static long dmaengine_ref_count;
|
||||||
|
|
||||||
|
@ -162,7 +162,7 @@ static void chan_dev_release(struct device *dev)
|
||||||
chan_dev = container_of(dev, typeof(*chan_dev), device);
|
chan_dev = container_of(dev, typeof(*chan_dev), device);
|
||||||
if (atomic_dec_and_test(chan_dev->idr_ref)) {
|
if (atomic_dec_and_test(chan_dev->idr_ref)) {
|
||||||
mutex_lock(&dma_list_mutex);
|
mutex_lock(&dma_list_mutex);
|
||||||
idr_remove(&dma_idr, chan_dev->dev_id);
|
ida_remove(&dma_ida, chan_dev->dev_id);
|
||||||
mutex_unlock(&dma_list_mutex);
|
mutex_unlock(&dma_list_mutex);
|
||||||
kfree(chan_dev->idr_ref);
|
kfree(chan_dev->idr_ref);
|
||||||
}
|
}
|
||||||
|
@ -898,14 +898,15 @@ static int get_dma_id(struct dma_device *device)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
mutex_lock(&dma_list_mutex);
|
do {
|
||||||
|
if (!ida_pre_get(&dma_ida, GFP_KERNEL))
|
||||||
|
return -ENOMEM;
|
||||||
|
mutex_lock(&dma_list_mutex);
|
||||||
|
rc = ida_get_new(&dma_ida, &device->dev_id);
|
||||||
|
mutex_unlock(&dma_list_mutex);
|
||||||
|
} while (rc == -EAGAIN);
|
||||||
|
|
||||||
rc = idr_alloc(&dma_idr, NULL, 0, 0, GFP_KERNEL);
|
return rc;
|
||||||
if (rc >= 0)
|
|
||||||
device->dev_id = rc;
|
|
||||||
|
|
||||||
mutex_unlock(&dma_list_mutex);
|
|
||||||
return rc < 0 ? rc : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1035,7 +1036,7 @@ err_out:
|
||||||
/* if we never registered a channel just release the idr */
|
/* if we never registered a channel just release the idr */
|
||||||
if (atomic_read(idr_ref) == 0) {
|
if (atomic_read(idr_ref) == 0) {
|
||||||
mutex_lock(&dma_list_mutex);
|
mutex_lock(&dma_list_mutex);
|
||||||
idr_remove(&dma_idr, device->dev_id);
|
ida_remove(&dma_ida, device->dev_id);
|
||||||
mutex_unlock(&dma_list_mutex);
|
mutex_unlock(&dma_list_mutex);
|
||||||
kfree(idr_ref);
|
kfree(idr_ref);
|
||||||
return rc;
|
return rc;
|
||||||
|
|
Loading…
Reference in New Issue