2022-01-17 03:00:12

by Xiaoke Wang

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

From: Xiaoke Wang <[email protected]>

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 <[email protected]>
---
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(+)

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)) {
--


2022-01-17 17:03:59

by Bean Huo

[permalink] [raw]
Subject: Re: [PATCH v2] scsi: ufs: ufshcd-pltfrm: check the return value of devm_kstrdup()

On Sun, 2022-01-16 at 11:06 +0800, [email protected] wrote:
> From: Xiaoke Wang <[email protected]>
>
>
>
> 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 <[email protected]>
Reviewed-by: Bean Huo <[email protected]>

2022-01-21 15:11:26

by Martin K. Petersen

[permalink] [raw]
Subject: Re: [PATCH v2] scsi: ufs: ufshcd-pltfrm: check the return value of devm_kstrdup()


> 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!

--
Martin K. Petersen Oracle Linux Engineering

2022-01-25 08:58:47

by Martin K. Petersen

[permalink] [raw]
Subject: Re: [PATCH v2] scsi: ufs: ufshcd-pltfrm: check the return value of devm_kstrdup()

On Sun, 16 Jan 2022 11:06:49 +0800, [email protected] wrote:

> From: Xiaoke Wang <[email protected]>
>
> 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-fixes, thanks!

[1/1] scsi: ufs: ufshcd-pltfrm: check the return value of devm_kstrdup()
https://git.kernel.org/mkp/scsi/c/a65b32748f45

--
Martin K. Petersen Oracle Linux Engineering