From: Kimberly Brown <kimbrownkd@gmail.com>
To: outreachy-kernel@googlegroups.com,
Rob Springer <rspringer@google.com>,
Todd Poynor <toddpoynor@google.com>,
Ben Chan <benchan@chromium.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH v2] staging: gasket: use sizeof(*p) for memory allocation
Date: Thu, 25 Oct 2018 20:04:55 -0400 [thread overview]
Message-ID: <20181026000455.GA26042@v> (raw)
In-Reply-To: <20181024041602.GA2385@v>
Use sizeof(*p) instead of sizeof(struct P) for memory allocation. This
change complies with the Linux kernel coding style. It improves
readability and decreases the opportunity for bugs if the pointer
variable type is changed. Issue found by checkpatch.
Signed-off-by: Kimberly Brown <kimbrownkd@gmail.com>
---
Changes in v2:
- Changed 4 additional memory allocations to use sizeof(*p).
- Removed 'interrupt:' from the subject line because the
gasket_page_table.c file is now included in this patch.
drivers/staging/gasket/gasket_interrupt.c | 17 ++++++++---------
drivers/staging/gasket/gasket_page_table.c | 3 ++-
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/drivers/staging/gasket/gasket_interrupt.c b/drivers/staging/gasket/gasket_interrupt.c
index 49d47afad64f..ad5657d213f0 100644
--- a/drivers/staging/gasket/gasket_interrupt.c
+++ b/drivers/staging/gasket/gasket_interrupt.c
@@ -184,7 +184,7 @@ gasket_interrupt_msix_init(struct gasket_interrupt_data *interrupt_data)
interrupt_data->msix_entries =
kcalloc(interrupt_data->num_interrupts,
- sizeof(struct msix_entry), GFP_KERNEL);
+ sizeof(*interrupt_data->msix_entries), GFP_KERNEL);
if (!interrupt_data->msix_entries)
return -ENOMEM;
@@ -322,8 +322,7 @@ int gasket_interrupt_init(struct gasket_dev *gasket_dev)
const struct gasket_driver_desc *driver_desc =
gasket_get_driver_desc(gasket_dev);
- interrupt_data = kzalloc(sizeof(struct gasket_interrupt_data),
- GFP_KERNEL);
+ interrupt_data = kzalloc(sizeof(*interrupt_data), GFP_KERNEL);
if (!interrupt_data)
return -ENOMEM;
gasket_dev->interrupt_data = interrupt_data;
@@ -336,17 +335,17 @@ int gasket_interrupt_init(struct gasket_dev *gasket_dev)
interrupt_data->pack_width = driver_desc->interrupt_pack_width;
interrupt_data->num_configured = 0;
- interrupt_data->eventfd_ctxs = kcalloc(driver_desc->num_interrupts,
- sizeof(struct eventfd_ctx *),
- GFP_KERNEL);
+ interrupt_data->eventfd_ctxs =
+ kcalloc(driver_desc->num_interrupts,
+ sizeof(*interrupt_data->eventfd_ctxs), GFP_KERNEL);
if (!interrupt_data->eventfd_ctxs) {
kfree(interrupt_data);
return -ENOMEM;
}
- interrupt_data->interrupt_counts = kcalloc(driver_desc->num_interrupts,
- sizeof(ulong),
- GFP_KERNEL);
+ interrupt_data->interrupt_counts =
+ kcalloc(driver_desc->num_interrupts,
+ sizeof(*interrupt_data->interrupt_counts), GFP_KERNEL);
if (!interrupt_data->interrupt_counts) {
kfree(interrupt_data->eventfd_ctxs);
kfree(interrupt_data);
diff --git a/drivers/staging/gasket/gasket_page_table.c b/drivers/staging/gasket/gasket_page_table.c
index 5b398b7ba81d..5f4c9b49cb5a 100644
--- a/drivers/staging/gasket/gasket_page_table.c
+++ b/drivers/staging/gasket/gasket_page_table.c
@@ -1302,7 +1302,8 @@ int gasket_alloc_coherent_memory(struct gasket_dev *gasket_dev, u64 size,
/* allocate the physical memory block */
gasket_dev->page_table[index]->coherent_pages =
- kcalloc(num_pages, sizeof(struct gasket_coherent_page_entry),
+ kcalloc(num_pages,
+ sizeof(*gasket_dev->page_table[index]->coherent_pages),
GFP_KERNEL);
if (!gasket_dev->page_table[index]->coherent_pages)
goto nomem;
--
2.17.1
next prev parent reply other threads:[~2018-10-26 0:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-24 4:16 [PATCH] staging: gasket: interrupt: use sizeof(*p) for memory allocation Kimberly Brown
2018-10-24 10:52 ` [Outreachy kernel] " Sasha Levin
2018-10-26 0:04 ` Kimberly Brown [this message]
2018-10-28 19:32 ` [PATCH v2] staging: gasket: " Todd Poynor
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=20181026000455.GA26042@v \
--to=kimbrownkd@gmail.com \
--cc=benchan@chromium.org \
--cc=gregkh@linuxfoundation.org \
--cc=outreachy-kernel@googlegroups.com \
--cc=rspringer@google.com \
--cc=sashal@kernel.org \
--cc=toddpoynor@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.