Skip to contentSkip to conversation

scsi: csiostor: Use kcalloc() instead of kzalloc()

PATCH In review Erick Archer 2 participants 2 messages Jan 14, 2024 – Jan 15, 2024 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 scsi: csiostor: Use kcalloc() instead of kzalloc()

Use 2-factor multiplication argument form kcalloc() instead of kzalloc().

Also, it is preferred to use sizeof(*pointer) instead of sizeof(type) due to the type of the variable can change and one needs not change the former (unlike the latter).

---
Changes in v2:
- Update the changelog text describing the sizeof() changes (Gustavo A. R. Silva)

Version 1:

---
 drivers/scsi/csiostor/csio_init.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
drivers/scsi/csiostor/csio_init.c +5 -10
index d649b7a2a879..d72892e44fd1 100644
@@ -698,8 +698,7 @@ csio_lnodes_block_request(struct csio_hw *hw)
 	struct csio_lnode **lnode_list;
 	int cur_cnt = 0, ii;
 
-	lnode_list = kzalloc((sizeof(struct csio_lnode *) * hw->num_lns),
-			GFP_KERNEL);
+	lnode_list = kcalloc(hw->num_lns, sizeof(*lnode_list), GFP_KERNEL);
 	if (!lnode_list) {
 		csio_err(hw, "Failed to allocate lnodes_list");
 		return;
@@ -737,8 +736,7 @@ csio_lnodes_unblock_request(struct csio_hw *hw)
 	struct csio_lnode **lnode_list;
 	int cur_cnt = 0, ii;
 
-	lnode_list = kzalloc((sizeof(struct csio_lnode *) * hw->num_lns),
-			GFP_KERNEL);
+	lnode_list = kcalloc(hw->num_lns, sizeof(*lnode_list), GFP_KERNEL);
 	if (!lnode_list) {
 		csio_err(hw, "Failed to allocate lnodes_list");
 		return;
@@ -775,8 +773,7 @@ csio_lnodes_block_by_port(struct csio_hw *hw, uint8_t portid)
 	struct csio_lnode **lnode_list;
 	int cur_cnt = 0, ii;
 
-	lnode_list = kzalloc((sizeof(struct csio_lnode *) * hw->num_lns),
-			GFP_KERNEL);
+	lnode_list = kcalloc(hw->num_lns, sizeof(*lnode_list), GFP_KERNEL);
 	if (!lnode_list) {
 		csio_err(hw, "Failed to allocate lnodes_list");
 		return;
@@ -816,8 +813,7 @@ csio_lnodes_unblock_by_port(struct csio_hw *hw, uint8_t portid)
 	struct csio_lnode **lnode_list;
 	int cur_cnt = 0, ii;
 
-	lnode_list = kzalloc((sizeof(struct csio_lnode *) * hw->num_lns),
-			GFP_KERNEL);
+	lnode_list = kcalloc(hw->num_lns, sizeof(*lnode_list), GFP_KERNEL);
 	if (!lnode_list) {
 		csio_err(hw, "Failed to allocate lnodes_list");
 		return;
@@ -855,8 +851,7 @@ csio_lnodes_exit(struct csio_hw *hw, bool npiv)
 	struct csio_lnode **lnode_list;
 	int cur_cnt = 0, ii;
 
-	lnode_list = kzalloc((sizeof(struct csio_lnode *) * hw->num_lns),
-			GFP_KERNEL);
+	lnode_list = kcalloc(hw->num_lns, sizeof(*lnode_list), GFP_KERNEL);
 	if (!lnode_list) {
 		csio_err(hw, "lnodes_exit: Failed to allocate lnodes_list.\n");
 		return;

--
2.25.1

Reviewed-by on v2 1/1
#1 lore raw
Quoted 9 lines · Erick Archer

Use 2-factor multiplication argument form kcalloc() instead of kzalloc().

Also, it is preferred to use sizeof(*pointer) instead of sizeof(type) due to the type of the variable can change and one needs not change the former (unlike the latter).

Thanks!

Signature · 1 line
Gustavo
Quoted 69 lines

---
Changes in v2:
- Update the changelog text describing the sizeof() changes (Gustavo A. R. Silva)

Version 1:

---
  drivers/scsi/csiostor/csio_init.c | 15 +++++----------
  1 file changed, 5 insertions(+), 10 deletions(-)
drivers/scsi/csiostor/csio_init.c +5 -11
index d649b7a2a879..d72892e44fd1 100644
@@ -698,8 +698,7 @@ csio_lnodes_block_request(struct csio_hw *hw)
  	struct csio_lnode **lnode_list;
  	int cur_cnt = 0, ii;
 
-	lnode_list = kzalloc((sizeof(struct csio_lnode *) * hw->num_lns),
-			GFP_KERNEL);
+	lnode_list = kcalloc(hw->num_lns, sizeof(*lnode_list), GFP_KERNEL);
  	if (!lnode_list) {
  		csio_err(hw, "Failed to allocate lnodes_list");
  		return;
@@ -737,8 +736,7 @@ csio_lnodes_unblock_request(struct csio_hw *hw)
  	struct csio_lnode **lnode_list;
  	int cur_cnt = 0, ii;
 
-	lnode_list = kzalloc((sizeof(struct csio_lnode *) * hw->num_lns),
-			GFP_KERNEL);
+	lnode_list = kcalloc(hw->num_lns, sizeof(*lnode_list), GFP_KERNEL);
  	if (!lnode_list) {
  		csio_err(hw, "Failed to allocate lnodes_list");
  		return;
@@ -775,8 +773,7 @@ csio_lnodes_block_by_port(struct csio_hw *hw, uint8_t portid)
  	struct csio_lnode **lnode_list;
  	int cur_cnt = 0, ii;
 
-	lnode_list = kzalloc((sizeof(struct csio_lnode *) * hw->num_lns),
-			GFP_KERNEL);
+	lnode_list = kcalloc(hw->num_lns, sizeof(*lnode_list), GFP_KERNEL);
  	if (!lnode_list) {
  		csio_err(hw, "Failed to allocate lnodes_list");
  		return;
@@ -816,8 +813,7 @@ csio_lnodes_unblock_by_port(struct csio_hw *hw, uint8_t portid)
  	struct csio_lnode **lnode_list;
  	int cur_cnt = 0, ii;
 
-	lnode_list = kzalloc((sizeof(struct csio_lnode *) * hw->num_lns),
-			GFP_KERNEL);
+	lnode_list = kcalloc(hw->num_lns, sizeof(*lnode_list), GFP_KERNEL);
  	if (!lnode_list) {
  		csio_err(hw, "Failed to allocate lnodes_list");
  		return;
@@ -855,8 +851,7 @@ csio_lnodes_exit(struct csio_hw *hw, bool npiv)
  	struct csio_lnode **lnode_list;
  	int cur_cnt = 0, ii;
 
-	lnode_list = kzalloc((sizeof(struct csio_lnode *) * hw->num_lns),
-			GFP_KERNEL);
+	lnode_list = kcalloc(hw->num_lns, sizeof(*lnode_list), GFP_KERNEL);
  	if (!lnode_list) {
  		csio_err(hw, "lnodes_exit: Failed to allocate lnodes_list.\n");
  		return;
--

2.25.1