2020-05-27 04:51:50

by Zhang, Qiang

[permalink] [raw]
Subject: [PATCH v4] workqueue: Remove unnecessary kfree(NULL)

From: Zhang Qiang <[email protected]>

The callback function "rcu_free_wq" could be called after memory
was released for "wq->rescuer" already and assignment is empty. so
remove unnecessary kfree(NULL).

Fixes: def98c84b6cd ("workqueue: Fix spurious sanity check failures in destroy_workqueue()")
Fixes: 8efe1223d73c ("workqueue: Fix missing kfree(rescuer) in destroy_workqueue()")

Signed-off-by: Zhang Qiang <[email protected]>
---
v1->v2->v3->v4:
Modify wrong submission information.

kernel/workqueue.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 891ccad5f271..a2451cdcd503 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -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);
}

--
2.24.1


2020-05-27 10:05:29

by Markus Elfring

[permalink] [raw]
Subject: Re: [PATCH v4] workqueue: Remove unnecessary kfree() call in rcu_free_wq()

> The callback function "rcu_free_wq" could be called after memory
> was released for "wq->rescuer" already and assignment is empty. so
> remove unnecessary kfree(NULL).

I have got the impression that also this wording approach contains weaknesses.
How do you think about a wording variant like the following?

The data structure member “wq->rescuer” was reset to a null pointer
in one if branch. It was passed to a call of the function “kfree”
in the callback function “rcu_free_wq” (which was eventually executed).
The function “kfree” does not perform more meaningful data processing
for a passed null pointer (besides immediately returning from such a call).
Thus delete this function call which became unnecessary with the referenced
software update.


> Fixes: def98c84b6cd ("workqueue: Fix spurious sanity check failures in destroy_workqueue()")

This change triggered another collateral evolution finally.
Would you like to detect similarly questionable function calls
by advanced source code analysis?


> Fixes: 8efe1223d73c ("workqueue: Fix missing kfree(rescuer) in destroy_workqueue()")

Please delete this tag from the change description
(because I find that it is not so relevant here.)


> v1->v2->v3->v4:
> Modify wrong submission information.

Will it be nicer to mention the adjustment of the commit message?

Regards,
Markus