Skip to contentSkip to conversation

drm/amdkfd: Fix memory leaks according to error branches

PATCH Markus Elfring 3 participants 6 messages Jun 20, 2020 Kernel janitors

lore
Share & tools
lore
#0 lore raw
Quoted 7 lines

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.

I suggest to improve this change description.

* Can an other wording variant be nicer?

* Will the tag “Fixes” become helpful for the commit message?

Regards,
Markus

#1 lore raw
Quoted 11 lines · Markus Elfring
Quoted 7 lines

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.

I suggest to improve this change description.

* Can an other wording variant be nicer?

Markus's suggestion is as usual extremely imprecise. However, I also find the message quite unclear.

It would be good to always use English words. alloc and err are not English words. Perhaps most people will figure out what they are abbreviations for, but it would be better to use a few more letters to make it so that no one has to guess.

Then there are a bunch of things that are connected by arrows with no spaces between them. The most obvious meaning of an arrow with no space around it is a variable dereference. After spending some mental effort, one can realize that that is not what you mean here. A layout like:

first_function ->

     second_function ->
       third_function

would be much more readable.

I don't know what "this patch maybe catched" means. Is "catched" supposed to be "caught" or "cached"? Overall, the sentence could be "Kmemleak could possibly detect this issue", or something like that. But I don't know what this means. Did you detect the problem with kmemleak? if you did not detect the problem with kmemleak, and overall you don't know whether kmemleak would detect the bug or not, is this information useful at all for the patch?

"These changes are to" makes a lot of words with no information. While it is perhaps not necessary to slavishly follow the rule about using the imperative, if it is convenient to use the imperative, doing so eliminates such meaningless phrases.

memleak is also not an English word. Memory leak is only a few more characters, and doesn't require the reader to make the small extra effort to figure out what you mean.

julia

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+dG8gZmlndXJlIG91dCB3aGF0IHlvdSBtZWFuLgo+ Cj5qdWxpYQo+Cj4+Cj4+ICogV2lsbCB0aGUgdGFnIOKAnEZpeGVz4oCdIGJlY29tZSBoZWxwZnVs IGZvciB0aGUgY29tbWl0IG1lc3NhZ2U/Cj4+Cj4+IFJlZ2FyZHMsCj4+IE1hcmt1cwo+PgoNCg0K

#3 lore raw
Quoted 61 lines · Bernard

From: Julia Lawall <[email protected]>
Date: 2020-06-20 17:37:19
To: Markus Elfring <[email protected]>
Cc: Bernard Zhao <[email protected]>,[email protected],[email protected],[email protected],[email protected],[email protected],Alex Deucher <[email protected]>,"Christian König" <[email protected]>,"Felix Kühling" <[email protected]>,Daniel Vetter <[email protected]>,David Airlie <[email protected]>
Subject: Re: [PATCH v2] drm/amdkfd: Fix memory leaks according to error branches>

Quoted 34 lines · Markus Elfring
Quoted 9 lines
Quoted 8 lines

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.

Quoted 3 lines

I suggest to improve this change description.

* Can an other wording variant be nicer?

Markus's suggestion is as usual extremely imprecise. However, I also find the message quite unclear.

It would be good to always use English words. alloc and err are not English words. Perhaps most people will figure out what they are abbreviations for, but it would be better to use a few more letters to make it so that no one has to guess.

Then there are a bunch of things that are connected by arrows with no spaces between them. The most obvious meaning of an arrow with no space around it is a variable dereference. After spending some mental effort, one can realize that that is not what you mean here. A layout like:

first_function ->

    second_function ->
      third_function

would be much more readable.

Quoted 7 lines

I don't know what "this patch maybe catched" means. Is "catched" supposed to be "caught" or "cached"? Overall, the sentence could be "Kmemleak could possibly detect this issue", or something like that. But I don't know what this means. Did you detect the problem with kmemleak? if you did not detect the problem with kmemleak, and overall you don't know whether kmemleak would detect the bug or not, is this information useful at all for the patch?

Hi:

Kmemleak detected a memory leak as below:
kobject_init_and_add->

	kobject_add_varg->
		kobject_set_name_vargs->
			kvasprintf_const->
				kstrdup_const->
					kstrdup->
						kmalloc_track_caller->
							kmalloc_slab
Quoted 2 lines

If kobject_init_and_add is called, but kobject_put is not called in the error branch. This will be detected by kmemleak.

Thanks. This is much more understandable. The last part still seems a bit hypothetical. After the trace, which explain why you made the change, just say what you did in the patch to fix the problem.

julia

Quoted 23 lines

BR//Bernard

Quoted 17 lines

"These changes are to" makes a lot of words with no information. While it is perhaps not necessary to slavishly follow the rule about using the imperative, if it is convenient to use the imperative, doing so eliminates such meaningless phrases.

memleak is also not an English word. Memory leak is only a few more characters, and doesn't require the reader to make the small extra effort to figure out what you mean.

julia

Quoted 6 lines

* Will the tag “Fixes” become helpful for the commit message?

Regards,
Markus

#4 lore raw
In reply to Julia Lawall
Quoted 5 lines
Quoted 3 lines

I suggest to improve this change description.

* Can an other wording variant be nicer?

Markus's suggestion is as usual extremely imprecise.

I pointed a general possibility out. I did not propose an exact wording alternative as it happened for other patches.

Quoted 1 line

However, I also find the message quite unclear.

I find this response interesting.

Quoted 1 line

It would be good to always use English words.

I am curious how this review will evolve further with such information also after the third patch version.
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/patchwork/patch/1260303/

Regards,
Markus

#5 lore raw
In reply to Julia Lawall
Quoted 3 lines

memleak is also not an English word. Memory leak is only a few more characters, and doesn't require the reader to make the small extra effort to figure out what you mean.

Would you like to achieve similar adjustments at any more places?

How do you think about effects from a corresponding jargon?
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/drivers/gpu/drm/msm/msm_submitqueue.c?id7d3819633cd520e3f95df541a04644aab4c657

Regards,
Markus