kstrdup() can return NULL if some internal memory errors happen, so it is better to check the return value of it. Signed-off-by: xkernel <xkernel.wang@xxxxxxxxxxx> --- drivers/scsi/ufs/ufshcd-pltfrm.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/ufs/ufshcd-pltfrm.c b/drivers/scsi/ufs/ufshcd-pltfrm.c index 8859c13..32e7bd3 100644 --- a/drivers/scsi/ufs/ufshcd-pltfrm.c +++ b/drivers/scsi/ufs/ufshcd-pltfrm.c @@ -89,9 +89,15 @@ static int ufshcd_parse_clock_info(struct ufs_hba *hba) goto out; } + clki->name = kstrdup(name, GFP_KERNEL); + if (!clki->name) { + ret = -ENOMEM; + devm_kfree(dev, clki); + goto out; + } + clki->min_freq = clkfreq[i]; clki->max_freq = clkfreq[i+1]; - clki->name = kstrdup(name, GFP_KERNEL); if (!strcmp(name, "ref_clk")) clki->keep_link_active = true; dev_dbg(dev, "%s: min %u max %u name %s\n", "freq-table-hz", @@ -127,6 +133,10 @@ static int ufshcd_populate_vreg(struct device *dev, const char *name, return -ENOMEM; vreg->name = kstrdup(name, GFP_KERNEL); + if (!vreg->name) { + devm_kfree(dev, vreg); + return -ENOMEM; + } snprintf(prop_name, MAX_PROP_SIZE, "%s-max-microamp", name); if (of_property_read_u32(np, prop_name, &vreg->max_uA)) { --