Skip to content
/ linux Public

Commit f471ecf

Browse files
GoodLuck612Sasha Levin
authored andcommitted
scsi: smartpqi: Fix memory leak in pqi_report_phys_luns()
[ Upstream commit 41b3731 ] pqi_report_phys_luns() fails to release the rpl_list buffer when encountering an unsupported data format or when the allocation for rpl_16byte_wwid_list fails. These early returns bypass the cleanup logic, leading to memory leaks. Consolidate the error handling by adding an out_free_rpl_list label and use goto statements to ensure rpl_list is consistently freed on failure. Compile tested only. Issue found using a prototype static analysis tool and code review. Fixes: 28ca6d8 ("scsi: smartpqi: Add extended report physical LUNs") Signed-off-by: Zilin Guan <zilin@seu.edu.cn> Tested-by: Don Brace <don.brace@microchip.com> Acked-by: Don Brace <don.brace@microchip.com> Link: https://patch.msgid.link/20260131093641.1008117-1-zilin@seu.edu.cn Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent c5f16ff commit f471ecf

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

drivers/scsi/smartpqi/smartpqi_init.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,8 @@ static inline int pqi_report_phys_luns(struct pqi_ctrl_info *ctrl_info, void **b
12131213
dev_err(&ctrl_info->pci_dev->dev,
12141214
"RPL returned unsupported data format %u\n",
12151215
rpl_response_format);
1216-
return -EINVAL;
1216+
rc = -EINVAL;
1217+
goto out_free_rpl_list;
12171218
} else {
12181219
dev_warn(&ctrl_info->pci_dev->dev,
12191220
"RPL returned extended format 2 instead of 4\n");
@@ -1225,8 +1226,10 @@ static inline int pqi_report_phys_luns(struct pqi_ctrl_info *ctrl_info, void **b
12251226

12261227
rpl_16byte_wwid_list = kmalloc(struct_size(rpl_16byte_wwid_list, lun_entries,
12271228
num_physicals), GFP_KERNEL);
1228-
if (!rpl_16byte_wwid_list)
1229-
return -ENOMEM;
1229+
if (!rpl_16byte_wwid_list) {
1230+
rc = -ENOMEM;
1231+
goto out_free_rpl_list;
1232+
}
12301233

12311234
put_unaligned_be32(num_physicals * sizeof(struct report_phys_lun_16byte_wwid),
12321235
&rpl_16byte_wwid_list->header.list_length);
@@ -1247,6 +1250,10 @@ static inline int pqi_report_phys_luns(struct pqi_ctrl_info *ctrl_info, void **b
12471250
*buffer = rpl_16byte_wwid_list;
12481251

12491252
return 0;
1253+
1254+
out_free_rpl_list:
1255+
kfree(rpl_list);
1256+
return rc;
12501257
}
12511258

12521259
static inline int pqi_report_logical_luns(struct pqi_ctrl_info *ctrl_info, void **buffer)

0 commit comments

Comments
 (0)