[PATCH v3] drm/amd: Fix memory leak according to error branch

Felix Kuehling felix.kuehling at amd.com
Sat Jun 20 14:56:24 UTC 2020


Am 2020-06-20 um 9:21 a.m. schrieb Julia Lawall:
>
> On Sat, 20 Jun 2020, Markus Elfring wrote:
>
>>> The function kobject_init_and_add alloc memory like:
>>> kobject_init_and_add->kobject_add_varg->kobject_set_name_vargs
>>> ->kvasprintf_const->kstrdup_const->kstrdup->kmalloc_track_caller
>>> ->kmalloc_slab, in err branch this memory not free. If use
>>> kmemleak, this path maybe catched.
>>> These changes are to add kobject_put in kobject_init_and_add
>>> failed branch, fix potential memleak.
>>>>> Changes since V2:
>>> *remove duplicate kobject_put in kfd_procfs_init.
>> Under which circumstances are going to improve this change description accordingly?
> Bernard, please update the log message as well.  The mail you sent was
> much more clear, but mail just gets lost over time.  The log message
> itself should be improved.

Hi all,

The behaviour of kobject_init_and_add is documented in the kernel
source: https://elixir.bootlin.com/linux/v5.7.2/source/lib/kobject.c#L459:

* If this function returns an error, kobject_put() must be called to
* properly clean up the memory associated with the object. This is the
* same type of error handling after a call to kobject_add() and kobject
* lifetime rules are the same here.

No need to have a complicated explanation with a call stack in the
change description. Just point to the kernel documentation.

Regards,
  Felix


>
> julia
>
>> Would you like to add the tag “Fixes” to the commit message?
>>
>> Regards,
>> Markus
> >
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/amd-gfx/attachments/20200620/a8e3c8f6/attachment.htm>


More information about the amd-gfx mailing list