diff mbox series

[v2] scsi: ufs: ufshcd-pltfrm: check the return value of devm_kstrdup()

Message ID tencent_4257E15D4A94FF9020DDCC4BB9B21C041408@qq.com
State New
Headers show
Series [v2] scsi: ufs: ufshcd-pltfrm: check the return value of devm_kstrdup() | expand

Commit Message

Xiaoke Wang Jan. 16, 2022, 3:06 a.m. UTC
From: Xiaoke Wang <xkernel.wang@foxmail.com>

devm_kstrdup() returns pointer to allocated string on success,
NULL on failure. So it is better to check the return value of it.

Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
---
Changelogs:
1. Use my official name.
2. Synchronize with the latest source code(kstrdup -> devm_kstrdup).
3. Clear up useless code(devm_kfree).
 drivers/scsi/ufs/ufshcd-pltfrm.c | 7 +++++++
 1 file changed, 7 insertions(+)

--

Comments

Bean Huo Jan. 17, 2022, 9:02 a.m. UTC | #1
On Sun, 2022-01-16 at 11:06 +0800, xkernel.wang@foxmail.com wrote:
> From: Xiaoke Wang <xkernel.wang@foxmail.com>
> 
> 
> 
> devm_kstrdup() returns pointer to allocated string on success,
> 
> NULL on failure. So it is better to check the return value of it.
> 
> 
> 
> Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
Reviewed-by: Bean Huo <beanhuo@micron.com>
Martin K. Petersen Jan. 19, 2022, 3:37 a.m. UTC | #2
> devm_kstrdup() returns pointer to allocated string on success,
> NULL on failure. So it is better to check the return value of it.

Applied to 5.17/scsi-staging, thanks!
diff mbox series

Patch

diff --git a/drivers/scsi/ufs/ufshcd-pltfrm.c b/drivers/scsi/ufs/ufshcd-pltfrm.c
index d35b892..186540a 100644
--- a/drivers/scsi/ufs/ufshcd-pltfrm.c
+++ b/drivers/scsi/ufs/ufshcd-pltfrm.c
@@ -92,6 +92,11 @@  static int ufshcd_parse_clock_info(struct ufs_hba *hba)
 		clki->min_freq = clkfreq[i];
 		clki->max_freq = clkfreq[i+1];
 		clki->name = devm_kstrdup(dev, name, GFP_KERNEL);
+		if (!clki->name) {
+			ret = -ENOMEM;
+			goto out;
+		}
+
 		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 +132,8 @@  static int ufshcd_populate_vreg(struct device *dev, const char *name,
 		return -ENOMEM;
 
 	vreg->name = devm_kstrdup(dev, name, GFP_KERNEL);
+	if (!vreg->name)
+		return -ENOMEM;
 
 	snprintf(prop_name, MAX_PROP_SIZE, "%s-max-microamp", name);
 	if (of_property_read_u32(np, prop_name, &vreg->max_uA)) {