summaryrefslogtreecommitdiff
path: root/drivers/mmc/core/host.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-04-21 17:23:30 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2008-04-21 17:23:30 -0700
commit135cedad7457be6a96d5e151dfd48f7888a75e94 (patch)
treed2ea838ef41ab7dcb85e655b0e6b6ed585c11fe8 /drivers/mmc/core/host.c
parent8a3227268877b81096d7b7a841aaf51099ad2068 (diff)
parente70aa3fac1ac50c7a75ac676a1489dd1ea3b4be5 (diff)
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/drzeus/mmc
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/drzeus/mmc: (26 commits) mmc: sdio_ops.c should #include "sdio_ops.h" mmc: proper prototypes for mmc_attach_*() mmc: make __mmc_release_bus() static sdhci: improve no card, no reset quirk MMC: OMAP: Do not busy wait for end of command for ever MMC: OMAP: Start new commands from work queue instead of irq MMC: OMAP: Lazy clock shutdown MMC: OMAP: Move failing command abortion to workqueue MMC: OMAP: Use tasklet instead of workqueue for cover switch notification MMC: OMAP: Check the get_cover_state function pointer if not set MMC: OMAP: Using setup_timer instead of init_timer MMC: OMAP: Abort stuck commands MMC: OMAP: General cleanup for MMC multislot support MMC: OMAP: Power functions modified to MMC multislot support MMC: OMAP: Fix timeout calculation for MMC multislot support MMC: OMAP: New release dma and abort xfer functions MMC: OMAP: Add back cover switch support MMC: OMAP: Introduce new multislot structure and change driver to use it MMC: OMAP: Remove cover switch handling to allow adding multislot support MMC: OMAP: Fix the BYTEBLOCK capability removal ...
Diffstat (limited to 'drivers/mmc/core/host.c')
-rw-r--r--drivers/mmc/core/host.c39
1 files changed, 22 insertions, 17 deletions
diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
index c65d203a846d..1d795c5379b5 100644
--- a/drivers/mmc/core/host.c
+++ b/drivers/mmc/core/host.c
@@ -2,7 +2,7 @@
* linux/drivers/mmc/core/host.c
*
* Copyright (C) 2003 Russell King, All Rights Reserved.
- * Copyright (C) 2007 Pierre Ossman
+ * Copyright (C) 2007-2008 Pierre Ossman
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -57,12 +57,25 @@ static DEFINE_SPINLOCK(mmc_host_lock);
*/
struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
{
+ int err;
struct mmc_host *host;
+ if (!idr_pre_get(&mmc_host_idr, GFP_KERNEL))
+ return NULL;
+
host = kzalloc(sizeof(struct mmc_host) + extra, GFP_KERNEL);
if (!host)
return NULL;
+ spin_lock(&mmc_host_lock);
+ err = idr_get_new(&mmc_host_idr, host, &host->index);
+ spin_unlock(&mmc_host_lock);
+ if (err)
+ goto free;
+
+ snprintf(host->class_dev.bus_id, BUS_ID_SIZE,
+ "mmc%d", host->index);
+
host->parent = dev;
host->class_dev.parent = dev;
host->class_dev.class = &mmc_host_class;
@@ -85,6 +98,10 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
host->max_blk_count = PAGE_CACHE_SIZE / 512;
return host;
+
+free:
+ kfree(host);
+ return NULL;
}
EXPORT_SYMBOL(mmc_alloc_host);
@@ -104,18 +121,6 @@ int mmc_add_host(struct mmc_host *host)
WARN_ON((host->caps & MMC_CAP_SDIO_IRQ) &&
!host->ops->enable_sdio_irq);
- 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.bus_id, BUS_ID_SIZE,
- "mmc%d", host->index);
-
led_trigger_register_simple(host->class_dev.bus_id, &host->led);
err = device_add(&host->class_dev);
@@ -144,10 +149,6 @@ void mmc_remove_host(struct mmc_host *host)
device_del(&host->class_dev);
led_trigger_unregister_simple(host->led);
-
- spin_lock(&mmc_host_lock);
- idr_remove(&mmc_host_idr, host->index);
- spin_unlock(&mmc_host_lock);
}
EXPORT_SYMBOL(mmc_remove_host);
@@ -160,6 +161,10 @@ EXPORT_SYMBOL(mmc_remove_host);
*/
void mmc_free_host(struct mmc_host *host)
{
+ spin_lock(&mmc_host_lock);
+ idr_remove(&mmc_host_idr, host->index);
+ spin_unlock(&mmc_host_lock);
+
put_device(&host->class_dev);
}