Skip to content

Commit 2bd24a1

Browse files
committed
ide: add port and host iterators
Add ide_port_for_each_dev() / ide_host_for_each_port() iterators and update IDE code to use them. While at it: - s/unit/i/ variable in ide_port_wait_ready(), ide_probe_port(), ide_port_tune_devices(), ide_port_init_devices_data(), do_reset1(), ide_acpi_set_state() and scc_dma_end() - s/d/i/ variable in ide_proc_port_register_devices() There should be no functional changes caused by this patch. Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
1 parent 5e7f3a4 commit 2bd24a1

7 files changed

Lines changed: 67 additions & 85 deletions

File tree

‎drivers/ide/ide-acpi.c‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,8 @@ void ide_acpi_push_timing(ide_hwif_t *hwif)
641641
*/
642642
void ide_acpi_set_state(ide_hwif_t *hwif, int on)
643643
{
644-
int unit;
644+
ide_drive_t *drive;
645+
int i;
645646

646647
if (ide_noacpi || ide_noacpi_psx)
647648
return;
@@ -655,9 +656,8 @@ void ide_acpi_set_state(ide_hwif_t *hwif, int on)
655656
/* channel first and then drives for power on and verse versa for power off */
656657
if (on)
657658
acpi_bus_set_power(hwif->acpidata->obj_handle, ACPI_STATE_D0);
658-
for (unit = 0; unit < MAX_DRIVES; ++unit) {
659-
ide_drive_t *drive = hwif->devices[unit];
660659

660+
ide_port_for_each_dev(i, drive, hwif) {
661661
if (!drive->acpidata->obj_handle)
662662
drive->acpidata->obj_handle = ide_acpi_drive_get_handle(drive);
663663

@@ -717,9 +717,7 @@ void ide_acpi_port_init_devices(ide_hwif_t *hwif)
717717
/*
718718
* Send IDENTIFY for each drive
719719
*/
720-
for (i = 0; i < MAX_DRIVES; i++) {
721-
drive = hwif->devices[i];
722-
720+
ide_port_for_each_dev(i, drive, hwif) {
723721
memset(drive->acpidata, 0, sizeof(*drive->acpidata));
724722

725723
if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
@@ -744,9 +742,7 @@ void ide_acpi_port_init_devices(ide_hwif_t *hwif)
744742
ide_acpi_get_timing(hwif);
745743
ide_acpi_push_timing(hwif);
746744

747-
for (i = 0; i < MAX_DRIVES; i++) {
748-
drive = hwif->devices[i];
749-
745+
ide_port_for_each_dev(i, drive, hwif) {
750746
if (drive->dev_flags & IDE_DFLAG_PRESENT)
751747
/* Execute ACPI startup code */
752748
ide_acpi_exec_tfs(drive);

‎drivers/ide/ide-iops.c‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,8 +1081,9 @@ static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi)
10811081
struct ide_io_ports *io_ports = &hwif->io_ports;
10821082
const struct ide_tp_ops *tp_ops = hwif->tp_ops;
10831083
const struct ide_port_ops *port_ops;
1084+
ide_drive_t *tdrive;
10841085
unsigned long flags, timeout;
1085-
unsigned int unit;
1086+
int i;
10861087
DEFINE_WAIT(wait);
10871088

10881089
spin_lock_irqsave(&hwif->lock, flags);
@@ -1110,9 +1111,7 @@ static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi)
11101111

11111112
prepare_to_wait(&ide_park_wq, &wait, TASK_UNINTERRUPTIBLE);
11121113
timeout = jiffies;
1113-
for (unit = 0; unit < MAX_DRIVES; unit++) {
1114-
ide_drive_t *tdrive = hwif->devices[unit];
1115-
1114+
ide_port_for_each_dev(i, tdrive, hwif) {
11161115
if (tdrive->dev_flags & IDE_DFLAG_PRESENT &&
11171116
tdrive->dev_flags & IDE_DFLAG_PARKED &&
11181117
time_after(tdrive->sleep, timeout))
@@ -1133,8 +1132,8 @@ static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi)
11331132
* First, reset any device state data we were maintaining
11341133
* for any of the drives on this interface.
11351134
*/
1136-
for (unit = 0; unit < MAX_DRIVES; ++unit)
1137-
pre_reset(hwif->devices[unit]);
1135+
ide_port_for_each_dev(i, tdrive, hwif)
1136+
pre_reset(tdrive);
11381137

11391138
if (io_ports->ctl_addr == 0) {
11401139
spin_unlock_irqrestore(&hwif->lock, flags);

‎drivers/ide/ide-probe.c‎

Lines changed: 38 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,8 @@ static int ide_register_port(ide_hwif_t *hwif)
697697

698698
static int ide_port_wait_ready(ide_hwif_t *hwif)
699699
{
700-
int unit, rc;
700+
ide_drive_t *drive;
701+
int i, rc;
701702

702703
printk(KERN_DEBUG "Probing IDE interface %s...\n", hwif->name);
703704

@@ -714,9 +715,7 @@ static int ide_port_wait_ready(ide_hwif_t *hwif)
714715
return rc;
715716

716717
/* Now make sure both master & slave are ready */
717-
for (unit = 0; unit < MAX_DRIVES; unit++) {
718-
ide_drive_t *drive = hwif->devices[unit];
719-
718+
ide_port_for_each_dev(i, drive, hwif) {
720719
/* Ignore disks that we will not probe for later. */
721720
if ((drive->dev_flags & IDE_DFLAG_NOPROBE) == 0 ||
722721
(drive->dev_flags & IDE_DFLAG_PRESENT)) {
@@ -732,7 +731,7 @@ static int ide_port_wait_ready(ide_hwif_t *hwif)
732731
}
733732
out:
734733
/* Exit function with master reselected (let's be sane) */
735-
if (unit)
734+
if (i)
736735
SELECT_DRIVE(hwif->devices[0]);
737736

738737
return rc;
@@ -778,9 +777,10 @@ EXPORT_SYMBOL_GPL(ide_undecoded_slave);
778777

779778
static int ide_probe_port(ide_hwif_t *hwif)
780779
{
780+
ide_drive_t *drive;
781781
unsigned long flags;
782782
unsigned int irqd;
783-
int unit, rc = -ENODEV;
783+
int i, rc = -ENODEV;
784784

785785
BUG_ON(hwif->present);
786786

@@ -806,9 +806,7 @@ static int ide_probe_port(ide_hwif_t *hwif)
806806
* Second drive should only exist if first drive was found,
807807
* but a lot of cdrom drives are configured as single slaves.
808808
*/
809-
for (unit = 0; unit < MAX_DRIVES; ++unit) {
810-
ide_drive_t *drive = hwif->devices[unit];
811-
809+
ide_port_for_each_dev(i, drive, hwif) {
812810
(void) probe_for_drive(drive);
813811
if (drive->dev_flags & IDE_DFLAG_PRESENT)
814812
rc = 0;
@@ -829,20 +827,17 @@ static int ide_probe_port(ide_hwif_t *hwif)
829827
static void ide_port_tune_devices(ide_hwif_t *hwif)
830828
{
831829
const struct ide_port_ops *port_ops = hwif->port_ops;
832-
int unit;
833-
834-
for (unit = 0; unit < MAX_DRIVES; unit++) {
835-
ide_drive_t *drive = hwif->devices[unit];
830+
ide_drive_t *drive;
831+
int i;
836832

833+
ide_port_for_each_dev(i, drive, hwif) {
837834
if (drive->dev_flags & IDE_DFLAG_PRESENT) {
838835
if (port_ops && port_ops->quirkproc)
839836
port_ops->quirkproc(drive);
840837
}
841838
}
842839

843-
for (unit = 0; unit < MAX_DRIVES; ++unit) {
844-
ide_drive_t *drive = hwif->devices[unit];
845-
840+
ide_port_for_each_dev(i, drive, hwif) {
846841
if (drive->dev_flags & IDE_DFLAG_PRESENT) {
847842
ide_set_max_pio(drive);
848843

@@ -853,9 +848,7 @@ static void ide_port_tune_devices(ide_hwif_t *hwif)
853848
}
854849
}
855850

856-
for (unit = 0; unit < MAX_DRIVES; ++unit) {
857-
ide_drive_t *drive = hwif->devices[unit];
858-
851+
ide_port_for_each_dev(i, drive, hwif) {
859852
if ((hwif->host_flags & IDE_HFLAG_NO_IO_32BIT) ||
860853
drive->id[ATA_ID_DWORD_IO])
861854
drive->dev_flags |= IDE_DFLAG_NO_IO_32BIT;
@@ -927,12 +920,11 @@ static DEFINE_MUTEX(ide_cfg_mtx);
927920
*/
928921
static int ide_port_setup_devices(ide_hwif_t *hwif)
929922
{
923+
ide_drive_t *drive;
930924
int i, j = 0;
931925

932926
mutex_lock(&ide_cfg_mtx);
933-
for (i = 0; i < MAX_DRIVES; i++) {
934-
ide_drive_t *drive = hwif->devices[i];
935-
927+
ide_port_for_each_dev(i, drive, hwif) {
936928
if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
937929
continue;
938930

@@ -1161,10 +1153,10 @@ static int hwif_init(ide_hwif_t *hwif)
11611153

11621154
static void hwif_register_devices(ide_hwif_t *hwif)
11631155
{
1156+
ide_drive_t *drive;
11641157
unsigned int i;
11651158

1166-
for (i = 0; i < MAX_DRIVES; i++) {
1167-
ide_drive_t *drive = hwif->devices[i];
1159+
ide_port_for_each_dev(i, drive, hwif) {
11681160
struct device *dev = &drive->gendev;
11691161
int ret;
11701162

@@ -1187,11 +1179,10 @@ static void hwif_register_devices(ide_hwif_t *hwif)
11871179
static void ide_port_init_devices(ide_hwif_t *hwif)
11881180
{
11891181
const struct ide_port_ops *port_ops = hwif->port_ops;
1182+
ide_drive_t *drive;
11901183
int i;
11911184

1192-
for (i = 0; i < MAX_DRIVES; i++) {
1193-
ide_drive_t *drive = hwif->devices[i];
1194-
1185+
ide_port_for_each_dev(i, drive, hwif) {
11951186
drive->dn = i + hwif->channel * 2;
11961187

11971188
if (hwif->host_flags & IDE_HFLAG_IO_32BIT)
@@ -1282,16 +1273,16 @@ static const u8 ide_hwif_to_major[] =
12821273

12831274
static void ide_port_init_devices_data(ide_hwif_t *hwif)
12841275
{
1285-
int unit;
1276+
ide_drive_t *drive;
1277+
int i;
12861278

1287-
for (unit = 0; unit < MAX_DRIVES; ++unit) {
1288-
ide_drive_t *drive = hwif->devices[unit];
1289-
u8 j = (hwif->index * MAX_DRIVES) + unit;
1279+
ide_port_for_each_dev(i, drive, hwif) {
1280+
u8 j = (hwif->index * MAX_DRIVES) + i;
12901281

12911282
memset(drive, 0, sizeof(*drive));
12921283

12931284
drive->media = ide_disk;
1294-
drive->select = (unit << 4) | ATA_DEVICE_OBS;
1285+
drive->select = (i << 4) | ATA_DEVICE_OBS;
12951286
drive->hwif = hwif;
12961287
drive->ready_stat = ATA_DRDY;
12971288
drive->bad_wstat = BAD_W_STAT;
@@ -1387,10 +1378,11 @@ static void ide_free_port_slot(int idx)
13871378

13881379
static void ide_port_free_devices(ide_hwif_t *hwif)
13891380
{
1381+
ide_drive_t *drive;
13901382
int i;
13911383

1392-
for (i = 0; i < MAX_DRIVES; i++)
1393-
kfree(hwif->devices[i]);
1384+
ide_port_for_each_dev(i, drive, hwif)
1385+
kfree(drive);
13941386
}
13951387

13961388
static int ide_port_alloc_devices(ide_hwif_t *hwif, int node)
@@ -1478,9 +1470,7 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
14781470
ide_hwif_t *hwif, *mate = NULL;
14791471
int i, j = 0;
14801472

1481-
for (i = 0; i < MAX_HOST_PORTS; i++) {
1482-
hwif = host->ports[i];
1483-
1473+
ide_host_for_each_port(i, hwif, host) {
14841474
if (hwif == NULL) {
14851475
mate = NULL;
14861476
continue;
@@ -1506,9 +1496,7 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
15061496
ide_port_init_devices(hwif);
15071497
}
15081498

1509-
for (i = 0; i < MAX_HOST_PORTS; i++) {
1510-
hwif = host->ports[i];
1511-
1499+
ide_host_for_each_port(i, hwif, host) {
15121500
if (hwif == NULL)
15131501
continue;
15141502

@@ -1523,9 +1511,7 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
15231511
ide_port_tune_devices(hwif);
15241512
}
15251513

1526-
for (i = 0; i < MAX_HOST_PORTS; i++) {
1527-
hwif = host->ports[i];
1528-
1514+
ide_host_for_each_port(i, hwif, host) {
15291515
if (hwif == NULL)
15301516
continue;
15311517

@@ -1550,19 +1536,15 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
15501536
ide_acpi_port_init_devices(hwif);
15511537
}
15521538

1553-
for (i = 0; i < MAX_HOST_PORTS; i++) {
1554-
hwif = host->ports[i];
1555-
1539+
ide_host_for_each_port(i, hwif, host) {
15561540
if (hwif == NULL)
15571541
continue;
15581542

15591543
if (hwif->present)
15601544
hwif_register_devices(hwif);
15611545
}
15621546

1563-
for (i = 0; i < MAX_HOST_PORTS; i++) {
1564-
hwif = host->ports[i];
1565-
1547+
ide_host_for_each_port(i, hwif, host) {
15661548
if (hwif == NULL)
15671549
continue;
15681550

@@ -1602,11 +1584,10 @@ EXPORT_SYMBOL_GPL(ide_host_add);
16021584

16031585
static void __ide_port_unregister_devices(ide_hwif_t *hwif)
16041586
{
1587+
ide_drive_t *drive;
16051588
int i;
16061589

1607-
for (i = 0; i < MAX_DRIVES; i++) {
1608-
ide_drive_t *drive = hwif->devices[i];
1609-
1590+
ide_port_for_each_dev(i, drive, hwif) {
16101591
if (drive->dev_flags & IDE_DFLAG_PRESENT) {
16111592
device_unregister(&drive->gendev);
16121593
wait_for_completion(&drive->gendev_rel_comp);
@@ -1675,9 +1656,7 @@ void ide_host_free(struct ide_host *host)
16751656
ide_hwif_t *hwif;
16761657
int i;
16771658

1678-
for (i = 0; i < MAX_HOST_PORTS; i++) {
1679-
hwif = host->ports[i];
1680-
1659+
ide_host_for_each_port(i, hwif, host) {
16811660
if (hwif == NULL)
16821661
continue;
16831662

@@ -1692,11 +1671,12 @@ EXPORT_SYMBOL_GPL(ide_host_free);
16921671

16931672
void ide_host_remove(struct ide_host *host)
16941673
{
1674+
ide_hwif_t *hwif;
16951675
int i;
16961676

1697-
for (i = 0; i < MAX_HOST_PORTS; i++) {
1698-
if (host->ports[i])
1699-
ide_unregister(host->ports[i]);
1677+
ide_host_for_each_port(i, hwif, host) {
1678+
if (hwif)
1679+
ide_unregister(hwif);
17001680
}
17011681

17021682
ide_host_free(host);

‎drivers/ide/ide-proc.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -593,14 +593,13 @@ EXPORT_SYMBOL(ide_proc_unregister_driver);
593593

594594
void ide_proc_port_register_devices(ide_hwif_t *hwif)
595595
{
596-
int d;
597596
struct proc_dir_entry *ent;
598597
struct proc_dir_entry *parent = hwif->proc;
598+
ide_drive_t *drive;
599599
char name[64];
600+
int i;
600601

601-
for (d = 0; d < MAX_DRIVES; d++) {
602-
ide_drive_t *drive = hwif->devices[d];
603-
602+
ide_port_for_each_dev(i, drive, hwif) {
604603
if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0 || drive->proc)
605604
continue;
606605

‎drivers/ide/ide.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ MODULE_PARM_DESC(ignore_cable, "ignore cable detection");
488488

489489
void ide_port_apply_params(ide_hwif_t *hwif)
490490
{
491+
ide_drive_t *drive;
491492
int i;
492493

493494
if (ide_ignore_cable & (1 << hwif->index)) {
@@ -496,8 +497,8 @@ void ide_port_apply_params(ide_hwif_t *hwif)
496497
hwif->cbl = ATA_CBL_PATA40_SHORT;
497498
}
498499

499-
for (i = 0; i < MAX_DRIVES; i++)
500-
ide_dev_apply_params(hwif->devices[i], i);
500+
ide_port_for_each_dev(i, drive, hwif)
501+
ide_dev_apply_params(drive, i);
501502
}
502503

503504
/*

‎drivers/ide/scc_pata.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,17 +406,17 @@ static int scc_dma_end(ide_drive_t *drive)
406406
data_loss = 1;
407407
if (retry++) {
408408
struct request *rq = hwif->rq;
409-
int unit;
409+
ide_drive_t *drive;
410+
int i;
411+
410412
/* ERROR_RESET and drive->crc_count are needed
411413
* to reduce DMA transfer mode in retry process.
412414
*/
413415
if (rq)
414416
rq->errors |= ERROR_RESET;
415-
for (unit = 0; unit < MAX_DRIVES; unit++) {
416-
ide_drive_t *drive = hwif->devices[unit];
417417

418+
ide_port_for_each_dev(i, drive, hwif)
418419
drive->crc_count++;
419-
}
420420
}
421421
}
422422
}

0 commit comments

Comments
 (0)