lkml.org 
[lkml]   [2012]   [May]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH] tty: tty_mutex: fix lockdep warning in tty_lock_pair(v3)
From
On Sat, May 26, 2012 at 3:16 PM, Peter Zijlstra <peterz@infradead.org> wrote:

>
>
> 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);

I remember that the patch may cause kernel hang in
my test. I will test it again to see if it is good.

>
>
> 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.

You mean that the below is good usage of lock?

LOCK A
LOCK B

UNLOCK A
UNLOCK B


Thanks,
--
Ming Lei
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2012-05-26 11:41    [from the cache]
©2003-2011 Jasper Spaans