All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Rob Springer <rspringer@google.com>,
	John Joseph <jnjoseph@google.com>,
	Ben Chan <benchan@chromium.org>,
	devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org
Subject: [PATCH] drivers/staging/gasket: Use 2-factor allocator calls
Date: Wed, 4 Jul 2018 10:31:25 -0700	[thread overview]
Message-ID: <20180704173125.GA34354@beast> (raw)

As already done treewide, switch from open-coded multiplication to using
2-factor allocator helpers.

Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/staging/gasket/gasket_core.c       |  6 +++---
 drivers/staging/gasket/gasket_interrupt.c  | 15 +++++++++------
 drivers/staging/gasket/gasket_page_table.c |  6 +++---
 drivers/staging/gasket/gasket_sysfs.c      | 12 ++++++------
 4 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/drivers/staging/gasket/gasket_core.c b/drivers/staging/gasket/gasket_core.c
index 6511a33eb658..82b3eca7774e 100644
--- a/drivers/staging/gasket/gasket_core.c
+++ b/drivers/staging/gasket/gasket_core.c
@@ -1697,9 +1697,9 @@ static int gasket_mmap(struct file *filp, struct vm_area_struct *vma)
 			return -EPERM;
 		}
 		num_map_regions = bar_desc->num_mappable_regions;
-		map_regions = kzalloc(
-			num_map_regions * sizeof(*bar_desc->mappable_regions),
-			GFP_KERNEL);
+		map_regions = kcalloc(num_map_regions,
+				      sizeof(*bar_desc->mappable_regions),
+				      GFP_KERNEL);
 		if (map_regions) {
 			memcpy(map_regions, bar_desc->mappable_regions,
 			       num_map_regions *
diff --git a/drivers/staging/gasket/gasket_interrupt.c b/drivers/staging/gasket/gasket_interrupt.c
index b74eefe41d72..1fd7bee5db2f 100644
--- a/drivers/staging/gasket/gasket_interrupt.c
+++ b/drivers/staging/gasket/gasket_interrupt.c
@@ -136,23 +136,26 @@ int gasket_interrupt_init(
 	interrupt_data->wire_interrupt_offsets = wire_int_offsets;
 
 	/* Allocate all dynamic structures. */
-	interrupt_data->msix_entries = kzalloc(
-		sizeof(struct msix_entry) * num_interrupts, GFP_KERNEL);
+	interrupt_data->msix_entries = kcalloc(num_interrupts,
+					       sizeof(struct msix_entry),
+					       GFP_KERNEL);
 	if (!interrupt_data->msix_entries) {
 		kfree(interrupt_data);
 		return -ENOMEM;
 	}
 
-	interrupt_data->eventfd_ctxs = kzalloc(
-		sizeof(struct eventfd_ctx *) * num_interrupts, GFP_KERNEL);
+	interrupt_data->eventfd_ctxs = kcalloc(num_interrupts,
+					       sizeof(struct eventfd_ctx *),
+					       GFP_KERNEL);
 	if (!interrupt_data->eventfd_ctxs) {
 		kfree(interrupt_data->msix_entries);
 		kfree(interrupt_data);
 		return -ENOMEM;
 	}
 
-	interrupt_data->interrupt_counts = kzalloc(
-		sizeof(ulong) * num_interrupts, GFP_KERNEL);
+	interrupt_data->interrupt_counts = kcalloc(num_interrupts,
+						   sizeof(ulong),
+						   GFP_KERNEL);
 	if (!interrupt_data->interrupt_counts) {
 		kfree(interrupt_data->eventfd_ctxs);
 		kfree(interrupt_data->msix_entries);
diff --git a/drivers/staging/gasket/gasket_page_table.c b/drivers/staging/gasket/gasket_page_table.c
index 6dc10508b15e..c5390a860f86 100644
--- a/drivers/staging/gasket/gasket_page_table.c
+++ b/drivers/staging/gasket/gasket_page_table.c
@@ -1674,9 +1674,9 @@ int gasket_alloc_coherent_memory(struct gasket_dev *gasket_dev, u64 size,
 	gasket_dev->page_table[index]->num_coherent_pages = num_pages;
 
 	/* allocate the physical memory block */
-	gasket_dev->page_table[index]->coherent_pages = kzalloc(
-		num_pages * sizeof(struct gasket_coherent_page_entry),
-		GFP_KERNEL);
+	gasket_dev->page_table[index]->coherent_pages =
+		kcalloc(num_pages, sizeof(struct gasket_coherent_page_entry),
+			GFP_KERNEL);
 	if (!gasket_dev->page_table[index]->coherent_pages)
 		goto nomem;
 	*dma_address = 0;
diff --git a/drivers/staging/gasket/gasket_sysfs.c b/drivers/staging/gasket/gasket_sysfs.c
index d45098c90b4b..40268fb50fc3 100644
--- a/drivers/staging/gasket/gasket_sysfs.c
+++ b/drivers/staging/gasket/gasket_sysfs.c
@@ -137,9 +137,9 @@ static void put_mapping(struct gasket_sysfs_mapping *mapping)
 		device = mapping->device;
 		legacy_device = mapping->legacy_device;
 		num_files_to_remove = mapping->attribute_count;
-		files_to_remove = kzalloc(
-			num_files_to_remove * sizeof(*files_to_remove),
-			GFP_KERNEL);
+		files_to_remove = kcalloc(num_files_to_remove,
+					  sizeof(*files_to_remove),
+					  GFP_KERNEL);
 		for (i = 0; i < num_files_to_remove; i++)
 			files_to_remove[i] = mapping->attributes[i].attr;
 
@@ -238,9 +238,9 @@ int gasket_sysfs_create_mapping(
 	kref_init(&mapping->refcount);
 	mapping->device = device;
 	mapping->gasket_dev = gasket_dev;
-	mapping->attributes = kzalloc(
-		GASKET_SYSFS_MAX_NODES * sizeof(*mapping->attributes),
-		GFP_KERNEL);
+	mapping->attributes = kcalloc(GASKET_SYSFS_MAX_NODES,
+				      sizeof(*mapping->attributes),
+				      GFP_KERNEL);
 	mapping->attribute_count = 0;
 	if (!mapping->attributes) {
 		gasket_nodev_error("Unable to allocate sysfs attribute array.");
-- 
2.17.1


-- 
Kees Cook
Pixel Security

                 reply	other threads:[~2018-07-04 17:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20180704173125.GA34354@beast \
    --to=keescook@chromium.org \
    --cc=benchan@chromium.org \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jnjoseph@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rspringer@google.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.