From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S937067AbXGMUBH (ORCPT ); Fri, 13 Jul 2007 16:01:07 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1758559AbXGMUAz (ORCPT ); Fri, 13 Jul 2007 16:00:55 -0400 Received: from smtp116.sbc.mail.sp1.yahoo.com ([69.147.64.89]:33429 "HELO smtp116.sbc.mail.sp1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1757643AbXGMUAz (ORCPT ); Fri, 13 Jul 2007 16:00:55 -0400 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=pacbell.net; h=Received:X-YMail-OSG:From:To:Subject:Date:User-Agent:Cc:References:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:Content-Disposition:Message-Id; b=DnauiwuwnikX06pgBncCxtkzN69cpFwBzxMk1eAZlBjc+SS4jl6neUftqXGev5wTXBwckRS9ZLUbnMRKsFMMk+7IFNprNRz4eGtaktA6huaRuelu529/+o68QbvUBTi/qtWpdEcQiCQr18c7gDBB0mGFFGefDIl5bi/7hHM6yPs= ; X-YMail-OSG: dMq2HxAVM1kljuRSP.A5jeKqCaJh9iV3ABDXTXGIVxORgo6f2G2Vlh_Vd0KohiqMvaQBZg1hRiow02ExDNLgj.2FzY9iTQw7Ps3SPG1IlIe5cXW_fZyKBZUj07Md From: David Brownell To: Matthias Kaehlcke Subject: Re: [PATCH 2/5] use mutex instead of semaphore in the USB gadget serial driver Date: Fri, 13 Jul 2007 13:00:52 -0700 User-Agent: KMail/1.9.6 Cc: dbrownell@users.sourceforge.net, linux-usb-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, alborchers@steinerpoint.com References: <20070713192023.GD18159@traven> <20070713192525.GF18159@traven> In-Reply-To: <20070713192525.GF18159@traven> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200707131300.52923.david-b@pacbell.net> Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org On Friday 13 July 2007, Matthias Kaehlcke wrote: > The USB gadget serial driver uses a semaphore as mutex. Use the > mutex API instead of the (binary) semaphore. > > Signed-off-by: Matthias Kaehlcke ACK (and thanks) > > -- > > diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c > index dd33ff0..4192d24 100644 > --- a/drivers/usb/gadget/serial.c > +++ b/drivers/usb/gadget/serial.c > @@ -33,6 +33,7 @@ > #include > #include > #include > +#include > > #include > #include > @@ -258,7 +259,7 @@ static const char *EP_IN_NAME; > static const char *EP_OUT_NAME; > static const char *EP_NOTIFY_NAME; > > -static struct semaphore gs_open_close_sem[GS_NUM_PORTS]; > +static struct mutex gs_open_close_lock[GS_NUM_PORTS]; > > static unsigned int read_q_size = GS_DEFAULT_READ_Q_SIZE; > static unsigned int write_q_size = GS_DEFAULT_WRITE_Q_SIZE; > @@ -595,7 +596,7 @@ static int __init gs_module_init(void) > tty_set_operations(gs_tty_driver, &gs_tty_ops); > > for (i=0; i < GS_NUM_PORTS; i++) > - sema_init(&gs_open_close_sem[i], 1); > + mutex_init(&gs_open_close_lock[i]); > > retval = tty_register_driver(gs_tty_driver); > if (retval) { > @@ -635,7 +636,7 @@ static int gs_open(struct tty_struct *tty, struct file *file) > struct gs_port *port; > struct gs_dev *dev; > struct gs_buf *buf; > - struct semaphore *sem; > + struct mutex *mtx; > int ret; > > port_num = tty->index; > @@ -656,10 +657,10 @@ static int gs_open(struct tty_struct *tty, struct file *file) > return -ENODEV; > } > > - sem = &gs_open_close_sem[port_num]; > - if (down_interruptible(sem)) { > + mtx = &gs_open_close_lock[port_num]; > + if (mutex_lock_interruptible(mtx)) { > printk(KERN_ERR > - "gs_open: (%d,%p,%p) interrupted waiting for semaphore\n", > + "gs_open: (%d,%p,%p) interrupted waiting for mutex\n", > port_num, tty, file); > return -ERESTARTSYS; > } > @@ -754,12 +755,12 @@ static int gs_open(struct tty_struct *tty, struct file *file) > > exit_unlock_port: > spin_unlock_irqrestore(&port->port_lock, flags); > - up(sem); > + mutex_unlock(mtx); > return ret; > > exit_unlock_dev: > spin_unlock_irqrestore(&dev->dev_lock, flags); > - up(sem); > + mutex_unlock(mtx); > return ret; > > } > @@ -781,7 +782,7 @@ exit_unlock_dev: > static void gs_close(struct tty_struct *tty, struct file *file) > { > struct gs_port *port = tty->driver_data; > - struct semaphore *sem; > + struct mutex *mtx; > > if (port == NULL) { > printk(KERN_ERR "gs_close: NULL port pointer\n"); > @@ -790,8 +791,8 @@ static void gs_close(struct tty_struct *tty, struct file *file) > > gs_debug("gs_close: (%d,%p,%p)\n", port->port_num, tty, file); > > - sem = &gs_open_close_sem[port->port_num]; > - down(sem); > + mtx = &gs_open_close_lock[port->port_num]; > + mutex_lock(mtx); > > spin_lock_irq(&port->port_lock); > > @@ -846,7 +847,7 @@ static void gs_close(struct tty_struct *tty, struct file *file) > > exit: > spin_unlock_irq(&port->port_lock); > - up(sem); > + mutex_unlock(mtx); > } > > /* > > -- > Matthias Kaehlcke > Linux Application Developer > Barcelona > > If liberty means anything at all, it means the > right to tell people what they do not want to hear > (George Orwell) > .''`. > using free software / Debian GNU/Linux | http://debian.org : :' : > `. `'` > gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4 `- >