Skip to contentSkip to conversation

mmc: core: switch to ida_simple_ functions in block.c

PATCH Applied Heiner Kallweit 2 participants 2 messages Feb 1, 2017 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmc: core: switch to ida_simple_ functions in block.c

ida code in block.c can be significantly simplified by switching to the ida_simple_ functions.

---
 drivers/mmc/core/block.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)
drivers/mmc/core/block.c +5 -26
index ede759dd..d5d8b0e6 100644
@@ -90,7 +90,6 @@ static int max_devices;
 #define MAX_DEVICES 256
 
 static DEFINE_IDA(mmc_blk_ida);
-static DEFINE_SPINLOCK(mmc_blk_lock);
 
 /*
  * There is one mmc_blk_data per slot.
@@ -163,11 +162,7 @@ static void mmc_blk_put(struct mmc_blk_data *md)
 	if (md->usage == 0) {
 		int devidx = mmc_get_devidx(md->disk);
 		blk_cleanup_queue(md->queue.queue);
-
-		spin_lock(&mmc_blk_lock);
-		ida_remove(&mmc_blk_ida, devidx);
-		spin_unlock(&mmc_blk_lock);
-
+		ida_simple_remove(&mmc_blk_ida, devidx);
 		put_disk(md->disk);
 		kfree(md);
 	}
@@ -1836,23 +1831,9 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
 	struct mmc_blk_data *md;
 	int devidx, ret;
 
-again:
-	if (!ida_pre_get(&mmc_blk_ida, GFP_KERNEL))
-		return ERR_PTR(-ENOMEM);
-
-	spin_lock(&mmc_blk_lock);
-	ret = ida_get_new(&mmc_blk_ida, &devidx);
-	spin_unlock(&mmc_blk_lock);
-
-	if (ret == -EAGAIN)
-		goto again;
-	else if (ret)
-		return ERR_PTR(ret);
-
-	if (devidx >= max_devices) {
-		ret = -ENOSPC;
-		goto out;
-	}
+	devidx = ida_simple_get(&mmc_blk_ida, 0, max_devices, GFP_KERNEL);
+	if (devidx < 0)
+		return ERR_PTR(devidx);
 
 	md = kzalloc(sizeof(struct mmc_blk_data), GFP_KERNEL);
 	if (!md) {
@@ -1941,9 +1922,7 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
  err_kfree:
 	kfree(md);
  out:
-	spin_lock(&mmc_blk_lock);
-	ida_remove(&mmc_blk_ida, devidx);
-	spin_unlock(&mmc_blk_lock);
+	ida_simple_remove(&mmc_blk_ida, devidx);
 	return ERR_PTR(ret);
 }
 
Signature · 1 line
2.11.0
Applied
#1 lore raw
Quoted 4 lines · Heiner Kallweit

ida code in block.c can be significantly simplified by switching to the ida_simple_ functions.

Thanks, applied for next!

Kind regards
Uffe

Quoted 70 lines
---
 drivers/mmc/core/block.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)
drivers/mmc/core/block.c +5 -27
index ede759dd..d5d8b0e6 100644
@@ -90,7 +90,6 @@ static int max_devices;
 #define MAX_DEVICES 256
 
 static DEFINE_IDA(mmc_blk_ida);
-static DEFINE_SPINLOCK(mmc_blk_lock);
 
 /*
  * There is one mmc_blk_data per slot.
@@ -163,11 +162,7 @@ static void mmc_blk_put(struct mmc_blk_data *md)
        if (md->usage == 0) {
                int devidx = mmc_get_devidx(md->disk);
                blk_cleanup_queue(md->queue.queue);
-
-               spin_lock(&mmc_blk_lock);
-               ida_remove(&mmc_blk_ida, devidx);
-               spin_unlock(&mmc_blk_lock);
-
+               ida_simple_remove(&mmc_blk_ida, devidx);
                put_disk(md->disk);
                kfree(md);
        }
@@ -1836,23 +1831,9 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
        struct mmc_blk_data *md;
        int devidx, ret;
 
-again:
-       if (!ida_pre_get(&mmc_blk_ida, GFP_KERNEL))
-               return ERR_PTR(-ENOMEM);
-
-       spin_lock(&mmc_blk_lock);
-       ret = ida_get_new(&mmc_blk_ida, &devidx);
-       spin_unlock(&mmc_blk_lock);
-
-       if (ret == -EAGAIN)
-               goto again;
-       else if (ret)
-               return ERR_PTR(ret);
-
-       if (devidx >= max_devices) {
-               ret = -ENOSPC;
-               goto out;
-       }
+       devidx = ida_simple_get(&mmc_blk_ida, 0, max_devices, GFP_KERNEL);
+       if (devidx < 0)
+               return ERR_PTR(devidx);
 
        md = kzalloc(sizeof(struct mmc_blk_data), GFP_KERNEL);
        if (!md) {
@@ -1941,9 +1922,7 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
  err_kfree:
        kfree(md);
  out:
-       spin_lock(&mmc_blk_lock);
-       ida_remove(&mmc_blk_ida, devidx);
-       spin_unlock(&mmc_blk_lock);
+       ida_simple_remove(&mmc_blk_ida, devidx);
        return ERR_PTR(ret);
 }
 
--

2.11.0