From: SF Markus Elfring <elfring@users.sourceforge.net>
To: linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Doug Ledford <dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
Hal Rosenstock
<hal.rosenstock-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
Leon Romanovsky <leonro-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>,
Matan Barak <matanb-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>,
Sean Hefty <sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>,
Yishai Hadas <yishaih-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
Cc: LKML <linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
kernel-janitors-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH 11/29] IB/mlx4: Use kmalloc_array() in three functions
Date: Sat, 18 Feb 2017 20:59:51 +0000 [thread overview]
Message-ID: <3002f281-292a-c53e-0b37-d23a3be0d5d7@users.sourceforge.net> (raw)
In-Reply-To: <1935365a-bd7c-461e-6a84-0c5d3a501fff-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 18 Feb 2017 10:32:32 +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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/infiniband/hw/mlx4/main.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c
index ba6af84cc236..350c9148340e 100644
--- a/drivers/infiniband/hw/mlx4/main.c
+++ b/drivers/infiniband/hw/mlx4/main.c
@@ -304,7 +304,9 @@ static int mlx4_ib_add_gid(struct ib_device *device,
ctx->refcount++;
}
if (!ret && hw_update) {
- gids = kmalloc(sizeof(*gids) * MLX4_MAX_PORT_GIDS, GFP_ATOMIC);
+ gids = kmalloc_array(MLX4_MAX_PORT_GIDS,
+ sizeof(*gids),
+ GFP_ATOMIC);
if (!gids) {
ret = -ENOMEM;
} else {
@@ -359,7 +361,9 @@ static int mlx4_ib_del_gid(struct ib_device *device,
if (!ret && hw_update) {
int i;
- gids = kmalloc(sizeof(*gids) * MLX4_MAX_PORT_GIDS, GFP_ATOMIC);
+ gids = kmalloc_array(MLX4_MAX_PORT_GIDS,
+ sizeof(*gids),
+ GFP_ATOMIC);
if (!gids) {
ret = -ENOMEM;
} else {
@@ -2828,9 +2832,9 @@ static void *mlx4_ib_add(struct mlx4_dev *dev)
goto err_counter;
ibdev->ib_uc_qpns_bitmap - kmalloc(BITS_TO_LONGS(ibdev->steer_qpn_count) *
- sizeof(long),
- GFP_KERNEL);
+ kmalloc_array(BITS_TO_LONGS(ibdev->steer_qpn_count),
+ sizeof(long),
+ GFP_KERNEL);
if (!ibdev->ib_uc_qpns_bitmap)
goto err_steer_qp_release;
--
2.11.1
next prev parent reply other threads:[~2017-02-18 20:59 UTC|newest]
Thread overview: 77+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-18 20:45 [PATCH 00/29] IB/mlx: Fine-tuning for several function implementations SF Markus Elfring
[not found] ` <1935365a-bd7c-461e-6a84-0c5d3a501fff-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
2017-02-18 20:47 ` [PATCH 01/29] IB/mlx4: Use kcalloc() in mlx4_ib_alloc_pv_bufs() SF Markus Elfring
2017-02-19 17:06 ` Majd Dibbiny
2017-02-18 20:49 ` [PATCH 02/29] IB/mlx4: Improve another size determination " SF Markus Elfring
[not found] ` <14b2089f-f52c-0b18-90d5-810abc9f9fd6-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
2017-02-19 17:06 ` Majd Dibbiny
2017-02-18 20:50 ` [PATCH 03/29] IB/mlx4: Improve another size determination in mlx4_ib_alloc_demux_ctx() SF Markus Elfring
2017-02-19 17:06 ` Majd Dibbiny
2017-02-18 20:54 ` [PATCH 06/29] IB/mlx4: Delete three unnecessary return statements SF Markus Elfring
2017-02-19 17:06 ` Majd Dibbiny
2017-02-18 20:55 ` [PATCH 07/29] IB/mlx4: Split a condition check in handle_slaves_guid_change() SF Markus Elfring
[not found] ` <951c0746-b88e-8ee7-78e8-5be2a53a2e43-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
2017-02-19 17:09 ` Majd Dibbiny
2017-02-18 20:56 ` [PATCH 08/29] IB/mlx4: Delete an unnecessary check before the function call "kfree" in free_pv_objec SF Markus Elfring
2017-02-19 17:11 ` [PATCH 08/29] IB/mlx4: Delete an unnecessary check before the function call "kfree" in free_pv_o Majd Dibbiny
2017-02-18 20:57 ` [PATCH 09/29] IB/mlx4: Move an assignment out of a check in forward_trap() SF Markus Elfring
2017-02-19 17:12 ` Majd Dibbiny
2017-02-18 20:58 ` [PATCH 10/29] IB/mlx4: Enclose 15 expressions for the sizeof operator by parentheses SF Markus Elfring
2017-02-19 17:21 ` Majd Dibbiny
2017-02-18 20:59 ` SF Markus Elfring [this message]
2017-02-19 17:21 ` [PATCH 11/29] IB/mlx4: Use kmalloc_array() in three functions Majd Dibbiny
2017-02-18 21:01 ` [PATCH 13/29] IB/mlx4: Split a condition check in five functions SF Markus Elfring
2017-02-19 17:21 ` Majd Dibbiny
2017-02-18 21:02 ` [PATCH 14/29] IB/mlx4: Delete an unnecessary variable in __mlx4_ib_query_gid() SF Markus Elfring
2017-02-18 21:04 ` [PATCH 16/29] IB/mlx4: Improve another size determination in do_slave_init() SF Markus Elfring
2017-02-18 21:05 ` [PATCH 17/29] IB/mlx4: Improve another size determination in mlx4_ib_add() SF Markus Elfring
2017-02-19 17:36 ` Majd Dibbiny
[not found] ` <2269d63f-433d-b62b-06f2-38a4d9d466f4-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
2017-02-19 17:36 ` Majd Dibbiny
2017-02-18 21:06 ` [PATCH 18/29] IB/mlx4: Delete an unnecessary variable initialisation " SF Markus Elfring
2017-02-18 21:08 ` [PATCH 19/29] IB/mlx4: Delete an unnecessary variable assignment " SF Markus Elfring
[not found] ` <3f4e69c8-a030-fb75-26bb-e14208c141c5-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
2017-02-19 19:42 ` Majd Dibbiny
2017-02-18 21:10 ` [PATCH 20/29] IB/mlx4: Delete an error message for a failed memory allocation " SF Markus Elfring
2017-02-19 19:48 ` Majd Dibbiny
2017-02-18 21:12 ` [PATCH 22/29] IB/mlx4: Use kmalloc_array() in alloc_proxy_bufs() SF Markus Elfring
[not found] ` <b7f36e89-a3c8-0842-d496-0dbb64fdd73f-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
2017-02-19 19:53 ` Majd Dibbiny
2017-02-18 21:15 ` [PATCH 25/29] IB/mlx4: Add spaces for better code readability SF Markus Elfring
2017-02-18 21:17 ` [PATCH 27/29] IB/mlx5: Use kmalloc_array() in create_kernel_qp() SF Markus Elfring
2017-02-18 21:18 ` [PATCH 28/29] IB/mlx5: Less function calls in create_kernel_qp() after error detection SF Markus Elfring
2017-02-18 21:19 ` [PATCH 29/29] IB/mlx5: Use kmalloc_array() in create_srq_kernel() SF Markus Elfring
2017-04-20 20:37 ` [PATCH 00/29] IB/mlx: Fine-tuning for several function implementations Doug Ledford
2017-04-20 21:02 ` SF Markus Elfring
[not found] ` <8f433ee0-4dde-44db-cd36-fc2831b45df6-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
2017-04-21 2:23 ` Doug Ledford
2017-04-21 18:17 ` [PATCH v2 00/17] " SF Markus Elfring
2017-04-21 18:21 ` [PATCH v2 01/17] IB/mlx4: Use kcalloc() in mlx4_ib_alloc_pv_bufs() SF Markus Elfring
2017-04-21 18:29 ` [PATCH v2 00/17] IB/mlx: Fine-tuning for several function implementations Bart Van Assche
2017-04-21 19:21 ` SF Markus Elfring
[not found] ` <6c7fd04f-5c46-a35e-822c-567dd7538521-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
2017-04-21 19:55 ` Bart Van Assche
2017-04-21 18:30 ` [PATCH v2 04/17] IB/mlx4: Fix a typo in a comment line SF Markus Elfring
2017-04-21 18:33 ` [PATCH v2 05/17] IB/mlx4: Delete four unnecessary return statements SF Markus Elfring
2017-04-21 18:36 ` [PATCH v2 06/17] IB/mlx4: Delete an unnecessary check before kfree() in free_pv_object() SF Markus Elfring
2017-04-21 18:38 ` [PATCH v2 08/17] IB/mlx4: Enclose 46 expressions for sizeof by parentheses SF Markus Elfring
2017-04-21 18:42 ` [PATCH v2 10/17] IB/mlx4: Delete an unnecessary variable in __mlx4_ib_query_gid() SF Markus Elfring
[not found] ` <a56f9301-e116-c59c-681a-9108519920e5-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
2017-04-21 18:24 ` [PATCH v2 02/17] IB/mlx: Use kmalloc_array() in six functions SF Markus Elfring
2017-04-21 18:28 ` [PATCH v2 03/17] IB/mlx4: Improve size determinations " SF Markus Elfring
2017-04-21 18:37 ` [PATCH v2 07/17] IB/mlx4: Move an assignment out of a check in forward_trap() SF Markus Elfring
2017-04-21 18:40 ` [PATCH v2 09/17] IB/mlx4: Split a condition check in six functions SF Markus Elfring
2017-04-21 18:44 ` [PATCH v2 11/17] IB/mlx4: Delete an unnecessary variable initialisation in mlx4_ib_add() SF Markus Elfring
2017-04-21 18:48 ` [PATCH v2 14/17] IB/mlx4: Delete unnecessary braces " SF Markus Elfring
2017-04-21 18:45 ` [PATCH v2 12/17] IB/mlx4: Delete an unnecessary variable assignment " SF Markus Elfring
2017-04-21 18:46 ` [PATCH v2 13/17] IB/mlx4: Delete an error message for a failed memory allocation " SF Markus Elfring
2017-04-21 18:50 ` [PATCH v2 15/17] IB/mlx4: Delete unwanted spaces behind usages of the sizeof operator SF Markus Elfring
2017-04-21 18:54 ` [PATCH v2 16/17] IB/mlx4: Add spaces for better code readability SF Markus Elfring
2017-04-21 19:28 ` Joe Perches
2017-04-21 18:55 ` [PATCH v2 17/17] IB/mlx5: Less function calls in create_kernel_qp() after error detection SF Markus Elfring
2017-08-06 14:00 ` [PATCH v2 00/17] IB/mlx: Fine-tuning for several function implementations SF Markus Elfring
2017-02-18 20:51 ` [PATCH 04/29] IB/mlx4: Improve another size determination in alloc_pv_object() SF Markus Elfring
2017-02-19 17:06 ` Majd Dibbiny
2017-02-18 20:52 ` [PATCH 05/29] IB/mlx4: Fix a typo in a comment line SF Markus Elfring
2017-02-19 17:06 ` Majd Dibbiny
2017-02-18 21:00 ` [PATCH 12/29] IB/mlx4: Enclose 17 expressions for the sizeof operator by parentheses SF Markus Elfring
2017-02-19 17:21 ` Majd Dibbiny
2017-02-18 21:03 ` [PATCH 15/29] IB/mlx4: Delete an unnecessary return statement in do_slave_init() SF Markus Elfring
2017-02-19 17:36 ` Majd Dibbiny
2017-02-18 21:11 ` [PATCH 21/29] IB/mlx4: Delete unnecessary braces in mlx4_ib_add() SF Markus Elfring
[not found] ` <6abe0f08-b308-08ac-9f84-868887c0218c-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
2017-02-19 19:51 ` Majd Dibbiny
2017-02-18 21:13 ` [PATCH 23/29] IB/mlx4: Improve size determinations in create_qp_common() SF Markus Elfring
[not found] ` <9b7e9f1c-ccf4-6de6-158f-cd9f86f5edb4-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
2017-02-19 19:54 ` Majd Dibbiny
2017-02-18 21:14 ` [PATCH 24/29] IB/mlx4: Delete unwanted spaces behind usages of the sizeof operator SF Markus Elfring
2017-02-18 21:16 ` [PATCH 26/29] IB/mlx4: Enclose 14 expressions for the sizeof operator by parentheses SF Markus Elfring
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=3002f281-292a-c53e-0b37-d23a3be0d5d7@users.sourceforge.net \
--to=elfring@users.sourceforge.net \
--cc=dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=hal.rosenstock-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=kernel-janitors-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=leonro-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=matanb-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
--cc=sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
--cc=yishaih-VPRAkNaXOzVWk0Htik3J/w@public.gmane.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).