1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
From 50a063a5271868aaf17ee86741e6452a6c405a50 Mon Sep 17 00:00:00 2001
Message-Id: <50a063a5271868aaf17ee86741e6452a6c405a50.1529072479.git.marcel.ziswiler@toradex.com>
In-Reply-To: <fb4764e8eb658d35e8fc62ae79c77e1f6e2b0ef3.1529072479.git.marcel.ziswiler@toradex.com>
References: <fb4764e8eb658d35e8fc62ae79c77e1f6e2b0ef3.1529072479.git.marcel.ziswiler@toradex.com>
From: Marcel Ziswiler <marcel.ziswiler@toradex.com>
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 <marcel.ziswiler@toradex.com>
---
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
|