Skip to content

Commit 5e0bf3e

Browse files
Huai-Yuan Liumartinkpetersen
authored andcommitted
scsi: lpfc: Fix a possible null pointer dereference
In function lpfc_xcvr_data_show, the memory allocation with kmalloc might fail, thereby making rdp_context a null pointer. In the following context and functions that use this pointer, there are dereferencing operations, leading to null pointer dereference. To fix this issue, a null pointer check should be added. If it is null, use scnprintf to notify the user and return len. Fixes: 479b091 ("scsi: lpfc: Create a sysfs entry called lpfc_xcvr_data for transceiver info") Signed-off-by: Huai-Yuan Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Justin Tee <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 14d3835 commit 5e0bf3e

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

drivers/scsi/lpfc/lpfc_attr.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,6 +1907,11 @@ lpfc_xcvr_data_show(struct device *dev, struct device_attribute *attr,
19071907

19081908
/* Get transceiver information */
19091909
rdp_context = kmalloc(sizeof(*rdp_context), GFP_KERNEL);
1910+
if (!rdp_context) {
1911+
len = scnprintf(buf, PAGE_SIZE - len,
1912+
"SPF info NA: alloc failure\n");
1913+
return len;
1914+
}
19101915

19111916
rc = lpfc_get_sfp_info_wait(phba, rdp_context);
19121917
if (rc) {

0 commit comments

Comments
 (0)