Virtio: Fine-tuning for two function implementations
Subsystems (2)
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
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
@@ -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
PATCH 1/3 virtio_pci: Use kcalloc() in vp_request_msix_vectors()
In reply to SF Markus ElfringFrom: 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
@@ -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
PATCH 2/3 virtio_pci: Use kmalloc_array() in vp_request_msix_vectors()
In reply to SF Markus ElfringFrom: 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
@@ -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
PATCH 3/3 virtio_ring: Use kmalloc_array() in alloc_indirect()
In reply to SF Markus ElfringFrom: 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
@@ -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
PATCH 3/3 virtio_ring: Use kmalloc_array() in alloc_indirect()
In reply to SF Markus ElfringFrom: 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
@@ -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
Quoted 6 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Thu, 26 Jan 2017 22:40:02 +0100A few update suggestions were taken into account
from static source code analysis.
Quoted 9 lines
Markus Elfring (3):
virtio_pci: Usekcalloc()invp_request_msix_vectors()
virtio_pci: Usekmalloc_array()invp_request_msix_vectors()
virtio_ring: Usekmalloc_array()inalloc_indirect()drivers/virtio/virtio_pci_common.c | 8 ++++---- drivers/virtio/virtio_ring.c | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-)