libata-link: implement and use link/device iterators
Multiple links and different number of devices per link should be
considered to iterate over links and devices. This patch implements
and uses link and device iterators - ata_port_for_each_link() and
ata_link_for_each_dev() - and ata_link_max_devices().
This change makes a lot of functions iterate over only possible
devices instead of from dev 0 to dev ATA_MAX_DEVICES. All such
changes have been examined and nothing should be broken.
While at it, add a separating comment before device helpers to
distinguish them better from link helpers and others.
Signed-off-by: Tejun Heo <htejun@gmail.com>
Signed-off-by: Jeff Garzik <jeff@garzik.org>
diff --git a/drivers/ata/pata_pdc2027x.c b/drivers/ata/pata_pdc2027x.c
index fa78050..83c90ca 100644
--- a/drivers/ata/pata_pdc2027x.c
+++ b/drivers/ata/pata_pdc2027x.c
@@ -479,15 +479,14 @@
*/
static int pdc2027x_set_mode(struct ata_port *ap, struct ata_device **r_failed)
{
- int i;
+ struct ata_device *dev;
+ int rc;
- i = ata_do_set_mode(ap, r_failed);
- if (i < 0)
- return i;
+ rc = ata_do_set_mode(ap, r_failed);
+ if (rc < 0)
+ return rc;
- for (i = 0; i < ATA_MAX_DEVICES; i++) {
- struct ata_device *dev = &ap->link.device[i];
-
+ ata_link_for_each_dev(dev, &ap->link) {
if (ata_dev_enabled(dev)) {
pdc2027x_set_piomode(ap, dev);