Re: [PATCH] rxrpc: fix bad unlock balance in rxrpc_do_sendmsg
From: Dan Carpenter
Date: Mon Aug 22 2022 - 10:07:13 EST
On Mon, Aug 22, 2022 at 07:55:27PM +0600, Khalid Masum wrote:
> >
> > /*
> > + * @holding_mutex: An indication whether caller can still holds
> > + * the call->user_mutex when returned to caller.
>
> Maybe we can use mutex_is_locked instead of using the holding_mutex
> parameter to get whether call->user_mutex is still held.
That doesn't work. What if there is contention for the lock and someone
else took it. Locks under contention are sort of the whole point of
locking so it's highly likely.
I do kind of feel the code has a layering violation. I'd prefer instead
of "I am setting this variable to true to reflect the caller blah blah",
the variable could just be set in the caller. I'd probably flip it
around and call it "dropped_lock" instead of "holding_lock".
bool dropped_lock = false;
...
if (!dropped_lock)
mutex_unlock();
That way only the callers and the function which drops the lock need to
be involved with setting the variable.
regards,
dan carpenter