Thread (6 messages) flat view 6 messages, 2 authors, 2016-07-26
STALE3680d

Revision v2 of 2 in this series.

Revisions (2)
  1. v1 [diff vs current]
  2. v2 current

[PATCH net-next v2 3/3] virtio: use kcalloc and kmalloc_array

From: Stephen Hemminger <stephen@networkplumber.org>
Date: 2016-07-26 16:37:32

Preferred style is to use kcalloc and kmalloc_array.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
--- a/drivers/net/virtio_net.c	2016-07-26 09:28:21.401557546 -0700
+++ b/drivers/net/virtio_net.c	2016-07-26 09:36:05.107695337 -0700
@@ -1551,13 +1551,13 @@ static int virtnet_find_vqs(struct virtn
 		    virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ);
 
 	/* Allocate space for find_vqs parameters */
-	vqs = kzalloc(total_vqs * sizeof(*vqs), GFP_KERNEL);
+	vqs = kcalloc(total_vqs, sizeof(*vqs), GFP_KERNEL);
 	if (!vqs)
 		goto err_vq;
-	callbacks = kmalloc(total_vqs * sizeof(*callbacks), GFP_KERNEL);
+	callbacks = kmalloc_array(total_vqs, sizeof(*callbacks), GFP_KERNEL);
 	if (!callbacks)
 		goto err_callback;
-	names = kmalloc(total_vqs * sizeof(*names), GFP_KERNEL);
+	names = kmalloc_array(total_vqs, sizeof(*names), GFP_KERNEL);
 	if (!names)
 		goto err_names;
 
@@ -1613,10 +1613,10 @@ static int virtnet_alloc_queues(struct v
 {
 	int i;
 
-	vi->sq = kzalloc(sizeof(*vi->sq) * vi->max_queue_pairs, GFP_KERNEL);
+	vi->sq = kcalloc(vi->max_queue_pairs, sizeof(*vi->sq), GFP_KERNEL);
 	if (!vi->sq)
 		goto err_sq;
-	vi->rq = kzalloc(sizeof(*vi->rq) * vi->max_queue_pairs, GFP_KERNEL);
+	vi->rq = kcalloc(vi->max_queue_pairs, sizeof(*vi->rq), GFP_KERNEL);
 	if (!vi->rq)
 		goto err_rq;
 
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help