treewide: kmalloc() -> kmalloc_array()
[linux-block.git] / drivers / char / virtio_console.c
index 21085515814f23f09e6fbea4cb49d4d3d99d86c7..17084cfcf53ecdbcbf83f5efec201384da70aaa1 100644 (file)
@@ -433,8 +433,7 @@ static struct port_buffer *alloc_buf(struct virtio_device *vdev, size_t buf_size
         * Allocate buffer and the sg list. The sg list array is allocated
         * directly after the port_buffer struct.
         */
-       buf = kmalloc(sizeof(*buf) + sizeof(struct scatterlist) * pages,
-                     GFP_KERNEL);
+       buf = kmalloc(struct_size(buf, sg, pages), GFP_KERNEL);
        if (!buf)
                goto fail;
 
@@ -1892,13 +1891,14 @@ static int init_vqs(struct ports_device *portdev)
        nr_ports = portdev->max_nr_ports;
        nr_queues = use_multiport(portdev) ? (nr_ports + 1) * 2 : 2;
 
-       vqs = kmalloc(nr_queues * sizeof(struct virtqueue *), GFP_KERNEL);
-       io_callbacks = kmalloc(nr_queues * sizeof(vq_callback_t *), GFP_KERNEL);
-       io_names = kmalloc(nr_queues * sizeof(char *), GFP_KERNEL);
-       portdev->in_vqs = kmalloc(nr_ports * sizeof(struct virtqueue *),
-                                 GFP_KERNEL);
-       portdev->out_vqs = kmalloc(nr_ports * sizeof(struct virtqueue *),
-                                  GFP_KERNEL);
+       vqs = kmalloc_array(nr_queues, sizeof(struct virtqueue *), GFP_KERNEL);
+       io_callbacks = kmalloc_array(nr_queues, sizeof(vq_callback_t *),
+                                    GFP_KERNEL);
+       io_names = kmalloc_array(nr_queues, sizeof(char *), GFP_KERNEL);
+       portdev->in_vqs = kmalloc_array(nr_ports, sizeof(struct virtqueue *),
+                                       GFP_KERNEL);
+       portdev->out_vqs = kmalloc_array(nr_ports, sizeof(struct virtqueue *),
+                                        GFP_KERNEL);
        if (!vqs || !io_callbacks || !io_names || !portdev->in_vqs ||
            !portdev->out_vqs) {
                err = -ENOMEM;