ide: check drive->present in ide_get_paired_drive()
authorBartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Fri, 10 Oct 2008 20:39:26 +0000 (22:39 +0200)
committerBartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Fri, 10 Oct 2008 20:39:26 +0000 (22:39 +0200)
* Change ide_get_paired_drive() to return NULL if peer device
  is not present and update all users accordingly.

While at it:

* ide_get_paired_drive() -> ide_get_pair_dev()

* Use ide_get_pair_dev() in cs5530.c, sc1200.c and via82cxxx.c.

There should be no functional changes caused by this patch.

Acked-by: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
drivers/ide/arm/palm_bk3710.c
drivers/ide/pci/cs5530.c
drivers/ide/pci/cs5535.c
drivers/ide/pci/opti621.c
drivers/ide/pci/sc1200.c
drivers/ide/pci/siimage.c
drivers/ide/pci/via82cxxx.c
include/linux/ide.h

index 6cea984776fd975fb1aa8aa1937b598075fedf72..320971c78cb7e7521f3134d9bb30da849f618131 100644 (file)
@@ -180,7 +180,7 @@ static void palm_bk3710_setpiomode(void __iomem *base, ide_drive_t *mate,
        val32 |= (t2i << (dev ? 8 : 0));
        writel(val32, base + BK3710_DATRCVR);
 
-       if (mate && mate->present) {
+       if (mate) {
                u8 mode2 = ide_get_best_pio_mode(mate, 255, 4);
 
                if (mode2 < mode)
@@ -230,7 +230,7 @@ static void palm_bk3710_set_pio_mode(ide_drive_t *drive, u8 pio)
         * Obtain the drive PIO data for tuning the Palm Chip registers
         */
        cycle_time = ide_pio_cycle_time(drive, pio);
-       mate = ide_get_paired_drive(drive);
+       mate = ide_get_pair_dev(drive);
        palm_bk3710_setpiomode(base, mate, is_slave, cycle_time, pio);
 }
 
index ef91e9d7c54f130d2bdb85b0e91a9fe0eb8f8f1d..804ecabbd65f023a66b5cacb6ad40daaa623c179 100644 (file)
@@ -81,11 +81,11 @@ static void cs5530_set_pio_mode(ide_drive_t *drive, const u8 pio)
 static u8 cs5530_udma_filter(ide_drive_t *drive)
 {
        ide_hwif_t *hwif = drive->hwif;
-       ide_drive_t *mate = &hwif->drives[(drive->dn & 1) ^ 1];
+       ide_drive_t *mate = ide_get_pair_dev(drive);
        u16 *mateid = mate->id;
        u8 mask = hwif->ultra_mask;
 
-       if (mate->present == 0)
+       if (mate == NULL)
                goto out;
 
        if (ata_id_has_dma(mateid) && __ide_dma_bad_drive(mate) == 0) {
index dd3dc23af9951c0c705c9e324a9fc33c2380fb09..707d2e1825528a5b1219e51e6e9258f16d52616d 100644 (file)
@@ -80,12 +80,12 @@ static void cs5535_set_speed(ide_drive_t *drive, const u8 speed)
 
        /* Set the PIO timings */
        if (speed < XFER_SW_DMA_0) {
-               ide_drive_t *pair = ide_get_paired_drive(drive);
+               ide_drive_t *pair = ide_get_pair_dev(drive);
                u8 cmd, pioa;
 
                cmd = pioa = speed - XFER_PIO_0;
 
-               if (pair->present) {
+               if (pair) {
                        u8 piob = ide_get_best_pio_mode(pair, 255, 4);
 
                        if (piob < cmd)
index e28e672ddafcf9dd5cd940792f4961cc82f179c5..e913da479808fc28bccaebeaa163e522e13844aa 100644 (file)
@@ -137,7 +137,7 @@ static u8 read_reg(int reg)
 static void opti621_set_pio_mode(ide_drive_t *drive, const u8 pio)
 {
        ide_hwif_t *hwif = drive->hwif;
-       ide_drive_t *pair = ide_get_paired_drive(drive);
+       ide_drive_t *pair = ide_get_pair_dev(drive);
        unsigned long flags;
        u8 tim, misc, addr_pio = pio, clk;
 
@@ -153,7 +153,7 @@ static void opti621_set_pio_mode(ide_drive_t *drive, const u8 pio)
 
        drive->drive_data = XFER_PIO_0 + pio;
 
-       if (pair->present) {
+       if (pair) {
                if (pair->drive_data && pair->drive_data < drive->drive_data)
                        addr_pio = pair->drive_data - XFER_PIO_0;
        }
index 695cc9742048b256d90cd50909066348e4209006..37326d2205b868348b86584097918c10d84e0a97 100644 (file)
@@ -104,11 +104,11 @@ static void sc1200_tunepio(ide_drive_t *drive, u8 pio)
 static u8 sc1200_udma_filter(ide_drive_t *drive)
 {
        ide_hwif_t *hwif = drive->hwif;
-       ide_drive_t *mate = &hwif->drives[(drive->dn & 1) ^ 1];
+       ide_drive_t *mate = ide_get_pair_dev(drive);
        u16 *mateid = mate->id;
        u8 mask = hwif->ultra_mask;
 
-       if (mate->present == 0)
+       if (mate == NULL)
                goto out;
 
        if (ata_id_has_dma(mateid) && __ide_dma_bad_drive(mate) == 0) {
index 7b5bd8729f646c9ed5cacf2c51586c3754af0097..83c36e6035faca1eba4d52159d19cbe0703aa3bf 100644 (file)
@@ -245,7 +245,7 @@ static void sil_set_pio_mode(ide_drive_t *drive, u8 pio)
 
        ide_hwif_t *hwif        = HWIF(drive);
        struct pci_dev *dev     = to_pci_dev(hwif->dev);
-       ide_drive_t *pair       = ide_get_paired_drive(drive);
+       ide_drive_t *pair       = ide_get_pair_dev(drive);
        u32 speedt              = 0;
        u16 speedp              = 0;
        unsigned long addr      = siimage_seldev(drive, 0x04);
@@ -259,7 +259,7 @@ static void sil_set_pio_mode(ide_drive_t *drive, u8 pio)
        u8 unit                 = drive->select.b.unit;
 
        /* trim *taskfile* PIO to the slowest of the master/slave */
-       if (pair->present) {
+       if (pair) {
                u8 pair_pio = ide_get_best_pio_mode(pair, 255, 4);
 
                if (pair_pio < tf_pio)
index 94fb9ab3223f8ff61088bd32fb40087610a96381..9cb531dc905ae242feba375fd1f987502e631a1d 100644 (file)
@@ -154,7 +154,7 @@ static void via_set_speed(ide_hwif_t *hwif, u8 dn, struct ide_timing *timing)
 static void via_set_drive(ide_drive_t *drive, const u8 speed)
 {
        ide_hwif_t *hwif = drive->hwif;
-       ide_drive_t *peer = hwif->drives + (~drive->dn & 1);
+       ide_drive_t *peer = ide_get_pair_dev(drive);
        struct pci_dev *dev = to_pci_dev(hwif->dev);
        struct ide_host *host = pci_get_drvdata(dev);
        struct via82cxxx_dev *vdev = host->host_priv;
@@ -173,7 +173,7 @@ static void via_set_drive(ide_drive_t *drive, const u8 speed)
 
        ide_timing_compute(drive, speed, &t, T, UT);
 
-       if (peer->present) {
+       if (peer) {
                ide_timing_compute(peer, peer->current_speed, &p, T, UT);
                ide_timing_merge(&p, &t, &t, IDE_TIMING_8BIT);
        }
index a9206c463d7d920c2c8c52e1d2e1884c8ffa478a..1d9716a95dc4d878adf41ae5c892ced40bb8b870 100644 (file)
@@ -1450,10 +1450,10 @@ static inline int hwif_to_node(ide_hwif_t *hwif)
        return hwif->dev ? dev_to_node(hwif->dev) : -1;
 }
 
-static inline ide_drive_t *ide_get_paired_drive(ide_drive_t *drive)
+static inline ide_drive_t *ide_get_pair_dev(ide_drive_t *drive)
 {
-       ide_hwif_t *hwif        = HWIF(drive);
+       ide_drive_t *peer = &drive->hwif->drives[(drive->dn ^ 1) & 1];
 
-       return &hwif->drives[(drive->dn ^ 1) & 1];
+       return peer->present ? peer : NULL;
 }
 #endif /* _IDE_H */