From 50a063a5271868aaf17ee86741e6452a6c405a50 Mon Sep 17 00:00:00 2001 Message-Id: <50a063a5271868aaf17ee86741e6452a6c405a50.1529072479.git.marcel.ziswiler@toradex.com> In-Reply-To: References: From: Marcel Ziswiler Date: Thu, 19 Apr 2018 13:49:30 +0200 Subject: [PATCH 16/27] Revert "mmc: core: simplify ida handling" This reverts commit 7413d1f509eb0ee605973c1a6da9911700c80012. Signed-off-by: Marcel Ziswiler --- drivers/mmc/core/host.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c index 3740fb0052a4..841b9ce01a8e 100644 --- a/drivers/mmc/core/host.c +++ b/drivers/mmc/core/host.c @@ -35,11 +35,14 @@ #define cls_dev_to_mmc_host(d) container_of(d, struct mmc_host, class_dev) static DEFINE_IDA(mmc_host_ida); +static DEFINE_SPINLOCK(mmc_host_lock); static void mmc_host_classdev_release(struct device *dev) { struct mmc_host *host = cls_dev_to_mmc_host(dev); - ida_simple_remove(&mmc_host_ida, host->index); + spin_lock(&mmc_host_lock); + ida_remove(&mmc_host_ida, host->index); + spin_unlock(&mmc_host_lock); kfree(host); } @@ -358,13 +361,22 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev) /* scanning will be enabled when we're ready */ host->rescan_disable = 1; - err = ida_simple_get(&mmc_host_ida, 0, 0, GFP_KERNEL); - if (err < 0) { +again: + if (!ida_pre_get(&mmc_host_ida, GFP_KERNEL)) { kfree(host); return NULL; } - host->index = err; + spin_lock(&mmc_host_lock); + err = ida_get_new(&mmc_host_ida, &host->index); + spin_unlock(&mmc_host_lock); + + if (err == -EAGAIN) { + goto again; + } else if (err) { + kfree(host); + return NULL; + } dev_set_name(&host->class_dev, "mmc%d", host->index); -- 2.14.4