SF Markus Elfring
2017-Jan-26 21:44 UTC
[PATCH 0/3] Virtio: Fine-tuning for two function implementations
From: Markus Elfring <elfring at users.sourceforge.net> 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(-) -- 2.11.0
SF Markus Elfring
2017-Jan-26 21:46 UTC
[PATCH 1/3] virtio_pci: Use kcalloc() in vp_request_msix_vectors()
From: Markus Elfring <elfring at users.sourceforge.net> 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. Signed-off-by: Markus Elfring <elfring at users.sourceforge.net> --- drivers/virtio/virtio_pci_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c index 186cbab327b8..559a2b706093 100644 --- a/drivers/virtio/virtio_pci_common.c +++ b/drivers/virtio/virtio_pci_common.c @@ -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; -- 2.11.0
SF Markus Elfring
2017-Jan-26 21:46 UTC
[PATCH 2/3] virtio_pci: Use kmalloc_array() in vp_request_msix_vectors()
From: Markus Elfring <elfring at users.sourceforge.net> 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. Signed-off-by: Markus Elfring <elfring at users.sourceforge.net> --- drivers/virtio/virtio_pci_common.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c index 559a2b706093..623a8cea1441 100644 --- a/drivers/virtio/virtio_pci_common.c +++ b/drivers/virtio/virtio_pci_common.c @@ -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 -- 2.11.0
SF Markus Elfring
2017-Jan-26 21:47 UTC
[PATCH 3/3] virtio_ring: Use kmalloc_array() in alloc_indirect()
From: Markus Elfring <elfring at users.sourceforge.net> 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. Signed-off-by: Markus Elfring <elfring at users.sourceforge.net> --- drivers/virtio/virtio_ring.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 409aeaa49246..34b6b694298c 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -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; -- 2.11.0
Jason Wang
2017-Feb-03 02:57 UTC
[PATCH 0/3] Virtio: Fine-tuning for two function implementations
On 2017?01?27? 05:44, SF Markus Elfring wrote:> From: Markus Elfring <elfring at users.sourceforge.net> > 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(-) >Acked-by: Jason Wang <jasowang at redhat.com>