mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: SF Markus Elfring <elfring@users.sourceforge.net>
To: virtualization@lists.linux-foundation.org,
	Jason Wang <jasowang@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH 3/3] virtio_ring: Use kmalloc_array() in alloc_indirect()
Date: Thu, 26 Jan 2017 22:47:59 +0100	[thread overview]
Message-ID: <a460744a-0fec-4a47-c98a-42b88ddada64@users.sourceforge.net> (raw)
In-Reply-To: <61829748-a13d-42e4-8f6c-103ee5ca2c88@users.sourceforge.net>

From: Markus Elfring <elfring@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@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

  parent reply	other threads:[~2017-01-26 21:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-26 21:44 [PATCH 0/3] Virtio: Fine-tuning for two function implementations SF Markus Elfring
2017-01-26 21:46 ` [PATCH 1/3] virtio_pci: Use kcalloc() in vp_request_msix_vectors() SF Markus Elfring
2017-01-26 21:46 ` [PATCH 2/3] virtio_pci: Use kmalloc_array() " SF Markus Elfring
2017-01-26 21:47 ` SF Markus Elfring [this message]
2017-02-03  2:57 ` [PATCH 0/3] Virtio: Fine-tuning for two function implementations Jason Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a460744a-0fec-4a47-c98a-42b88ddada64@users.sourceforge.net \
    --to=elfring@users.sourceforge.net \
    --cc=jasowang@redhat.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=virtualization@lists.linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome