Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936517AbcLOPC0 (ORCPT ); Thu, 15 Dec 2016 10:02:26 -0500 Received: from p3plsmtps2ded01.prod.phx3.secureserver.net ([208.109.80.58]:39420 "EHLO p3plsmtps2ded01.prod.phx3.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757926AbcLOPCY (ORCPT ); Thu, 15 Dec 2016 10:02:24 -0500 x-originating-ip: 72.167.245.219 From: Matthew Wilcox To: Vinod Koul , Dan Williams , dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Matthew Wilcox Subject: [PATCH] dmaengine: Convert ID allocation to an IDA Date: Thu, 15 Dec 2016 08:57:51 -0800 Message-Id: <1481821071-8477-1-git-send-email-mawilcox@linuxonhyperv.com> X-Mailer: git-send-email 1.7.4.1 X-CMAE-Envelope: MS4wfEg5TkjN1J9vjR68rLMw5DyLSFVKMugTEsbfq1rf6HUuppm7Ipqm4IOFYrTuiTDAq0kXg0W+eZ32exLyRi2tgVmGCO1sTyLCGOAzdUiBCe7/8BFCqamO UEczlebDePjCN51SBlmOWZk+ZrxwPSCGjafyD5AUrkw0o0FSYVpbycgtRnDrUFrRY2RoCuP7sywVfPLaMfTuFphfOdHmcofSepTj45Zv/v9ZO/iyVQfikCdS 8fNxHIktARyTIta8Lij7Wql4DJmUzCsIlD3JVqGC466uSLVMF3MfvuTcpMPJjNvVOb/rz4OhN+SMMuGjhd7aCLKb8p/Tpmi9M2HRnMYsqj4= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2031 Lines: 67 From: Matthew Wilcox 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 --- drivers/dma/dmaengine.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c index 6b53526..24e0221 100644 --- a/drivers/dma/dmaengine.c +++ b/drivers/dma/dmaengine.c @@ -65,7 +65,7 @@ #include static DEFINE_MUTEX(dma_list_mutex); -static DEFINE_IDR(dma_idr); +static DEFINE_IDA(dma_ida); static LIST_HEAD(dma_device_list); 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); if (atomic_dec_and_test(chan_dev->idr_ref)) { 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); kfree(chan_dev->idr_ref); } @@ -898,14 +898,15 @@ static int get_dma_id(struct dma_device *device) { int rc; - mutex_lock(&dma_list_mutex); - - rc = idr_alloc(&dma_idr, NULL, 0, 0, GFP_KERNEL); - if (rc >= 0) - device->dev_id = rc; + 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); - mutex_unlock(&dma_list_mutex); - return rc < 0 ? rc : 0; + return rc; } /** @@ -1035,7 +1036,7 @@ int dma_async_device_register(struct dma_device *device) /* if we never registered a channel just release the idr */ if (atomic_read(idr_ref) == 0) { mutex_lock(&dma_list_mutex); - idr_remove(&dma_idr, device->dev_id); + ida_remove(&dma_ida, device->dev_id); mutex_unlock(&dma_list_mutex); kfree(idr_ref); return rc; -- 2.10.2