Re: [PATCH V2 RESEND] scsi: lpfc: Fix a possible null pointer dereference

From: Justin Tee
Date: Fri Jun 14 2024 - 12:26:52 EST


Hi Huai-Yuan,

> diff --git a/drivers/scsi/lpfc/lpfc_attr.c b/drivers/scsi/lpfc/lpfc_attr.c
> index b1c9107d3408..94d968a255ff 100644
> --- a/drivers/scsi/lpfc/lpfc_attr.c
> +++ b/drivers/scsi/lpfc/lpfc_attr.c
> @@ -1904,6 +1904,8 @@ lpfc_xcvr_data_show(struct device *dev, struct device_attribute *attr,
>
> /* Get transceiver information */
> rdp_context = kmalloc(sizeof(*rdp_context), GFP_KERNEL);
> + if (!rdp_context)
> + goto out_free_rdp;

Understood that kfree(NULL) essentially translates to no-op, but I'd
prefer that we return len here instead of goto out_free_rdp because
there really is nothing to free if kmalloc failed.

Thanks,
Justin