workqueue: Fix double kfree for rescuer
Subsystems (2)
PATCH 1/1 workqueue: Fix double kfree for rescuer
From: Zhang Qiang <[email protected]>
The duplicate memory release should be deleted from the implementation of the callback function "rcu_free_wq".
--- kernel/workqueue.c | 1 - 1 file changed, 1 deletion(-)
kernel/workqueue.c +0 -1
@@ -3491,7 +3491,6 @@ static void rcu_free_wq(struct rcu_head *rcu)else free_workqueue_attrs (wq->unbound_attrs); -kfree (wq->rescuer);kfree (wq); }
Signature · 1 line
2.24.1
Re: [PATCH v2] workqueue: Delete duplicate kfree() call for “rescuer” from rcu_free_wq()
Quoted 2 lines
The duplicate memory release should be deleted from the implementation of the callback function "
rcu_free_wq".
I would find it nicer if you would have extended my simple wording suggestion.
1. Mention conditions:
The callback function “rcu_free_wq” could be called after memory was released for “rescuer” already.
2. Specify the desired action:
Thus delete a misplaced call of the function “kfree”.
3. Please keep the patch versioning consistent.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?id=9cb1fd0efd195590b828b9b865421ad345a4a145#n709
Regards,
Markus
Quoted 2 lines
The duplicate memory release should be deleted from the implementation of the callback function "
rcu_free_wq".
I tried to help with the selection of a better commit message.
I have taken another look also at the implementation of the function “destroy_workqueue”.
* The function call “destroy_workqueue” can be performed there in an if branch after the statement “wq->rescuer = NULL” was executed.
* This data processing is independent from a possible call of the function “call_rcu(&wq->rcu, rcu_free_wq)” in another if branch. Thus it seems that a null pointer is intentionally passed by a data structure member to this callback function on demand.
The corresponding call of the function “kfree” can tolerate this special case.
Now I find that the proposed change can be inappropriate.
Regards,
Markus
Quoted 2 lines
* The function call “destroy_workqueue” can be performed there in an if branch after the statement “wq->rescuer = NULL” was executed.
Another correction:
* The function call “kfree(rescuer)” can be performed there in an if branch after the statement “wq->rescuer = NULL” was executed.
Regards,
Markus
I see, kfree does nothing with null pointers and direct return. but again kfree is not a good suggestion.
Quoted 21 lines · Markus Elfring
Quoted 2 lines
The duplicate memory release should be deleted from the implementation of the callback function "
rcu_free_wq".I tried to help with the selection of a better commit message.
I have taken another look also at the implementation of the function “destroy_workqueue”.* The function call “destroy_workqueue” can be performed there in an if branch after the statement “wq->rescuer = NULL” was executed.
* This data processing is independent from a possible call of the function “call_rcu(&wq->rcu, rcu_free_wq)” in another if branch. Thus it seems that a null pointer is intentionally passed by a data structure member to this callback function on demand.
The corresponding call of the function “kfree” can tolerate this special case.Now I find that the proposed change can be inappropriate.
Regards,
Markus
Quoted 2 lines
I see, kfree does nothing with null pointers and direct return. but again kfree is not a good suggestion.
I have got the impression that the implementation detail is important here if non-null pointers (according to valid rescuer objects) are occasionally passed by the corresponding data structure member for the callback function “rcu_free_wq”.
Can another clarification attempt reduce unwanted confusion for this patch review?
Regards,
Markus
Thanks for your advice.
The rescuer null pointer is intentionally passed by a data structure? and also I read the code of workqueue again, when destroy_workqueue is called, after "wq->rescuer = NULL" was executed, The scenario described below does not happen
"if non-null pointers (according to valid rescuer objects) are occasionally passed by the corresponding data structure member for the callback function "rcu_free_wq"."
Quoted 12 lines · Markus Elfring
Quoted 2 lines
I see, kfree does nothing with null pointers and direct return. but again kfree is not a good suggestion.
I have got the impression that the implementation detail is important here if non-null pointers (according to valid rescuer objects) are occasionally passed by the corresponding data structure member for the callback function “rcu_free_wq”.
Can another clarification attempt reduce unwanted confusion for this patch review?Regards,
Markus