Re: [PATCH] scsi: ufs: ufshcd-pltfrm: check the return value of kstrdup()

From: Xiaoke Wang
Date: Sun Dec 12 2021 - 20:58:10 EST


On 12/12/21 22:32, Bart Van Assche wrote:
> 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?

Note: the last mail seems fail because of the html content.

Sorry about that, xkernel is my English name I named myself, my full
name in Chinese format is "Xiaoke Wang". Thank you for your
suggestion, I will consider using my official name in the future.

clki is allocated on above of kstrdup(), line 86-90, and if clki is NULL
will return -ENOMEM which is the same return value with the patch. So
I think clki should be freed to prevent potential memory leak:
> clki = devm_kzalloc(dev, sizeof(*clki), GFP_KERNEL);
> if (!clki) {
> ret = -ENOMEM;
> goto out;
> }

vreg is in similar case.