From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753299AbZHCRz7 (ORCPT ); Mon, 3 Aug 2009 13:55:59 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753200AbZHCRz6 (ORCPT ); Mon, 3 Aug 2009 13:55:58 -0400 Received: from smtp1.linux-foundation.org ([140.211.169.13]:59235 "EHLO smtp1.linux-foundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751971AbZHCRz6 (ORCPT ); Mon, 3 Aug 2009 13:55:58 -0400 Date: Mon, 3 Aug 2009 10:55:34 -0700 (PDT) From: Linus Torvalds X-X-Sender: torvalds@localhost.localdomain To: Alan Cox cc: OGAWA Hirofumi , Sergey Senozhatsky , Linux Kernel Mailing List , Greg KH Subject: [PATCH 0/2] proper tty-ldisc refcounting (was Re: WARNING at: drivers/char/tty_ldisc.c) In-Reply-To: Message-ID: References: <20090802120120.GA3097@localdomain.by> <20090802190514.GA3278@localdomain.by> <87k51l9apo.fsf@devron.myhome.or.jp> <20090802234851.3fd1ac2c@lxorguk.ukuu.org.uk> User-Agent: Alpine 2.01 (LFD 1184 2008-12-16) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 2 Aug 2009, Linus Torvalds wrote: > > > You could just finish the ldisc refcounting. The last set of patches you > > had off me split tty->ldisc from struct tty ready to do exactly that and > > I don't think there is anything left that stops it happening now (It was > > just not ready in time) > > I considered it, and it didn't look horrible (the thing really is pretty > self-contained in tty_ldisc_try() and tty_ldisc_deref()). Here we are. It wasn't a straight conversion, because the old code really didn't think of the refcounts as lifetimes, but it wasn't too bad either. And doing the proper refcounting makes all the stupid "wait for idle" go away, so it actually removes code: drivers/char/tty_ldisc.c | 145 ++++++++++++++------------------------------ include/linux/tty_ldisc.h | 2 +- 2 files changed, 47 insertions(+), 100 deletions(-) and generally simplifies the logic. That said, looking through the code as I did this, I consciously avoided doing some other cleanups that really should be done some day. The code is chock-full of crazy stuff, where we just do o_ldisc = tty->ldisc; with dubious locking. None of that is _new_ though, and most of it is in the "replace one ldisc with another" code. And for all I know, maybe it's all fine, it's just very much not _obviously_ correct. As far as I can tell, this short series should not introduce any new problems, but hey, maybe it leaks ldisc references like mad because I made some silly mistake. It's a _fairly_ straightforward cleanup, but it's a big cnnceptual change to go from a model with a "wait until idle and then free" to a model of "count users and free on last use", and I could easily have screwed up something. "It works for me"(tm), including a shutdown/reboot cycle. Sergey, mind testing? You seem to be very good at consistently triggering odd things in the tty layer that few other people seem to ever hit. Greg - I've signed off on these, but I wasn't planning on committing them to my master branch. So perhaps you could do these as the new tty maintainer, assuming we get an ack from Alan and testing by Sergey. Linus