linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] IB/hns: Fine-tuning for two function implementations
@ 2017-02-16  9:00 SF Markus Elfring
  2017-02-16  9:02 ` [PATCH 1/2] IB/hns: Use kmalloc_array() in hns_roce_cmd_use_events() SF Markus Elfring
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-02-16  9:00 UTC (permalink / raw)
  To: linux-rdma, Doug Ledford, Hal Rosenstock, Sean Hefty, Wei Hu
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 16 Feb 2017 09:55:43 +0100

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
  Use kmalloc_array() in hns_roce_cmd_use_events()
  Use kcalloc() in hns_roce_buddy_init()

 drivers/infiniband/hw/hns/hns_roce_cmd.c |  6 +++---
 drivers/infiniband/hw/hns/hns_roce_mr.c  | 11 ++++++-----
 2 files changed, 9 insertions(+), 8 deletions(-)

-- 
2.11.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] IB/hns: Use kmalloc_array() in hns_roce_cmd_use_events()
  2017-02-16  9:00 [PATCH 0/2] IB/hns: Fine-tuning for two function implementations SF Markus Elfring
@ 2017-02-16  9:02 ` SF Markus Elfring
  2017-02-16  9:04 ` [PATCH 2/2] IB/hns: Use kcalloc() in hns_roce_buddy_init() SF Markus Elfring
  2017-04-20 20:32 ` [PATCH 0/2] IB/hns: Fine-tuning for two function implementations Doug Ledford
  2 siblings, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-02-16  9:02 UTC (permalink / raw)
  To: linux-rdma, Doug Ledford, Hal Rosenstock, Sean Hefty, Wei Hu
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 16 Feb 2017 08:50:11 +0100

* A multiplication for the size determination of a memory allocation
  indicated that an array data structure should be processed.
  Thus use the corresponding function "kmalloc_array".

  This issue was detected by using the Coccinelle software.

* Replace the specification of a data structure by a pointer dereference
  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/infiniband/hw/hns/hns_roce_cmd.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/infiniband/hw/hns/hns_roce_cmd.c b/drivers/infiniband/hw/hns/hns_roce_cmd.c
index 8c1f7a6f84d2..b94dcd823ad1 100644
--- a/drivers/infiniband/hw/hns/hns_roce_cmd.c
+++ b/drivers/infiniband/hw/hns/hns_roce_cmd.c
@@ -299,9 +299,9 @@ int hns_roce_cmd_use_events(struct hns_roce_dev *hr_dev)
 	struct hns_roce_cmdq *hr_cmd = &hr_dev->cmd;
 	int i;
 
-	hr_cmd->context = kmalloc(hr_cmd->max_cmds *
-				  sizeof(struct hns_roce_cmd_context),
-				  GFP_KERNEL);
+	hr_cmd->context = kmalloc_array(hr_cmd->max_cmds,
+					sizeof(*hr_cmd->context),
+					GFP_KERNEL);
 	if (!hr_cmd->context)
 		return -ENOMEM;
 
-- 
2.11.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] IB/hns: Use kcalloc() in hns_roce_buddy_init()
  2017-02-16  9:00 [PATCH 0/2] IB/hns: Fine-tuning for two function implementations SF Markus Elfring
  2017-02-16  9:02 ` [PATCH 1/2] IB/hns: Use kmalloc_array() in hns_roce_cmd_use_events() SF Markus Elfring
@ 2017-02-16  9:04 ` SF Markus Elfring
  2017-04-20 20:32 ` [PATCH 0/2] IB/hns: Fine-tuning for two function implementations Doug Ledford
  2 siblings, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-02-16  9:04 UTC (permalink / raw)
  To: linux-rdma, Doug Ledford, Hal Rosenstock, Sean Hefty, Wei Hu
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 16 Feb 2017 09:30:55 +0100

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

  This issue was detected by using the Coccinelle software.

* Replace the specification of data types by pointer dereferences
  to make the corresponding size determinations a bit safer according to
  the Linux coding style convention.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/infiniband/hw/hns/hns_roce_mr.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/infiniband/hw/hns/hns_roce_mr.c b/drivers/infiniband/hw/hns/hns_roce_mr.c
index 4139abee3b54..b48693510727 100644
--- a/drivers/infiniband/hw/hns/hns_roce_mr.c
+++ b/drivers/infiniband/hw/hns/hns_roce_mr.c
@@ -127,11 +127,12 @@ static int hns_roce_buddy_init(struct hns_roce_buddy *buddy, int max_order)
 
 	buddy->max_order = max_order;
 	spin_lock_init(&buddy->lock);
-
-	buddy->bits = kzalloc((buddy->max_order + 1) * sizeof(long *),
-			       GFP_KERNEL);
-	buddy->num_free = kzalloc((buddy->max_order + 1) * sizeof(int *),
-				   GFP_KERNEL);
+	buddy->bits = kcalloc(buddy->max_order + 1,
+			      sizeof(*buddy->bits),
+			      GFP_KERNEL);
+	buddy->num_free = kcalloc(buddy->max_order + 1,
+				  sizeof(*buddy->num_free),
+				  GFP_KERNEL);
 	if (!buddy->bits || !buddy->num_free)
 		goto err_out;
 
-- 
2.11.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] IB/hns: Fine-tuning for two function implementations
  2017-02-16  9:00 [PATCH 0/2] IB/hns: Fine-tuning for two function implementations SF Markus Elfring
  2017-02-16  9:02 ` [PATCH 1/2] IB/hns: Use kmalloc_array() in hns_roce_cmd_use_events() SF Markus Elfring
  2017-02-16  9:04 ` [PATCH 2/2] IB/hns: Use kcalloc() in hns_roce_buddy_init() SF Markus Elfring
@ 2017-04-20 20:32 ` Doug Ledford
  2 siblings, 0 replies; 4+ messages in thread
From: Doug Ledford @ 2017-04-20 20:32 UTC (permalink / raw)
  To: SF Markus Elfring, linux-rdma, Hal Rosenstock, Sean Hefty, Wei Hu
  Cc: LKML, kernel-janitors

On Thu, 2017-02-16 at 10:00 +0100, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 16 Feb 2017 09:55:43 +0100
> 
> A few update suggestions were taken into account
> from static source code analysis.
> 
> Markus Elfring (2):
>   Use kmalloc_array() in hns_roce_cmd_use_events()
>   Use kcalloc() in hns_roce_buddy_init()
> 
>  drivers/infiniband/hw/hns/hns_roce_cmd.c |  6 +++---
>  drivers/infiniband/hw/hns/hns_roce_mr.c  | 11 ++++++-----
>  2 files changed, 9 insertions(+), 8 deletions(-)

Series applied, thanks.

-- 
Doug Ledford <dledford@redhat.com>
    GPG KeyID: B826A3330E572FDD
   
Key fingerprint = AE6B 1BDA 122B 23B4 265B  1274 B826 A333 0E57 2FDD

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-04-20 20:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-16  9:00 [PATCH 0/2] IB/hns: Fine-tuning for two function implementations SF Markus Elfring
2017-02-16  9:02 ` [PATCH 1/2] IB/hns: Use kmalloc_array() in hns_roce_cmd_use_events() SF Markus Elfring
2017-02-16  9:04 ` [PATCH 2/2] IB/hns: Use kcalloc() in hns_roce_buddy_init() SF Markus Elfring
2017-04-20 20:32 ` [PATCH 0/2] IB/hns: Fine-tuning for two function implementations Doug Ledford

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).