ide: fix IDE port slots reservation and freeing (take 2)
* Make ide_find_port_slot() return port slot index. * Add ide_free_port_slot() helper. * Move ide_init_port_data() call and error printk() from ide_find_port_slot() to ide_host_alloc_all(). * Make ide_{find,free}_port_slot() take ide_cfg_mtx mutex and convert them use ide_indexes bitmap to keep track of reserved port slots. * Don't set hwif->chipset in ide_host_alloc_all() as it is no longer necessary. v2: * Pass the correct slot index to ide_init_port_data(). Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
This commit is contained in:
@@ -1470,18 +1470,20 @@ static int ide_sysfs_register_port(ide_hwif_t *hwif)
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static unsigned int ide_indexes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ide_find_port_slot - find free ide_hwifs[] slot
|
* ide_find_port_slot - find free port slot
|
||||||
* @d: IDE port info
|
* @d: IDE port info
|
||||||
*
|
*
|
||||||
* Return the new hwif. If we are out of free slots return NULL.
|
* Return the new port slot index or -ENOENT if we are out of free slots.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static ide_hwif_t *ide_find_port_slot(const struct ide_port_info *d)
|
static int ide_find_port_slot(const struct ide_port_info *d)
|
||||||
{
|
{
|
||||||
ide_hwif_t *hwif;
|
int idx = -ENOENT;
|
||||||
int i;
|
|
||||||
u8 bootable = (d && (d->host_flags & IDE_HFLAG_NON_BOOTABLE)) ? 0 : 1;
|
u8 bootable = (d && (d->host_flags & IDE_HFLAG_NON_BOOTABLE)) ? 0 : 1;
|
||||||
|
u8 i = (d && (d->host_flags & IDE_HFLAG_QD_2ND_PORT)) ? 1 : 0;;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Claim an unassigned slot.
|
* Claim an unassigned slot.
|
||||||
@@ -1493,35 +1495,33 @@ static ide_hwif_t *ide_find_port_slot(const struct ide_port_info *d)
|
|||||||
* Unless there is a bootable card that does not use the standard
|
* Unless there is a bootable card that does not use the standard
|
||||||
* ports 0x1f0/0x170 (the ide0/ide1 defaults).
|
* ports 0x1f0/0x170 (the ide0/ide1 defaults).
|
||||||
*/
|
*/
|
||||||
if (bootable) {
|
mutex_lock(&ide_cfg_mtx);
|
||||||
i = (d && (d->host_flags & IDE_HFLAG_QD_2ND_PORT)) ? 1 : 0;
|
if (MAX_HWIFS == 1) {
|
||||||
|
if (ide_indexes == 0 && i == 0)
|
||||||
for (; i < MAX_HWIFS; i++) {
|
idx = 1;
|
||||||
hwif = &ide_hwifs[i];
|
|
||||||
if (hwif->chipset == ide_unknown)
|
|
||||||
goto out_found;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
for (i = 2; i < MAX_HWIFS; i++) {
|
if (bootable) {
|
||||||
hwif = &ide_hwifs[i];
|
if ((ide_indexes | i) != (1 << MAX_HWIFS) - 1)
|
||||||
if (hwif->chipset == ide_unknown)
|
idx = ffz(ide_indexes | i);
|
||||||
goto out_found;
|
} else {
|
||||||
}
|
if ((ide_indexes | 3) != (1 << MAX_HWIFS) - 1)
|
||||||
for (i = 0; i < 2 && i < MAX_HWIFS; i++) {
|
idx = ffz(ide_indexes | 3);
|
||||||
hwif = &ide_hwifs[i];
|
else if ((ide_indexes & 3) != 3)
|
||||||
if (hwif->chipset == ide_unknown)
|
idx = ffz(ide_indexes);
|
||||||
goto out_found;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (idx >= 0)
|
||||||
|
ide_indexes |= (1 << idx);
|
||||||
|
mutex_unlock(&ide_cfg_mtx);
|
||||||
|
|
||||||
printk(KERN_ERR "%s: no free slot for interface\n",
|
return idx;
|
||||||
d ? d->name : "ide");
|
}
|
||||||
|
|
||||||
return NULL;
|
static void ide_free_port_slot(int idx)
|
||||||
|
{
|
||||||
out_found:
|
mutex_lock(&ide_cfg_mtx);
|
||||||
ide_init_port_data(hwif, i);
|
ide_indexes &= ~(1 << idx);
|
||||||
return hwif;
|
mutex_unlock(&ide_cfg_mtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ide_host *ide_host_alloc_all(const struct ide_port_info *d,
|
struct ide_host *ide_host_alloc_all(const struct ide_port_info *d,
|
||||||
@@ -1536,18 +1536,25 @@ struct ide_host *ide_host_alloc_all(const struct ide_port_info *d,
|
|||||||
|
|
||||||
for (i = 0; i < MAX_HWIFS; i++) {
|
for (i = 0; i < MAX_HWIFS; i++) {
|
||||||
ide_hwif_t *hwif;
|
ide_hwif_t *hwif;
|
||||||
|
int idx;
|
||||||
|
|
||||||
if (hws[i] == NULL)
|
if (hws[i] == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
hwif = ide_find_port_slot(d);
|
idx = ide_find_port_slot(d);
|
||||||
if (hwif) {
|
if (idx < 0) {
|
||||||
hwif->chipset = hws[i]->chipset;
|
printk(KERN_ERR "%s: no free slot for interface\n",
|
||||||
|
d ? d->name : "ide");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
hwif = &ide_hwifs[idx];
|
||||||
|
|
||||||
|
ide_init_port_data(hwif, idx);
|
||||||
|
|
||||||
host->ports[i] = hwif;
|
host->ports[i] = hwif;
|
||||||
host->n_ports++;
|
host->n_ports++;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (host->n_ports == 0) {
|
if (host->n_ports == 0) {
|
||||||
kfree(host);
|
kfree(host);
|
||||||
@@ -1695,11 +1702,17 @@ EXPORT_SYMBOL_GPL(ide_host_add);
|
|||||||
|
|
||||||
void ide_host_remove(struct ide_host *host)
|
void ide_host_remove(struct ide_host *host)
|
||||||
{
|
{
|
||||||
|
ide_hwif_t *hwif;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < MAX_HWIFS; i++) {
|
for (i = 0; i < MAX_HWIFS; i++) {
|
||||||
if (host->ports[i])
|
hwif = host->ports[i];
|
||||||
ide_unregister(host->ports[i]);
|
|
||||||
|
if (hwif == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
ide_unregister(hwif);
|
||||||
|
ide_free_port_slot(hwif->index);
|
||||||
}
|
}
|
||||||
|
|
||||||
kfree(host);
|
kfree(host);
|
||||||
|
Reference in New Issue
Block a user