[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20070425191359.GA13241@infradead.org>
Date: Wed, 25 Apr 2007 20:13:59 +0100
From: Christoph Hellwig <hch@...radead.org>
To: Matthias Kaehlcke <matthias.kaehlcke@...il.com>,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] use mutex instead of semaphore in tty_io.c
On Wed, Apr 25, 2007 at 05:49:34PM +0200, Matthias Kaehlcke wrote:
> drivers/char/tty_io.c uses a semaphore as mutex. use the mutex API
> instead of the (binary) semaphore
This looks like it should be a spinlock:
> - down(&allocated_ptys_lock);
> + mutex_lock(&allocated_ptys_lock);
> idr_remove(&allocated_ptys, idx);
> - up(&allocated_ptys_lock);
> + mutex_unlock(&allocated_ptys_lock);
idr_remove is a quick operation that doesn't sleep.
> @@ -2639,24 +2639,24 @@ static int ptmx_open(struct inode * inode, struct file * filp)
> nonseekable_open(inode, filp);
>
> /* find a device that is not in use. */
> - down(&allocated_ptys_lock);
> + mutex_lock(&allocated_ptys_lock);
> if (!idr_pre_get(&allocated_ptys, GFP_KERNEL)) {
> - up(&allocated_ptys_lock);
The idr_pre_get should be moved out of the lock, that's the whole
point for it's existance..
> + mutex_unlock(&allocated_ptys_lock);
> return -ENOMEM;
> }
> idr_ret = idr_get_new(&allocated_ptys, NULL, &index);
> if (idr_ret < 0) {
> - up(&allocated_ptys_lock);
> + mutex_unlock(&allocated_ptys_lock);
> if (idr_ret == -EAGAIN)
> return -ENOMEM;
> return -EIO;
> }
> if (index >= pty_limit) {
> idr_remove(&allocated_ptys, index);
> - up(&allocated_ptys_lock);
> + mutex_unlock(&allocated_ptys_lock);
> return -EIO;
> }
> - up(&allocated_ptys_lock);
> + mutex_unlock(&allocated_ptys_lock);
And idr_get_new is another quick, non-blocking operation.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists