]> git.karo-electronics.de Git - linux-beck.git/commitdiff
ide: add ide_for_each_present_dev() iterator
authorBartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Tue, 24 Mar 2009 22:22:41 +0000 (23:22 +0100)
committerBartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Tue, 24 Mar 2009 22:22:41 +0000 (23:22 +0100)
* Add ide_for_each_present_dev() iterator and convert IDE code to use it.

* Do some drive-by CodingStyle fixups in ide-acpi.c while at it.

There should be no functional changes caused by this patch.

Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
drivers/ide/ide-acpi.c
drivers/ide/ide-iops.c
drivers/ide/ide-probe.c
include/linux/ide.h

index a3bebba184255424ba17b49eb8bb4c80d648e93d..8d6d31fcbfba45d0c52baf64dcae7abb3d4716e7 100644 (file)
@@ -608,17 +608,17 @@ void ide_acpi_set_state(ide_hwif_t *hwif, int on)
                DEBPRINT("no ACPI data for %s\n", hwif->name);
                return;
        }
+
        /* channel first and then drives for power on and verse versa for power off */
        if (on)
                acpi_bus_set_power(hwif->acpidata->obj_handle, ACPI_STATE_D0);
 
-       ide_port_for_each_dev(i, drive, hwif) {
-               if (drive->acpidata->obj_handle &&
-                   (drive->dev_flags & IDE_DFLAG_PRESENT)) {
+       ide_port_for_each_present_dev(i, drive, hwif) {
+               if (drive->acpidata->obj_handle)
                        acpi_bus_set_power(drive->acpidata->obj_handle,
-                               on? ACPI_STATE_D0: ACPI_STATE_D3);
-               }
+                                          on ? ACPI_STATE_D0 : ACPI_STATE_D3);
        }
+
        if (!on)
                acpi_bus_set_power(hwif->acpidata->obj_handle, ACPI_STATE_D3);
 }
@@ -667,12 +667,9 @@ void ide_acpi_port_init_devices(ide_hwif_t *hwif)
        hwif->devices[1]->acpidata = &hwif->acpidata->slave;
 
        /* get _ADR info for each device */
-       ide_port_for_each_dev(i, drive, hwif) {
+       ide_port_for_each_present_dev(i, drive, hwif) {
                acpi_handle dev_handle;
 
-               if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
-                       continue;
-
                DEBPRINT("ENTER: %s at channel#: %d port#: %d\n",
                         drive->name, hwif->channel, drive->dn & 1);
 
@@ -685,13 +682,8 @@ void ide_acpi_port_init_devices(ide_hwif_t *hwif)
                drive->acpidata->obj_handle = dev_handle;
        }
 
-       /*
-        * Send IDENTIFY for each drive
-        */
-       ide_port_for_each_dev(i, drive, hwif) {
-               if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
-                       continue;
-
+       /* send IDENTIFY for each device */
+       ide_port_for_each_present_dev(i, drive, hwif) {
                err = taskfile_lib_get_identify(drive, drive->acpidata->idbuff);
                if (err)
                        DEBPRINT("identify device %s failed (%d)\n",
@@ -711,9 +703,7 @@ void ide_acpi_port_init_devices(ide_hwif_t *hwif)
        ide_acpi_get_timing(hwif);
        ide_acpi_push_timing(hwif);
 
-       ide_port_for_each_dev(i, drive, hwif) {
-               if (drive->dev_flags & IDE_DFLAG_PRESENT)
-                       /* Execute ACPI startup code */
-                       ide_acpi_exec_tfs(drive);
+       ide_port_for_each_present_dev(i, drive, hwif) {
+               ide_acpi_exec_tfs(drive);
        }
 }
index b1892bd95c6fe5e7d270e3b92e2fd825b6847cb3..02fed32a4047966e5c5db4fa6bd05619fa374d0f 100644 (file)
@@ -1103,9 +1103,8 @@ static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi)
 
                prepare_to_wait(&ide_park_wq, &wait, TASK_UNINTERRUPTIBLE);
                timeout = jiffies;
-               ide_port_for_each_dev(i, tdrive, hwif) {
-                       if (tdrive->dev_flags & IDE_DFLAG_PRESENT &&
-                           tdrive->dev_flags & IDE_DFLAG_PARKED &&
+               ide_port_for_each_present_dev(i, tdrive, hwif) {
+                       if ((tdrive->dev_flags & IDE_DFLAG_PARKED) &&
                            time_after(tdrive->sleep, timeout))
                                timeout = tdrive->sleep;
                }
index 5deb7e717333cd70e7c1f98d890d65bc1d44ff61..eb0a38cd83ce4ae079c77001393cef47dda55d8f 100644 (file)
@@ -825,22 +825,18 @@ static void ide_port_tune_devices(ide_hwif_t *hwif)
        ide_drive_t *drive;
        int i;
 
-       ide_port_for_each_dev(i, drive, hwif) {
-               if (drive->dev_flags & IDE_DFLAG_PRESENT) {
-                       if (port_ops && port_ops->quirkproc)
-                               port_ops->quirkproc(drive);
-               }
+       ide_port_for_each_present_dev(i, drive, hwif) {
+               if (port_ops && port_ops->quirkproc)
+                       port_ops->quirkproc(drive);
        }
 
-       ide_port_for_each_dev(i, drive, hwif) {
-               if (drive->dev_flags & IDE_DFLAG_PRESENT) {
-                       ide_set_max_pio(drive);
+       ide_port_for_each_present_dev(i, drive, hwif) {
+               ide_set_max_pio(drive);
 
-                       drive->dev_flags |= IDE_DFLAG_NICE1;
+               drive->dev_flags |= IDE_DFLAG_NICE1;
 
-                       if (hwif->dma_ops)
-                               ide_set_dma(drive);
-               }
+               if (hwif->dma_ops)
+                       ide_set_dma(drive);
        }
 }
 
@@ -911,10 +907,7 @@ static int ide_port_setup_devices(ide_hwif_t *hwif)
        int i, j = 0;
 
        mutex_lock(&ide_cfg_mtx);
-       ide_port_for_each_dev(i, drive, hwif) {
-               if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
-                       continue;
-
+       ide_port_for_each_present_dev(i, drive, hwif) {
                if (ide_init_queue(drive)) {
                        printk(KERN_ERR "ide: failed to init %s\n",
                                        drive->name);
@@ -1139,13 +1132,10 @@ static void hwif_register_devices(ide_hwif_t *hwif)
        ide_drive_t *drive;
        unsigned int i;
 
-       ide_port_for_each_dev(i, drive, hwif) {
+       ide_port_for_each_present_dev(i, drive, hwif) {
                struct device *dev = &drive->gendev;
                int ret;
 
-               if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
-                       continue;
-
                dev_set_name(dev, "%u.%u", hwif->index, i);
                dev->parent = &hwif->gendev;
                dev->bus = &ide_bus_type;
@@ -1610,11 +1600,9 @@ static void __ide_port_unregister_devices(ide_hwif_t *hwif)
        ide_drive_t *drive;
        int i;
 
-       ide_port_for_each_dev(i, drive, hwif) {
-               if (drive->dev_flags & IDE_DFLAG_PRESENT) {
-                       device_unregister(&drive->gendev);
-                       wait_for_completion(&drive->gendev_rel_comp);
-               }
+       ide_port_for_each_present_dev(i, drive, hwif) {
+               device_unregister(&drive->gendev);
+               wait_for_completion(&drive->gendev_rel_comp);
        }
 }
 
index e7b787de5286cb8bbf9306a80fe2d18e2b9bd6e7..7ed395b4b89164b0d5b596d5da7beeaecfd7465a 100644 (file)
@@ -1609,6 +1609,10 @@ static inline ide_drive_t *ide_get_pair_dev(ide_drive_t *drive)
 #define ide_port_for_each_dev(i, dev, port) \
        for ((i) = 0; ((dev) = (port)->devices[i]) || (i) < MAX_DRIVES; (i)++)
 
+#define ide_port_for_each_present_dev(i, dev, port) \
+       for ((i) = 0; ((dev) = (port)->devices[i]) || (i) < MAX_DRIVES; (i)++) \
+               if ((dev)->dev_flags & IDE_DFLAG_PRESENT)
+
 #define ide_host_for_each_port(i, port, host) \
        for ((i) = 0; ((port) = (host)->ports[i]) || (i) < MAX_HOST_PORTS; (i)++)