From patchwork Sat Oct 10 15:37:12 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 35669 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from bilbo.ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id 1FF7AB7DF8 for ; Sun, 11 Oct 2009 03:33:27 +1100 (EST) Received: by ozlabs.org (Postfix) id 2551BB7B78; Sun, 11 Oct 2009 03:33:20 +1100 (EST) Delivered-To: linuxppc-dev@ozlabs.org X-Greylist: delayed 3303 seconds by postgrey-1.32 at bilbo; Sun, 11 Oct 2009 03:33:19 EST Received: from www.tglx.de (www.tglx.de [62.245.132.106]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 72B81B7B6F for ; Sun, 11 Oct 2009 03:33:19 +1100 (EST) Received: from localhost.localdomain (www.tglx.de [127.0.0.1]) by www.tglx.de (8.13.8/8.13.8/TGLX-2007100201) with ESMTP id n9AFbCCl031667; Sat, 10 Oct 2009 17:37:12 +0200 Message-Id: <20091010153349.966159859@linutronix.de> User-Agent: quilt/0.47-1 Date: Sat, 10 Oct 2009 15:37:12 -0000 From: Thomas Gleixner To: LKML Subject: [patch 22/28] macintosh: Remove BKL from ans-lcd References: <20091010153314.827301943@linutronix.de> Content-Disposition: inline; filename=drivers-mac-ans-lcd-remove-bkl.patch X-Virus-Scanned: clamav-milter 0.95.1 at www.tglx.de X-Virus-Status: Clean X-Spam-Status: No, score=-1.7 required=5.0 tests=ALL_TRUSTED,AWL autolearn=failed version=3.2.4 X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on www.tglx.de Cc: Jonathan Corbet , Peter Zijlstra , Frederic Weisbecker , Vincent Sanders , Christoph Hellwig , linuxppc-dev@ozlabs.org, John Kacur , Andrew Morton , Ingo Molnar X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org The ans-lcd driver got the cycle_kernel_lock() in anslcd_open() from the BKL pushdown and it still uses the locked ioctl. The BKL serialization in this driver is more than obscure and definitely does not cover all possible corner cases. Protect the access to the hardware with a local mutex and get rid of BKL and locked ioctl. Signed-off-by: Thomas Gleixner Cc: Benjamin Herrenschmidt Cc: linuxppc-dev@ozlabs.org Acked-by: Benjamin Herrenschmidt --- drivers/macintosh/ans-lcd.c | 45 +++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) Index: linux-2.6-tip/drivers/macintosh/ans-lcd.c =================================================================== --- linux-2.6-tip.orig/drivers/macintosh/ans-lcd.c +++ linux-2.6-tip/drivers/macintosh/ans-lcd.c @@ -3,7 +3,6 @@ */ #include -#include #include #include #include @@ -26,6 +25,7 @@ static unsigned long anslcd_short_delay = 80; static unsigned long anslcd_long_delay = 3280; static volatile unsigned char __iomem *anslcd_ptr; +static DEFINE_MUTEX(anslcd_mutex); #undef DEBUG @@ -65,26 +65,31 @@ anslcd_write( struct file * file, const if (!access_ok(VERIFY_READ, buf, count)) return -EFAULT; + + mutex_lock(&anslcd_mutex); for ( i = *ppos; count > 0; ++i, ++p, --count ) { char c; __get_user(c, p); anslcd_write_byte_data( c ); } + mutex_unlock(&anslcd_mutex); *ppos = i; return p - buf; } -static int -anslcd_ioctl( struct inode * inode, struct file * file, - unsigned int cmd, unsigned long arg ) +static long +anslcd_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { char ch, __user *temp; + long ret = 0; #ifdef DEBUG printk(KERN_DEBUG "LCD: ioctl(%d,%d)\n",cmd,arg); #endif + mutex_lock(&anslcd_mutex); + switch ( cmd ) { case ANSLCD_CLEAR: @@ -93,7 +98,7 @@ anslcd_ioctl( struct inode * inode, stru anslcd_write_byte_ctrl ( 0x06 ); anslcd_write_byte_ctrl ( 0x01 ); anslcd_write_byte_ctrl ( 0x02 ); - return 0; + break; case ANSLCD_SENDCTRL: temp = (char __user *) arg; __get_user(ch, temp); @@ -101,33 +106,37 @@ anslcd_ioctl( struct inode * inode, stru anslcd_write_byte_ctrl ( ch ); __get_user(ch, temp); } - return 0; + break; case ANSLCD_SETSHORTDELAY: if (!capable(CAP_SYS_ADMIN)) - return -EACCES; - anslcd_short_delay=arg; - return 0; + ret =-EACCES; + else + anslcd_short_delay=arg; + break; case ANSLCD_SETLONGDELAY: if (!capable(CAP_SYS_ADMIN)) - return -EACCES; - anslcd_long_delay=arg; - return 0; + ret = -EACCES; + else + anslcd_long_delay=arg; + break; default: - return -EINVAL; + ret = -EINVAL; } + + mutex_unlock(&anslcd_mutex); + return ret; } static int anslcd_open( struct inode * inode, struct file * file ) { - cycle_kernel_lock(); return 0; } const struct file_operations anslcd_fops = { - .write = anslcd_write, - .ioctl = anslcd_ioctl, - .open = anslcd_open, + .write = anslcd_write, + .unlocked_ioctl = anslcd_ioctl, + .open = anslcd_open, }; static struct miscdevice anslcd_dev = { @@ -168,6 +177,7 @@ anslcd_init(void) printk(KERN_DEBUG "LCD: init\n"); #endif + mutex_lock(&anslcd_mutex); anslcd_write_byte_ctrl ( 0x38 ); anslcd_write_byte_ctrl ( 0x0c ); anslcd_write_byte_ctrl ( 0x06 ); @@ -176,6 +186,7 @@ anslcd_init(void) for(a=0;a<80;a++) { anslcd_write_byte_data(anslcd_logo[a]); } + mutex_unlock(&anslcd_mutex); return 0; }