Skip to contentSkip to conversation

Virtio: Fine-tuning for two function implementations

PATCH In review SF Markus Elfring 2 participants 7 messages Jan 26, 2017 – Feb 3, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Virtio: Fine-tuning for two function implementations

From: Markus Elfring <[email protected]>
Date: Thu, 26 Jan 2017 22:40:02 +0100

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (3):
virtio_pci: Use kcalloc() in vp_request_msix_vectors()
virtio_pci: Use kmalloc_array() in vp_request_msix_vectors()
virtio_ring: Use kmalloc_array() in alloc_indirect()

 drivers/virtio/virtio_pci_common.c | 8 ++++----
 drivers/virtio/virtio_ring.c       | 3 +--
 2 files changed, 5 insertions(+), 6 deletions(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH 1/3 virtio_pci: Use kcalloc() in vp_request_msix_vectors()

From: Markus Elfring <[email protected]>
Date: Thu, 26 Jan 2017 22:10:18 +0100

A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus reuse the corresponding function "kcalloc".

This issue was detected by using the Coccinelle software.

---
 drivers/virtio/virtio_pci_common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/virtio/virtio_pci_common.c +1 -1
index 186cbab327b8..559a2b706093 100644
@@ -117,7 +117,7 @@ static int vp_request_msix_vectors(struct virtio_device *vdev, int nvectors,
 	if (!vp_dev->msix_names)
 		goto error;
 	vp_dev->msix_affinity_masks
-		= kzalloc(nvectors * sizeof *vp_dev->msix_affinity_masks,
+		= kcalloc(nvectors, sizeof(*vp_dev->msix_affinity_masks),
 			  GFP_KERNEL);
 	if (!vp_dev->msix_affinity_masks)
 		goto error;
Signature · 1 line
2.11.0
#2 lore raw

PATCH 1/3 virtio_pci: Use kcalloc() in vp_request_msix_vectors()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 26 Jan 2017 22:10:18 +0100

A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus reuse the corresponding function "kcalloc".

This issue was detected by using the Coccinelle software.

---
 drivers/virtio/virtio_pci_common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/virtio/virtio_pci_common.c +1 -1
index 186cbab327b8..559a2b706093 100644
@@ -117,7 +117,7 @@ static int vp_request_msix_vectors(struct virtio_device *vdev, int nvectors,
 	if (!vp_dev->msix_names)
 		goto error;
 	vp_dev->msix_affinity_masks
-		= kzalloc(nvectors * sizeof *vp_dev->msix_affinity_masks,
+		= kcalloc(nvectors, sizeof(*vp_dev->msix_affinity_masks),
 			  GFP_KERNEL);
 	if (!vp_dev->msix_affinity_masks)
 		goto error;
Signature · 1 line
2.11.0
#3 lore raw

PATCH 2/3 virtio_pci: Use kmalloc_array() in vp_request_msix_vectors()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 26 Jan 2017 22:20:30 +0100

A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus reuse the corresponding function "kmalloc_array".

This issue was detected by using the Coccinelle software.

---
 drivers/virtio/virtio_pci_common.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/virtio/virtio_pci_common.c +3 -3
index 559a2b706093..623a8cea1441 100644
@@ -111,9 +111,9 @@ static int vp_request_msix_vectors(struct virtio_device *vdev, int nvectors,
 	int err = -ENOMEM;
 
 	vp_dev->msix_vectors = nvectors;
-
-	vp_dev->msix_names = kmalloc(nvectors * sizeof *vp_dev->msix_names,
-				     GFP_KERNEL);
+	vp_dev->msix_names = kmalloc_array(nvectors,
+					   sizeof(*vp_dev->msix_names),
+					   GFP_KERNEL);
 	if (!vp_dev->msix_names)
 		goto error;
 	vp_dev->msix_affinity_masks
Signature · 1 line
2.11.0
#4 lore raw

PATCH 3/3 virtio_ring: Use kmalloc_array() in alloc_indirect()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 26 Jan 2017 22:30:45 +0100

* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".

This issue was detected by using the Coccinelle software.

* Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 drivers/virtio/virtio_ring.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/virtio/virtio_ring.c +1 -2
index 409aeaa49246..34b6b694298c 100644
@@ -247,8 +247,7 @@ static struct vring_desc *alloc_indirect(struct virtqueue *_vq,
 	 * virtqueue.
 	 */
 	gfp &= ~__GFP_HIGHMEM;
-
-	desc = kmalloc(total_sg * sizeof(struct vring_desc), gfp);
+	desc = kmalloc_array(total_sg, sizeof(*desc), gfp);
 	if (!desc)
 		return NULL;
 
Signature · 1 line
2.11.0
#5 lore raw

PATCH 3/3 virtio_ring: Use kmalloc_array() in alloc_indirect()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 26 Jan 2017 22:30:45 +0100

* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".

This issue was detected by using the Coccinelle software.

* Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 drivers/virtio/virtio_ring.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/virtio/virtio_ring.c +1 -2
index 409aeaa49246..34b6b694298c 100644
@@ -247,8 +247,7 @@ static struct vring_desc *alloc_indirect(struct virtqueue *_vq,
 	 * virtqueue.
 	 */
 	gfp &= ~__GFP_HIGHMEM;
-
-	desc = kmalloc(total_sg * sizeof(struct vring_desc), gfp);
+	desc = kmalloc_array(total_sg, sizeof(*desc), gfp);
 	if (!desc)
 		return NULL;
 
Signature · 1 line
2.11.0
Acked-by on the v1 series
#6 lore raw
In reply to SF Markus Elfring
Quoted 6 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 26 Jan 2017 22:40:02 +0100

A few update suggestions were taken into account
from static source code analysis.

Quoted 9 lines

Markus Elfring (3):
virtio_pci: Use kcalloc() in vp_request_msix_vectors()
virtio_pci: Use kmalloc_array() in vp_request_msix_vectors()
virtio_ring: Use kmalloc_array() in alloc_indirect()

  drivers/virtio/virtio_pci_common.c | 8 ++++----
  drivers/virtio/virtio_ring.c       | 3 +--
  2 files changed, 5 insertions(+), 6 deletions(-)