Re: Buggy __free(kfree) usage pattern already in tree

From: Peter Zijlstra
Date: Tue Sep 19 2023 - 15:35:27 EST


On Tue, Sep 19, 2023 at 03:10:38PM +0200, Peter Zijlstra wrote:

> This isn't exactly nice..
>
> I tried something like:
>
> scoped_cond_guard (mutex_intr, return -EINTR, &task->signal->cred_guard_mutex) {
> ...
> }
>
> Which I can make work, but then I also tried to capture my other case:
>
> scoped_cond_guard (rwsem_down_intr, if (task) return -EINTR,
> task ? &task->signal->exec_guard_mutex : NULL) {
>
> ...
> }
>
> But I can't get that to work because of that extra if, the not case
> doesn't fall through and do the body.
>
> Anyway, I'll poke more..


#define scoped_cond_guard(_name, _label, args...) \
for (CLASS(_name, scope)(args), \
*done = NULL; !done; done = (void *)1) \
if (!__guard_ptr(_name)(&scope)) goto _label; \
else

Allows one to write:

scoped_cond_guard (rwsem_down_intr, no_lock,
task ? &task->signal->exec_guard_mutex : NULL) {

if (0) {
no_lock:
if (task)
return -EINTR;
}

... block that holds exec_guard_mutex if task ...
}

Still not exactly pretty, but perhaps better than before...