From: Matthias Kaehlcke <matthias.kaehlcke@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Christoph Hellwig <hch@infradead.org>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] use mutex instead of semaphore in tty_io.c
Date: Fri, 1 Jun 2007 09:48:21 +0200 [thread overview]
Message-ID: <20070601074821.GS14284@traven> (raw)
In-Reply-To: <20070531153712.de2f8a68.akpm@linux-foundation.org>
El Thu, May 31, 2007 at 03:37:12PM -0700 Andrew Morton ha dit:
> On Thu, 31 May 2007 15:42:26 +0200
> Matthias Kaehlcke <matthias.kaehlcke@gmail.com> wrote:
>
> > drivers/char/tty_io.c: Use spinlock instead of a (binary) semaphore
> >
>
> hm.
>
> >
>
> We end up with this:
>
> /* find a device that is not in use. */
> if (!idr_pre_get(&allocated_ptys, GFP_KERNEL))
> return -ENOMEM;
>
> spin_lock(&allocated_ptys_lock);
>
> idr_ret = idr_get_new(&allocated_ptys, NULL, &index);
> if (idr_ret < 0) {
> spin_unlock(&allocated_ptys_lock);
> if (idr_ret == -EAGAIN)
> return -ENOMEM;
> return -EIO;
> }
> if (index >= pty_limit) {
> idr_remove(&allocated_ptys, index);
> spin_unlock(&allocated_ptys_lock);
> return -EIO;
> }
> spin_unlock(&allocated_ptys_lock);
>
> this leaves a small window in which another thread can come in and steal
> away the idr tree's reserves, causing the idr_get_new() to fail. It's
> highly improbable, but it's real.
i agree, thanks for pointing it out
> Hence I think a straight semaphore->mutex conversion would be better.
that leads us back to the initial patch. christoph: is that ok for
you or do you have another proposal?
--
Matthias Kaehlcke
Linux Application Developer
Barcelona
The assumption that what currently exists must necessarily
exist is the acid that corrodes all visionary thinking
.''`.
using free software / Debian GNU/Linux | http://debian.org : :' :
`. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4 `-
next prev parent reply other threads:[~2007-06-01 7:46 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-25 15:49 [PATCH] use mutex instead of semaphore in tty_io.c Matthias Kaehlcke
2007-04-25 19:13 ` Christoph Hellwig
2007-04-25 19:46 ` Matthias Kaehlcke
2007-04-25 19:45 ` Christoph Hellwig
2007-05-31 13:42 ` Matthias Kaehlcke
2007-05-31 13:59 ` Christoph Hellwig
2007-05-31 22:37 ` Andrew Morton
2007-06-01 7:48 ` Matthias Kaehlcke [this message]
2007-04-26 2:20 ` Andrew Morton
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=20070601074821.GS14284@traven \
--to=matthias.kaehlcke@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=hch@infradead.org \
--cc=linux-kernel@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.