[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <tencent_D3914A6FFF832049CC70B9411CAD1492E108@qq.com>
Date: Sun, 12 Dec 2021 02:14:16 +0800
From: xkernel <xkernel.wang@...mail.com>
To: jejb@...ux.ibm.com, martin.petersen@...cle.com
Cc: alim.akhtar@...sung.com, avri.altman@....com,
linux-scsi@...r.kernel.org, linux-kernel@...r.kernel.org,
xkernel <xkernel.wang@...mail.com>
Subject: [PATCH] scsi: ufs: ufshcd-pltfrm: check the return value of kstrdup()
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@...mail.com>
---
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)) {
--
Powered by blists - more mailing lists