Skip to contentSkip to conversation

Remove unnecessary devm_kfree

PATCH Superseded Bean Huo 2 participants 5 messages Jan 12, 2021

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Bean Huo

author
#0 lore raw

v2 cover Remove unnecessary devm_kfree

From: Bean Huo <[email protected]>

Changelog:

V1-V2:
1. Remove unused variable i in patch 1/2
2. Add Eric Biggers review tag in patch 2/2

Bean Huo (2):
scsi: hisi_sas: Remove unnecessary devm_kfree
scsi: ufs: Remove unnecessary devm_kfree

 drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 28 +-------------------------
 drivers/scsi/ufs/ufshcd-crypto.c       |  4 +---
 2 files changed, 2 insertions(+), 30 deletions(-)
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH v2 1/2 scsi: hisi_sas: Remove unnecessary devm_kfree

From: Bean Huo <[email protected]>

The memory allocated with devm_kzalloc() is freed automatically no need to explicitly call devm_kfree.

---
 drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 28 +-------------------------
 1 file changed, 1 insertion(+), 27 deletions(-)
drivers/scsi/hisi_sas/hisi_sas_v3_hw.c +1 -27
index 91a7286e8102..5600411a0820 100644
@@ -4172,30 +4172,6 @@ static void debugfs_work_handler_v3_hw(struct work_struct *work)
 	hisi_hba->debugfs_dump_index++;
 }
 
-static void debugfs_release_v3_hw(struct hisi_hba *hisi_hba, int dump_index)
-{
-	struct device *dev = hisi_hba->dev;
-	int i;
-
-	devm_kfree(dev, hisi_hba->debugfs_iost_cache[dump_index].cache);
-	devm_kfree(dev, hisi_hba->debugfs_itct_cache[dump_index].cache);
-	devm_kfree(dev, hisi_hba->debugfs_iost[dump_index].iost);
-	devm_kfree(dev, hisi_hba->debugfs_itct[dump_index].itct);
-
-	for (i = 0; i < hisi_hba->queue_count; i++)
-		devm_kfree(dev, hisi_hba->debugfs_dq[dump_index][i].hdr);
-
-	for (i = 0; i < hisi_hba->queue_count; i++)
-		devm_kfree(dev,
-			   hisi_hba->debugfs_cq[dump_index][i].complete_hdr);
-
-	for (i = 0; i < DEBUGFS_REGS_NUM; i++)
-		devm_kfree(dev, hisi_hba->debugfs_regs[dump_index][i].data);
-
-	for (i = 0; i < hisi_hba->n_phy; i++)
-		devm_kfree(dev, hisi_hba->debugfs_port_reg[dump_index][i].data);
-}
-
 static const struct hisi_sas_debugfs_reg *debugfs_reg_array_v3_hw[DEBUGFS_REGS_NUM] = {
 	[DEBUGFS_GLOBAL] = &debugfs_global_reg,
 	[DEBUGFS_AXI] = &debugfs_axi_reg,
@@ -4206,7 +4182,7 @@ static int debugfs_alloc_v3_hw(struct hisi_hba *hisi_hba, int dump_index)
 {
 	const struct hisi_sas_hw *hw = hisi_hba->hw;
 	struct device *dev = hisi_hba->dev;
-	int p, c, d, r, i;
+	int p, c, d, r;
 	size_t sz;
 
 	for (r = 0; r < DEBUGFS_REGS_NUM; r++) {
@@ -4286,8 +4262,6 @@ static int debugfs_alloc_v3_hw(struct hisi_hba *hisi_hba, int dump_index)
 
 	return 0;
 fail:
-	for (i = 0; i < hisi_sas_debugfs_dump_count; i++)
-		debugfs_release_v3_hw(hisi_hba, i);
 	return -ENOMEM;
 }
 
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH v2 1/2] scsi: hisi_sas: Remove unnecessary devm_kfree

Quoted 5 lines · Bean Huo

From: Bean Huo <[email protected]>

The memory allocated with devm_kzalloc() is freed automatically no need to explicitly call devm_kfree.

This change is not right - we use devm_kfree() to manually release the devm-allocated debugfs memories upon memory allocation failure for driver debugfs feature during probe. The reason is that we allow the driver probe can still continue (for this failure).

Thanks,
John

Quoted 59 lines
---
  drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 28 +-------------------------
  1 file changed, 1 insertion(+), 27 deletions(-)
drivers/scsi/hisi_sas/hisi_sas_v3_hw.c +1 -27
index 91a7286e8102..5600411a0820 100644
@@ -4172,30 +4172,6 @@ static void debugfs_work_handler_v3_hw(struct work_struct *work)
  	hisi_hba->debugfs_dump_index++;
  }
 
-static void debugfs_release_v3_hw(struct hisi_hba *hisi_hba, int dump_index)
-{
-	struct device *dev = hisi_hba->dev;
-	int i;
-
-	devm_kfree(dev, hisi_hba->debugfs_iost_cache[dump_index].cache);
-	devm_kfree(dev, hisi_hba->debugfs_itct_cache[dump_index].cache);
-	devm_kfree(dev, hisi_hba->debugfs_iost[dump_index].iost);
-	devm_kfree(dev, hisi_hba->debugfs_itct[dump_index].itct);
-
-	for (i = 0; i < hisi_hba->queue_count; i++)
-		devm_kfree(dev, hisi_hba->debugfs_dq[dump_index][i].hdr);
-
-	for (i = 0; i < hisi_hba->queue_count; i++)
-		devm_kfree(dev,
-			   hisi_hba->debugfs_cq[dump_index][i].complete_hdr);
-
-	for (i = 0; i < DEBUGFS_REGS_NUM; i++)
-		devm_kfree(dev, hisi_hba->debugfs_regs[dump_index][i].data);
-
-	for (i = 0; i < hisi_hba->n_phy; i++)
-		devm_kfree(dev, hisi_hba->debugfs_port_reg[dump_index][i].data);
-}
-
  static const struct hisi_sas_debugfs_reg *debugfs_reg_array_v3_hw[DEBUGFS_REGS_NUM] = {
  	[DEBUGFS_GLOBAL] = &debugfs_global_reg,
  	[DEBUGFS_AXI] = &debugfs_axi_reg,
@@ -4206,7 +4182,7 @@ static int debugfs_alloc_v3_hw(struct hisi_hba *hisi_hba, int dump_index)
  {
  	const struct hisi_sas_hw *hw = hisi_hba->hw;
  	struct device *dev = hisi_hba->dev;
-	int p, c, d, r, i;
+	int p, c, d, r;
  	size_t sz;
 
  	for (r = 0; r < DEBUGFS_REGS_NUM; r++) {
@@ -4286,8 +4262,6 @@ static int debugfs_alloc_v3_hw(struct hisi_hba *hisi_hba, int dump_index)
 
  	return 0;
  fail:
-	for (i = 0; i < hisi_sas_debugfs_dump_count; i++)
-		debugfs_release_v3_hw(hisi_hba, i);
  	return -ENOMEM;
  }
 
author
#3 lore raw

Re: [PATCH v2 1/2] scsi: hisi_sas: Remove unnecessary devm_kfree

Quoted 7 lines · John Garry
Quoted 5 lines · Bean Huo

From: Bean Huo <[email protected]>

The memory allocated with devm_kzalloc() is freed automatically no need to explicitly call devm_kfree.

Quoted 8 lines

This change is not right - we use devm_kfree() to manually release the
devm-allocated debugfs memories upon memory allocation failure for driver debugfs feature during probe. The reason is that we allow the driver probe can still continue (for this failure).

Thanks,
John

yea, I see, probe didn't deal with ENOMEM error. will drop this change. thanks.

Bean

author
#4 lore raw

PATCH v2 2/2 scsi: ufs: Remove unnecessary devm_kfree

In reply to Bean Huo

From: Bean Huo <[email protected]>

The memory allocated with devm_kzalloc() is freed automatically no need to explicitly call devm_kfree.

---
 drivers/scsi/ufs/ufshcd-crypto.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/scsi/ufs/ufshcd-crypto.c +1 -3
index 07310b12a5dc..ec80ec83cf85 100644
@@ -182,7 +182,7 @@ int ufshcd_hba_init_crypto_capabilities(struct ufs_hba *hba)
 	err = blk_ksm_init(&hba->ksm,
 			   hba->crypto_capabilities.config_count + 1);
 	if (err)
-		goto out_free_caps;
+		goto out;
 
 	hba->ksm.ksm_ll_ops = ufshcd_ksm_ops;
 	/* UFS only supports 8 bytes for any DUN */
@@ -208,8 +208,6 @@ int ufshcd_hba_init_crypto_capabilities(struct ufs_hba *hba)
 
 	return 0;
 
-out_free_caps:
-	devm_kfree(hba->dev, hba->crypto_cap_array);
 out:
 	/* Indicate that init failed by clearing UFSHCD_CAP_CRYPTO */
 	hba->caps &= ~UFSHCD_CAP_CRYPTO;
Signature · 1 line
2.17.1