staging: gasket: use sizeof(*p) for memory allocation
authorKimberly Brown <kimbrownkd@gmail.com>
Fri, 26 Oct 2018 00:04:55 +0000 (20:04 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 5 Nov 2018 13:16:32 +0000 (14:16 +0100)
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>
Acked-by: Todd Poynor <toddpoynor@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/gasket/gasket_interrupt.c
drivers/staging/gasket/gasket_page_table.c

index 49d47afad64fa40672a908adc003e534c354d8dd..ad5657d213f0174c6f3ac07ed69ecb4e99bd6f14 100644 (file)
@@ -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);
index b7d460cf15fbc1ccf935801d9d4437f7297203ee..f5253ba9a4301ea325907cfb8a4c129aedda2a1e 100644 (file)
@@ -1278,7 +1278,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;