Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mmc: set controller name early

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>

+22 -17
+22 -17
drivers/mmc/core/host.c
··· 2 2 * linux/drivers/mmc/core/host.c 3 3 * 4 4 * Copyright (C) 2003 Russell King, All Rights Reserved. 5 - * Copyright (C) 2007 Pierre Ossman 5 + * Copyright (C) 2007-2008 Pierre Ossman 6 6 * 7 7 * This program is free software; you can redistribute it and/or modify 8 8 * it under the terms of the GNU General Public License version 2 as ··· 57 57 */ 58 58 struct mmc_host *mmc_alloc_host(int extra, struct device *dev) 59 59 { 60 + int err; 60 61 struct mmc_host *host; 62 + 63 + if (!idr_pre_get(&mmc_host_idr, GFP_KERNEL)) 64 + return NULL; 61 65 62 66 host = kzalloc(sizeof(struct mmc_host) + extra, GFP_KERNEL); 63 67 if (!host) 64 68 return NULL; 69 + 70 + spin_lock(&mmc_host_lock); 71 + err = idr_get_new(&mmc_host_idr, host, &host->index); 72 + spin_unlock(&mmc_host_lock); 73 + if (err) 74 + goto free; 75 + 76 + snprintf(host->class_dev.bus_id, BUS_ID_SIZE, 77 + "mmc%d", host->index); 65 78 66 79 host->parent = dev; 67 80 host->class_dev.parent = dev; ··· 98 85 host->max_blk_count = PAGE_CACHE_SIZE / 512; 99 86 100 87 return host; 88 + 89 + free: 90 + kfree(host); 91 + return NULL; 101 92 } 102 93 103 94 EXPORT_SYMBOL(mmc_alloc_host); ··· 120 103 121 104 WARN_ON((host->caps & MMC_CAP_SDIO_IRQ) && 122 105 !host->ops->enable_sdio_irq); 123 - 124 - if (!idr_pre_get(&mmc_host_idr, GFP_KERNEL)) 125 - return -ENOMEM; 126 - 127 - spin_lock(&mmc_host_lock); 128 - err = idr_get_new(&mmc_host_idr, host, &host->index); 129 - spin_unlock(&mmc_host_lock); 130 - if (err) 131 - return err; 132 - 133 - snprintf(host->class_dev.bus_id, BUS_ID_SIZE, 134 - "mmc%d", host->index); 135 106 136 107 led_trigger_register_simple(host->class_dev.bus_id, &host->led); 137 108 ··· 149 144 device_del(&host->class_dev); 150 145 151 146 led_trigger_unregister_simple(host->led); 152 - 153 - spin_lock(&mmc_host_lock); 154 - idr_remove(&mmc_host_idr, host->index); 155 - spin_unlock(&mmc_host_lock); 156 147 } 157 148 158 149 EXPORT_SYMBOL(mmc_remove_host); ··· 161 160 */ 162 161 void mmc_free_host(struct mmc_host *host) 163 162 { 163 + spin_lock(&mmc_host_lock); 164 + idr_remove(&mmc_host_idr, host->index); 165 + spin_unlock(&mmc_host_lock); 166 + 164 167 put_device(&host->class_dev); 165 168 } 166 169