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

From: Linus Torvalds
Date: Fri Sep 15 2023 - 18:11:56 EST


On Fri, 15 Sept 2023 at 14:50, Linus Torvalds
<torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> Call it "cond_guard()", and make the syntax otherwise be the same as
> "scoped_guard()", iow, using a unique ID for the guard name.

I *think* you don't even need a new "cond_guard()" macro.

This might be as simple as having our current scoped_guard() macro
have the conditional

"scope.lock && !done"

instead of just the current "!done".

Then you introduce "trylock" variants that conditionally set "lock = 1".

I dunno. Maybe there's something really obvious I'm missing, but I
really think that gives us the option to literally do just

scoped_guard(try_mutex, ..somelock..) {
...
}

and all it requires is for us to declare a "try_mutex" lock guard class.

Ok, so the current DEFINE_LOCK_GUARD_x() macros clearly set .lock to 1
unconditionally, so there's a small matter of extending the lock side
to be conditional...

"SMOP".

Linus