From: Peter Zijlstra <peterz@infradead.org>
To: Ming Lei <ming.lei@canonical.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-kernel@vger.kernel.org, Ming Lei <tom.leiming@gmail.com>,
Alan Cox <alan@linux.intel.com>, Arnd Bergmann <arnd@arndb.de>
Subject: Re: [PATCH] tty: tty_mutex: fix lockdep warning in tty_lock_pair(v3)
Date: Sat, 26 May 2012 09:16:04 +0200 [thread overview]
Message-ID: <1338016564.14636.4.camel@twins> (raw)
In-Reply-To: <1338000869-15129-1-git-send-email-ming.lei@canonical.com>
On Sat, 2012-05-26 at 10:54 +0800, Ming Lei wrote:
> From: Ming Lei <tom.leiming@gmail.com>
> Cc: Alan Cox <alan@linux.intel.com>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Oh very much not!
> Signed-off-by: Ming Lei <ming.lei@canonical.com>
> ---
> v3:
> fix unlock order in tty_unlock_pair
>
> drivers/tty/tty_mutex.c | 28 +++++++++++++++++++++-------
> 1 file changed, 21 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/tty/tty_mutex.c b/drivers/tty/tty_mutex.c
> index 69adc80..c7f4523 100644
> @@ -43,11 +49,14 @@ void __lockfunc tty_lock_pair(struct tty_struct *tty,
> {
> if (tty < tty2) {
> tty_lock(tty);
> - tty_lock(tty2);
> + tty_lock_nested(tty2, SINGLE_DEPTH_NESTING);
> } else {
> - if (tty2 && tty2 != tty)
> + int nested = 0;
> + if (tty2 && tty2 != tty) {
> tty_lock(tty2);
> - tty_lock(tty);
> + nested = SINGLE_DEPTH_NESTING;
> + }
> + tty_lock_nested(tty, nested);
> }
> }
> EXPORT_SYMBOL(tty_lock_pair);
I've still to hear what's wrong with a simple:
if (!tty2 || tty == tty2) {
tty_lock(tty);
return;
}
if (tty > tty2)
swap(tty, tty2);
tty_lock(tty);
tty_lock_nested(tty2, SINGLE_DEPTH_NESTING);
That's a lot more readable than the proposed code.
> @@ -55,8 +64,13 @@ EXPORT_SYMBOL(tty_lock_pair);
> void __lockfunc tty_unlock_pair(struct tty_struct *tty,
> struct tty_struct *tty2)
> {
> - tty_unlock(tty);
> - if (tty2 && tty2 != tty)
> + if (tty < tty2) {
> tty_unlock(tty2);
> + tty_unlock(tty);
> + } else {
> + tty_unlock(tty);
> + if (tty2 && tty2 != tty)
> + tty_unlock(tty2);
> + }
> }
> EXPORT_SYMBOL(tty_unlock_pair);
This is complete crap, unlock order doesn't matter.
next prev parent reply other threads:[~2012-05-26 7:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-26 2:54 [PATCH] tty: tty_mutex: fix lockdep warning in tty_lock_pair(v3) Ming Lei
2012-05-26 7:16 ` Peter Zijlstra [this message]
2012-05-26 9:23 ` Ming Lei
2012-05-26 16:39 ` Peter Zijlstra
2012-05-27 4:37 ` Ming Lei
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1338016564.14636.4.camel@twins \
--to=peterz@infradead.org \
--cc=alan@linux.intel.com \
--cc=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ming.lei@canonical.com \
--cc=tom.leiming@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox