linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: SF Markus Elfring <elfring@users.sourceforge.net>
To: netdev@vger.kernel.org, Alexey Dobriyan <adobriyan@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Harald Welte <laforge@gnumonks.org>,
	Johannes Berg <johannes.berg@intel.com>,
	Pablo Neira <pablo@netfilter.org>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH 1/5] gtp: Use kmalloc_array() in gtp_hashtable_new()
Date: Thu, 26 Jan 2017 11:17:05 +0100	[thread overview]
Message-ID: <b723e4d3-222b-6dd1-0223-2398536e4d1c@users.sourceforge.net> (raw)
In-Reply-To: <698070a4-e08e-78e5-0214-df69783cce22@users.sourceforge.net>

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 25 Jan 2017 22:01:00 +0100

* Multiplications for the size determination of memory allocations
  indicated that array data structures should be processed.
  Thus use the corresponding function "kmalloc_array".

  This issue was detected by using the Coccinelle software.

* Replace the specification of data structures by pointer dereferences
  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/net/gtp.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c
index 8b6810bad54b..5d0d520ae40f 100644
--- a/drivers/net/gtp.c
+++ b/drivers/net/gtp.c
@@ -783,11 +783,13 @@ static int gtp_hashtable_new(struct gtp_dev *gtp, int hsize)
 {
 	int i;
 
-	gtp->addr_hash = kmalloc(sizeof(struct hlist_head) * hsize, GFP_KERNEL);
+	gtp->addr_hash = kmalloc_array(hsize, sizeof(*gtp->addr_hash),
+				       GFP_KERNEL);
 	if (gtp->addr_hash == NULL)
 		return -ENOMEM;
 
-	gtp->tid_hash = kmalloc(sizeof(struct hlist_head) * hsize, GFP_KERNEL);
+	gtp->tid_hash = kmalloc_array(hsize, sizeof(*gtp->tid_hash),
+				      GFP_KERNEL);
 	if (gtp->tid_hash == NULL)
 		goto err1;
 
-- 
2.11.0

  reply	other threads:[~2017-01-26 10:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-26 10:15 [PATCH 0/5] GTP: Fine-tuning for some function implementations SF Markus Elfring
2017-01-26 10:17 ` SF Markus Elfring [this message]
2017-01-26 10:18 ` [PATCH 2/5] gtp: Improve another size determination in ipv4_pdp_add() SF Markus Elfring
2017-01-26 13:11   ` Alexey Dobriyan
2017-01-26 10:19 ` [PATCH 3/5] gtp: Adjust 12 checks for null pointers SF Markus Elfring
2017-01-26 10:20 ` [PATCH 4/5] gtp: Rename jump labels in gtp_encap_enable() SF Markus Elfring
2017-01-26 10:22 ` [PATCH 5/5] gtp: Rename jump labels in gtp_hashtable_new() SF Markus Elfring
2017-01-26 11:14 ` [PATCH 0/5] GTP: Fine-tuning for some function implementations Andreas Schultz

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=b723e4d3-222b-6dd1-0223-2398536e4d1c@users.sourceforge.net \
    --to=elfring@users.sourceforge.net \
    --cc=adobriyan@gmail.com \
    --cc=davem@davemloft.net \
    --cc=johannes.berg@intel.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=laforge@gnumonks.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pablo@netfilter.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;
as well as URLs for NNTP newsgroup(s).