Re: [PATCH] use mutex instead of semaphore in tty_io.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <[email protected]> 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                  `-
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux