Message ID | tencent_D3914A6FFF832049CC70B9411CAD1492E108@qq.com |
---|---|
State | New |
Headers | show |
Series | scsi: ufs: ufshcd-pltfrm: check the return value of kstrdup() | expand |
On 12/11/21 10:14, xkernel wrote: > 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@foxmail.com> Is xkernel the name of a person or the name of a robot? Patches should be signed by a person even if these have been generated by a robot. > + clki->name = kstrdup(name, GFP_KERNEL); > + if (!clki->name) { > + ret = -ENOMEM; > + devm_kfree(dev, clki); > + goto out; > + } Is the devm_kfree() call necessary? Is it useful? Thanks, Bart.
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)) {
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@foxmail.com> --- drivers/scsi/ufs/ufshcd-pltfrm.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) --