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