lkml.org 
[lkml]   [2007]   [Apr]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [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@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: 2007-04-25 21:17    [W:0.061 / U:0.536 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site