All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] scsi: ufs: ufshcd-pltfrm: check the return value of devm_kstrdup()
@ 2022-01-16  3:06 xkernel.wang
  2022-01-17  9:02 ` Bean Huo
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: xkernel.wang @ 2022-01-16  3:06 UTC (permalink / raw)
  To: bvanassche, jejb, martin.petersen
  Cc: alim.akhtar, avri.altman, linux-scsi, linux-kernel, Xiaoke Wang

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(+)

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] scsi: ufs: ufshcd-pltfrm: check the return value of devm_kstrdup()
  2022-01-16  3:06 [PATCH v2] scsi: ufs: ufshcd-pltfrm: check the return value of devm_kstrdup() xkernel.wang
@ 2022-01-17  9:02 ` Bean Huo
  2022-01-19  3:37 ` Martin K. Petersen
  2022-01-25  5:40 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Bean Huo @ 2022-01-17  9:02 UTC (permalink / raw)
  To: xkernel.wang, bvanassche, jejb, martin.petersen
  Cc: alim.akhtar, avri.altman, linux-scsi, linux-kernel

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>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] scsi: ufs: ufshcd-pltfrm: check the return value of devm_kstrdup()
  2022-01-16  3:06 [PATCH v2] scsi: ufs: ufshcd-pltfrm: check the return value of devm_kstrdup() xkernel.wang
  2022-01-17  9:02 ` Bean Huo
@ 2022-01-19  3:37 ` Martin K. Petersen
  2022-01-25  5:40 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2022-01-19  3:37 UTC (permalink / raw)
  To: xkernel.wang
  Cc: bvanassche, jejb, martin.petersen, alim.akhtar, avri.altman,
	linux-scsi, linux-kernel


> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] scsi: ufs: ufshcd-pltfrm: check the return value of devm_kstrdup()
  2022-01-16  3:06 [PATCH v2] scsi: ufs: ufshcd-pltfrm: check the return value of devm_kstrdup() xkernel.wang
  2022-01-17  9:02 ` Bean Huo
  2022-01-19  3:37 ` Martin K. Petersen
@ 2022-01-25  5:40 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2022-01-25  5:40 UTC (permalink / raw)
  To: xkernel.wang, bvanassche, jejb
  Cc: Martin K . Petersen, linux-kernel, avri.altman, linux-scsi, alim.akhtar

On Sun, 16 Jan 2022 11:06:49 +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.
> 
> 

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-01-25  5:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-16  3:06 [PATCH v2] scsi: ufs: ufshcd-pltfrm: check the return value of devm_kstrdup() xkernel.wang
2022-01-17  9:02 ` Bean Huo
2022-01-19  3:37 ` Martin K. Petersen
2022-01-25  5:40 ` Martin K. Petersen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.