@@ -697,7 +697,8 @@ static int ide_register_port(ide_hwif_t *hwif)
697697
698698static 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 }
733732out :
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
779778static 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)
829827static 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 */
928921static 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
11621154static 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)
11871179static 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
12831274static 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
13881379static 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
13961388static 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
16031585static 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
16931672void 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 );
0 commit comments