tree 433c4c4d75ebbf2b2671c7368afdb0fed8163a10
parent 1ad434d7cf5f490c71cfbbb2fb91076c01c8704e
author Russell King <[EMAIL PROTECTED]> Fri, 19 Aug 2005 09:42:52 +0100
committer Russell King <[EMAIL PROTECTED]> Fri, 19 Aug 2005 09:42:52 +0100

[MMC] Use an IDR for host name indicies

Signed-off-by: Russell King <[EMAIL PROTECTED]>

 drivers/mmc/mmc_sysfs.c  |   21 +++++++++++++++++++--
 include/linux/mmc/host.h |    1 +
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/mmc_sysfs.c b/drivers/mmc/mmc_sysfs.c
--- a/drivers/mmc/mmc_sysfs.c
+++ b/drivers/mmc/mmc_sysfs.c
@@ -12,6 +12,7 @@
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/device.h>
+#include <linux/idr.h>
 
 #include <linux/mmc/card.h>
 #include <linux/mmc/host.h>
@@ -236,6 +237,9 @@ static struct class mmc_host_class = {
        .release        = mmc_host_classdev_release,
 };
 
+static DEFINE_IDR(mmc_host_idr);
+static DEFINE_SPINLOCK(mmc_host_lock);
+
 /*
  * Internal function. Allocate a new MMC host.
  */
@@ -261,10 +265,19 @@ struct mmc_host *mmc_alloc_host_sysfs(in
  */
 int mmc_add_host_sysfs(struct mmc_host *host)
 {
-       static unsigned int host_num;
+       int err;
+
+       if (!idr_pre_get(&mmc_host_idr, GFP_KERNEL))
+               return -ENOMEM;
+
+       spin_lock(&mmc_host_lock);
+       err = idr_get_new(&mmc_host_idr, host, &host->index);
+       spin_unlock(&mmc_host_lock);
+       if (err)
+               return err;
 
        snprintf(host->class_dev.class_id, BUS_ID_SIZE,
-                "mmc%d", host_num++);
+                "mmc%d", host->index);
 
        return class_device_add(&host->class_dev);
 }
@@ -275,6 +288,10 @@ int mmc_add_host_sysfs(struct mmc_host *
 void mmc_remove_host_sysfs(struct mmc_host *host)
 {
        class_device_del(&host->class_dev);
+
+       spin_lock(&mmc_host_lock);
+       idr_remove(&mmc_host_idr, host->index);
+       spin_unlock(&mmc_host_lock);
 }
 
 /*
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
--- a/include/linux/mmc/host.h
+++ b/include/linux/mmc/host.h
@@ -64,6 +64,7 @@ struct device;
 struct mmc_host {
        struct device           *dev;
        struct class_device     class_dev;
+       int                     index;
        struct mmc_host_ops     *ops;
        unsigned int            f_min;
        unsigned int            f_max;
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to