Skip to contentSkip to conversation

HSI: Fine-tuning for three function implementations

PATCH In review SF Markus Elfring 2 participants 4 messages Apr 25, 2017 – May 1, 2017

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

cover HSI: Fine-tuning for three function implementations

From: Markus Elfring <[email protected]>
Date: Tue, 25 Apr 2017 14:32:10 +0200

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

Markus Elfring (2):
Use kcalloc() in hsi_register_board_info()
core: Use kcalloc() in two functions

 drivers/hsi/hsi_boardinfo.c | 2 +-
 drivers/hsi/hsi_core.c      | 7 +++----
 2 files changed, 4 insertions(+), 5 deletions(-)
Signature · 1 line
2.12.2
#1 lore raw

PATCH 1/2 HSI: Use kcalloc() in hsi_register_board_info()

From: Markus Elfring <[email protected]>
Date: Tue, 25 Apr 2017 13:56:08 +0200

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

This issue was detected by using the Coccinelle software.

---
 drivers/hsi/hsi_boardinfo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hsi/hsi_boardinfo.c +1 -1
index e56bc6da5f98..e381cb4c962e 100644
@@ -49,7 +49,7 @@ int __init hsi_register_board_info(struct hsi_board_info const *info,
 {
 	struct hsi_cl_info *cl_info;
 
-	cl_info = kzalloc(sizeof(*cl_info) * len, GFP_KERNEL);
+	cl_info = kcalloc(len, sizeof(*cl_info), GFP_KERNEL);
 	if (!cl_info)
 		return -ENOMEM;
 
Signature · 1 line
2.12.2
#2 lore raw

PATCH 2/2 HSI: core: Use kcalloc() in two functions

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 25 Apr 2017 14:17:50 +0200

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.

---
 drivers/hsi/hsi_core.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/hsi/hsi_core.c +3 -4
index c2a2a9795b0b..9065efd21851 100644
@@ -267,14 +267,13 @@ static void hsi_add_client_from_dt(struct hsi_port *port,
 
 	cl->rx_cfg.num_channels = cells;
 	cl->tx_cfg.num_channels = cells;
-
-	cl->rx_cfg.channels = kzalloc(cells * sizeof(channel), GFP_KERNEL);
+	cl->rx_cfg.channels = kcalloc(cells, sizeof(channel), GFP_KERNEL);
 	if (!cl->rx_cfg.channels) {
 		err = -ENOMEM;
 		goto err;
 	}
 
-	cl->tx_cfg.channels = kzalloc(cells * sizeof(channel), GFP_KERNEL);
+	cl->tx_cfg.channels = kcalloc(cells, sizeof(channel), GFP_KERNEL);
 	if (!cl->tx_cfg.channels) {
 		err = -ENOMEM;
 		goto err2;
@@ -485,7 +484,7 @@ struct hsi_controller *hsi_alloc_controller(unsigned int n_ports, gfp_t flags)
 	hsi = kzalloc(sizeof(*hsi), flags);
 	if (!hsi)
 		return NULL;
-	port = kzalloc(sizeof(*port)*n_ports, flags);
+	port = kcalloc(n_ports, sizeof(*port), flags);
 	if (!port) {
 		kfree(hsi);
 		return NULL;
Signature · 1 line
2.12.2
#3 lore raw
In reply to SF Markus Elfring

Hi,

Quoted 6 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 25 Apr 2017 14:32:10 +0200

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

Quoted 7 lines

Markus Elfring (2):
Use kcalloc() in hsi_register_board_info()
core: Use kcalloc() in two functions

 drivers/hsi/hsi_boardinfo.c | 2 +-
 drivers/hsi/hsi_core.c      | 7 +++----
 2 files changed, 4 insertions(+), 5 deletions(-)

Thanks for your patchset. We are currently in the merge window and your patch will appear in linux-next once 4.12-rc1 has been tagged by Linus Torvalds.

Until then I queued it into this branch:

https://git.kernel.org/cgit/linux/kernel/git/sre/linux-hsi.git/log/?h=for-next-next

-- Sebastian