Skip to contentSkip to conversation

IB/hns: Fine-tuning for two function implementations

PATCH In review SF Markus Elfring 2 participants 4 messages Feb 16, 2017 – Apr 20, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover IB/hns: Fine-tuning for two function implementations

From: Markus Elfring <[email protected]>
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(-)
Signature · 1 line
2.11.1
#1 lore raw

PATCH 1/2 IB/hns: Use kmalloc_array() in hns_roce_cmd_use_events()

From: Markus Elfring <[email protected]>
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.

---
 drivers/infiniband/hw/hns/hns_roce_cmd.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/infiniband/hw/hns/hns_roce_cmd.c +3 -3
index 8c1f7a6f84d2..b94dcd823ad1 100644
@@ -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;
 
Signature · 1 line
2.11.1
#2 lore raw

PATCH 2/2 IB/hns: Use kcalloc() in hns_roce_buddy_init()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
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.

---
 drivers/infiniband/hw/hns/hns_roce_mr.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/infiniband/hw/hns/hns_roce_mr.c +6 -5
index 4139abee3b54..b48693510727 100644
@@ -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;
 
Signature · 1 line
2.11.1
#3 lore raw
In reply to SF Markus Elfring
Quoted 6 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 16 Feb 2017 09:55:43 +0100

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

Quoted 7 lines

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.

Signature · 4 lines
Doug Ledford <[email protected]>
    GPG KeyID: B826A3330E572FDD
   
Key fingerprint = AE6B 1BDA 122B 23B4 265B  1274 B826 A333 0E57 2FDD