]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
ioat: ignore reserved bits for chancnt and xfercap
authorDan Williams <dan.j.williams@intel.com>
Tue, 8 Sep 2009 19:01:14 +0000 (12:01 -0700)
committerDan Williams <dan.j.williams@intel.com>
Wed, 9 Sep 2009 00:30:24 +0000 (17:30 -0700)
Don't trust that the reserved bits are always zero, also sanity check
the returned value.

Signed-off-by: Maciej Sosnowski <maciej.sosnowski@intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
drivers/dma/ioat/dma.c
drivers/dma/ioat/dma_v2.c

index 08417ad4edca42cbc0589a60d5148c5902367921..5173ba97ba317f4bdc76388d851faba3b98691b9 100644 (file)
@@ -132,7 +132,14 @@ static int ioat1_enumerate_channels(struct ioatdma_device *device)
 
        INIT_LIST_HEAD(&dma->channels);
        dma->chancnt = readb(device->reg_base + IOAT_CHANCNT_OFFSET);
+       dma->chancnt &= 0x1f; /* bits [4:0] valid */
+       if (dma->chancnt > ARRAY_SIZE(device->idx)) {
+               dev_warn(dev, "(%d) exceeds max supported channels (%zu)\n",
+                        dma->chancnt, ARRAY_SIZE(device->idx));
+               dma->chancnt = ARRAY_SIZE(device->idx);
+       }
        xfercap_scale = readb(device->reg_base + IOAT_XFERCAP_OFFSET);
+       xfercap_scale &= 0x1f; /* bits [4:0] valid */
        xfercap = (xfercap_scale == 0 ? -1 : (1UL << xfercap_scale));
        dev_dbg(dev, "%s: xfercap = %d\n", __func__, xfercap);
 
index ca11342493419ea57e9525058b64d8f913e3426a..137cf879265fa8cae52c2f5ee8049ab4f43ae0c7 100644 (file)
@@ -359,7 +359,14 @@ static int ioat2_enumerate_channels(struct ioatdma_device *device)
 
        INIT_LIST_HEAD(&dma->channels);
        dma->chancnt = readb(device->reg_base + IOAT_CHANCNT_OFFSET);
+       dma->chancnt &= 0x1f; /* bits [4:0] valid */
+       if (dma->chancnt > ARRAY_SIZE(device->idx)) {
+               dev_warn(dev, "(%d) exceeds max supported channels (%zu)\n",
+                        dma->chancnt, ARRAY_SIZE(device->idx));
+               dma->chancnt = ARRAY_SIZE(device->idx);
+       }
        xfercap_log = readb(device->reg_base + IOAT_XFERCAP_OFFSET);
+       xfercap_log &= 0x1f; /* bits [4:0] valid */
        if (xfercap_log == 0)
                return 0;
        dev_dbg(dev, "%s: xfercap = %d\n", __func__, 1 << xfercap_log);