Skip to content

Commit

Permalink
mmc: set controller name early
Browse files Browse the repository at this point in the history
Reorganise code so that mmc_hostname() works directly after allocation.
That way host drivers can use that name for resource allocations and
messages during probing.

Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
  • Loading branch information
Pierre Ossman committed Apr 18, 2008
1 parent e675349 commit ff3112f
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions drivers/mmc/core/host.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down

0 comments on commit ff3112f

Please sign in to comment.