[PATCH v2] hpsa: fix a memory leak in hpsa_find_cfgtables()

Haoxiang Li posted 1 patch 1 month ago
drivers/scsi/hpsa.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[PATCH v2] hpsa: fix a memory leak in hpsa_find_cfgtables()
Posted by Haoxiang Li 1 month ago
If write_driver_ver_to_cfgtable() fails, add iounmap() to
release the memory allocated by remap_pci_mem().

Found by manual static code review.

Fixes: 580ada3c1e2f ("[SCSI] hpsa: do a better job of detecting controller reset failure")
Cc: stable@vger.kernel.org
Signed-off-by: Haoxiang Li <lihaoxiang@isrc.iscas.ac.cn>
---
Changes in v2:
- replace iounmap with unified release method. Thanks, Greg!
---
 drivers/scsi/hpsa.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index 3654b12c5d5a..e38d4a7488f8 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -7646,8 +7646,10 @@ static int hpsa_find_cfgtables(struct ctlr_info *h)
 		return -ENOMEM;
 	}
 	rc = write_driver_ver_to_cfgtable(h->cfgtable);
-	if (rc)
+	if (rc) {
+		hpsa_free_cfgtables(h);
 		return rc;
+	}
 	/* Find performant mode table. */
 	trans_offset = readl(&h->cfgtable->TransMethodOffset);
 	h->transtable = remap_pci_mem(pci_resource_start(h->pdev,
-- 
2.25.1
Re: [PATCH v2] hpsa: fix a memory leak in hpsa_find_cfgtables()
Posted by Markus Elfring 4 weeks, 1 day ago
> If write_driver_ver_to_cfgtable() fails, add iounmap() to
> release the memory allocated by remap_pci_mem().

How do you think about to avoid a bit of duplicate source code here?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v6.19-rc4#n526

See also once more:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc4#n659


> Found by manual static code review.

Can such information indicate a contradiction?

Regards,
Markus