video: tegra: host: fix integer overflows
[linux-2.6.git] / drivers / block / sunvdc.c
index 317a790..48e8fee 100644 (file)
@@ -1,6 +1,6 @@
 /* sunvdc.c: Sun LDOM Virtual Disk Client.
  *
- * Copyright (C) 2007 David S. Miller <davem@davemloft.net>
+ * Copyright (C) 2007, 2008 David S. Miller <davem@davemloft.net>
  */
 
 #include <linux/module.h>
@@ -15,6 +15,7 @@
 #include <linux/delay.h>
 #include <linux/init.h>
 #include <linux/list.h>
+#include <linux/scatterlist.h>
 
 #include <asm/vio.h>
 #include <asm/ldc.h>
@@ -102,7 +103,7 @@ static int vdc_getgeo(struct block_device *bdev, struct hd_geometry *geo)
        return 0;
 }
 
-static struct block_device_operations vdc_fops = {
+static const struct block_device_operations vdc_fops = {
        .owner          = THIS_MODULE,
        .getgeo         = vdc_getgeo,
 };
@@ -152,7 +153,7 @@ static int vdc_send_attr(struct vio_driver_state *vio)
        pkt.vdisk_block_size = port->vdisk_block_size;
        pkt.max_xfer_size = port->max_xfer_size;
 
-       viodbg(HS, "SEND ATTR xfer_mode[0x%x] blksz[%u] max_xfer[%lu]\n",
+       viodbg(HS, "SEND ATTR xfer_mode[0x%x] blksz[%u] max_xfer[%llu]\n",
               pkt.xfer_mode, pkt.vdisk_block_size, pkt.max_xfer_size);
 
        return vio_ldc_send(&port->vio, &pkt, sizeof(pkt));
@@ -163,8 +164,8 @@ static int vdc_handle_attr(struct vio_driver_state *vio, void *arg)
        struct vdc_port *port = to_vdc_port(vio);
        struct vio_disk_attr_info *pkt = arg;
 
-       viodbg(HS, "GOT ATTR stype[0x%x] ops[%lx] disk_size[%lu] disk_type[%x] "
-              "xfer_mode[0x%x] blksz[%u] max_xfer[%lu]\n",
+       viodbg(HS, "GOT ATTR stype[0x%x] ops[%llx] disk_size[%llu] disk_type[%x] "
+              "xfer_mode[0x%x] blksz[%u] max_xfer[%llu]\n",
               pkt->tag.stype, pkt->operations,
               pkt->vdisk_size, pkt->vdisk_type,
               pkt->xfer_mode, pkt->vdisk_block_size,
@@ -211,14 +212,6 @@ static void vdc_end_special(struct vdc_port *port, struct vio_disk_desc *desc)
        vdc_finish(&port->vio, -err, WAITING_FOR_GEN_CMD);
 }
 
-static void vdc_end_request(struct request *req, int uptodate, int num_sectors)
-{
-       if (end_that_request_first(req, uptodate, num_sectors))
-               return;
-       add_disk_randomness(req->rq_disk);
-       end_that_request_last(req, uptodate);
-}
-
 static void vdc_end_one(struct vdc_port *port, struct vio_dring_state *dr,
                        unsigned int index)
 {
@@ -241,7 +234,7 @@ static void vdc_end_one(struct vdc_port *port, struct vio_dring_state *dr,
 
        rqe->req = NULL;
 
-       vdc_end_request(req, !desc->status, desc->size >> 9);
+       __blk_end_request(req, (desc->status ? -EIO : 0), desc->size);
 
        if (blk_queue_stopped(port->disk->queue))
                blk_start_queue(port->disk->queue);
@@ -388,6 +381,7 @@ static int __send_request(struct request *req)
                op = VD_OP_BWRITE;
        }
 
+       sg_init_table(sg, port->ring_cookies);
        nsg = blk_rq_map_sg(req->q, req, sg);
 
        len = 0;
@@ -422,7 +416,7 @@ static int __send_request(struct request *req)
                desc->slice = 0;
        }
        desc->status = ~0;
-       desc->offset = (req->sector << 9) / port->vdisk_block_size;
+       desc->offset = (blk_rq_pos(req) << 9) / port->vdisk_block_size;
        desc->size = len;
        desc->ncookies = err;
 
@@ -447,14 +441,13 @@ out:
 static void do_vdc_request(struct request_queue *q)
 {
        while (1) {
-               struct request *req = elv_next_request(q);
+               struct request *req = blk_fetch_request(q);
 
                if (!req)
                        break;
 
-               blkdev_dequeue_request(req);
                if (__send_request(req) < 0)
-                       vdc_end_request(req, 0, req->hard_nr_sectors);
+                       __blk_end_request_all(req, -EIO);
        }
 }
 
@@ -698,9 +691,8 @@ static int probe_disk(struct vdc_port *port)
 
        port->disk = g;
 
-       blk_queue_max_hw_segments(q, port->ring_cookies);
-       blk_queue_max_phys_segments(q, port->ring_cookies);
-       blk_queue_max_sectors(q, port->max_xfer_size);
+       blk_queue_max_segments(q, port->ring_cookies);
+       blk_queue_max_hw_sectors(q, port->max_xfer_size);
        g->major = vdc_major;
        g->first_minor = port->vio.vdev->dev_no << PARTITION_SHIFT;
        strcpy(g->disk_name, port->disk_name);
@@ -733,7 +725,7 @@ static struct vio_driver_ops vdc_vio_ops = {
        .handshake_complete     = vdc_handshake_complete,
 };
 
-static void print_version(void)
+static void __devinit print_version(void)
 {
        static int version_printed;
 
@@ -754,7 +746,7 @@ static int __devinit vdc_port_probe(struct vio_dev *vdev,
 
        err = -ENODEV;
        if ((vdev->dev_no << PARTITION_SHIFT) & ~(u64)MINORMASK) {
-               printk(KERN_ERR PFX "Port id [%lu] too large.\n",
+               printk(KERN_ERR PFX "Port id [%llu] too large.\n",
                       vdev->dev_no);
                goto err_out_release_mdesc;
        }
@@ -835,7 +827,7 @@ static int vdc_port_remove(struct vio_dev *vdev)
        return 0;
 }
 
-static struct vio_device_id vdc_port_match[] = {
+static const struct vio_device_id vdc_port_match[] = {
        {
                .type = "vdc-port",
        },