diff options
author | Russell King <rmk@dyn-67.arm.linux.org.uk> | 2005-08-19 04:42:52 -0400 |
---|---|---|
committer | Russell King <rmk+kernel@arm.linux.org.uk> | 2005-08-19 04:42:52 -0400 |
commit | dce773771834221817e2d359a7e07a618ba08807 (patch) | |
tree | 433c4c4d75ebbf2b2671c7368afdb0fed8163a10 /drivers/mmc/mmc_sysfs.c | |
parent | 1ad434d7cf5f490c71cfbbb2fb91076c01c8704e (diff) |
[MMC] Use an IDR for host name indicies
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Diffstat (limited to 'drivers/mmc/mmc_sysfs.c')
-rw-r--r-- | drivers/mmc/mmc_sysfs.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/drivers/mmc/mmc_sysfs.c b/drivers/mmc/mmc_sysfs.c index 34fa4a3a02d5..ad8949810fc5 100644 --- a/drivers/mmc/mmc_sysfs.c +++ b/drivers/mmc/mmc_sysfs.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include <linux/module.h> | 12 | #include <linux/module.h> |
13 | #include <linux/init.h> | 13 | #include <linux/init.h> |
14 | #include <linux/device.h> | 14 | #include <linux/device.h> |
15 | #include <linux/idr.h> | ||
15 | 16 | ||
16 | #include <linux/mmc/card.h> | 17 | #include <linux/mmc/card.h> |
17 | #include <linux/mmc/host.h> | 18 | #include <linux/mmc/host.h> |
@@ -236,6 +237,9 @@ static struct class mmc_host_class = { | |||
236 | .release = mmc_host_classdev_release, | 237 | .release = mmc_host_classdev_release, |
237 | }; | 238 | }; |
238 | 239 | ||
240 | static DEFINE_IDR(mmc_host_idr); | ||
241 | static DEFINE_SPINLOCK(mmc_host_lock); | ||
242 | |||
239 | /* | 243 | /* |
240 | * Internal function. Allocate a new MMC host. | 244 | * Internal function. Allocate a new MMC host. |
241 | */ | 245 | */ |
@@ -261,10 +265,19 @@ struct mmc_host *mmc_alloc_host_sysfs(int extra, struct device *dev) | |||
261 | */ | 265 | */ |
262 | int mmc_add_host_sysfs(struct mmc_host *host) | 266 | int mmc_add_host_sysfs(struct mmc_host *host) |
263 | { | 267 | { |
264 | static unsigned int host_num; | 268 | int err; |
269 | |||
270 | if (!idr_pre_get(&mmc_host_idr, GFP_KERNEL)) | ||
271 | return -ENOMEM; | ||
272 | |||
273 | spin_lock(&mmc_host_lock); | ||
274 | err = idr_get_new(&mmc_host_idr, host, &host->index); | ||
275 | spin_unlock(&mmc_host_lock); | ||
276 | if (err) | ||
277 | return err; | ||
265 | 278 | ||
266 | snprintf(host->class_dev.class_id, BUS_ID_SIZE, | 279 | snprintf(host->class_dev.class_id, BUS_ID_SIZE, |
267 | "mmc%d", host_num++); | 280 | "mmc%d", host->index); |
268 | 281 | ||
269 | return class_device_add(&host->class_dev); | 282 | return class_device_add(&host->class_dev); |
270 | } | 283 | } |
@@ -275,6 +288,10 @@ int mmc_add_host_sysfs(struct mmc_host *host) | |||
275 | void mmc_remove_host_sysfs(struct mmc_host *host) | 288 | void mmc_remove_host_sysfs(struct mmc_host *host) |
276 | { | 289 | { |
277 | class_device_del(&host->class_dev); | 290 | class_device_del(&host->class_dev); |
291 | |||
292 | spin_lock(&mmc_host_lock); | ||
293 | idr_remove(&mmc_host_idr, host->index); | ||
294 | spin_unlock(&mmc_host_lock); | ||
278 | } | 295 | } |
279 | 296 | ||
280 | /* | 297 | /* |