macintosh: Remove BKL from ans-lcd
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 <tglx@linutronix.de> LKML-Reference: <20091010153349.966159859@linutronix.de> Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
This commit is contained in:
parent
9e8ab74dda
commit
95fdac7372
@ -3,7 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <linux/types.h>
|
#include <linux/types.h>
|
||||||
#include <linux/smp_lock.h>
|
|
||||||
#include <linux/errno.h>
|
#include <linux/errno.h>
|
||||||
#include <linux/kernel.h>
|
#include <linux/kernel.h>
|
||||||
#include <linux/miscdevice.h>
|
#include <linux/miscdevice.h>
|
||||||
@ -26,6 +25,7 @@
|
|||||||
static unsigned long anslcd_short_delay = 80;
|
static unsigned long anslcd_short_delay = 80;
|
||||||
static unsigned long anslcd_long_delay = 3280;
|
static unsigned long anslcd_long_delay = 3280;
|
||||||
static volatile unsigned char __iomem *anslcd_ptr;
|
static volatile unsigned char __iomem *anslcd_ptr;
|
||||||
|
static DEFINE_MUTEX(anslcd_mutex);
|
||||||
|
|
||||||
#undef DEBUG
|
#undef DEBUG
|
||||||
|
|
||||||
@ -65,26 +65,31 @@ anslcd_write( struct file * file, const char __user * buf,
|
|||||||
|
|
||||||
if (!access_ok(VERIFY_READ, buf, count))
|
if (!access_ok(VERIFY_READ, buf, count))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
|
|
||||||
|
mutex_lock(&anslcd_mutex);
|
||||||
for ( i = *ppos; count > 0; ++i, ++p, --count )
|
for ( i = *ppos; count > 0; ++i, ++p, --count )
|
||||||
{
|
{
|
||||||
char c;
|
char c;
|
||||||
__get_user(c, p);
|
__get_user(c, p);
|
||||||
anslcd_write_byte_data( c );
|
anslcd_write_byte_data( c );
|
||||||
}
|
}
|
||||||
|
mutex_unlock(&anslcd_mutex);
|
||||||
*ppos = i;
|
*ppos = i;
|
||||||
return p - buf;
|
return p - buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static long
|
||||||
anslcd_ioctl( struct inode * inode, struct file * file,
|
anslcd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
|
||||||
unsigned int cmd, unsigned long arg )
|
|
||||||
{
|
{
|
||||||
char ch, __user *temp;
|
char ch, __user *temp;
|
||||||
|
long ret = 0;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printk(KERN_DEBUG "LCD: ioctl(%d,%d)\n",cmd,arg);
|
printk(KERN_DEBUG "LCD: ioctl(%d,%d)\n",cmd,arg);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
mutex_lock(&anslcd_mutex);
|
||||||
|
|
||||||
switch ( cmd )
|
switch ( cmd )
|
||||||
{
|
{
|
||||||
case ANSLCD_CLEAR:
|
case ANSLCD_CLEAR:
|
||||||
@ -93,7 +98,7 @@ anslcd_ioctl( struct inode * inode, struct file * file,
|
|||||||
anslcd_write_byte_ctrl ( 0x06 );
|
anslcd_write_byte_ctrl ( 0x06 );
|
||||||
anslcd_write_byte_ctrl ( 0x01 );
|
anslcd_write_byte_ctrl ( 0x01 );
|
||||||
anslcd_write_byte_ctrl ( 0x02 );
|
anslcd_write_byte_ctrl ( 0x02 );
|
||||||
return 0;
|
break;
|
||||||
case ANSLCD_SENDCTRL:
|
case ANSLCD_SENDCTRL:
|
||||||
temp = (char __user *) arg;
|
temp = (char __user *) arg;
|
||||||
__get_user(ch, temp);
|
__get_user(ch, temp);
|
||||||
@ -101,33 +106,37 @@ anslcd_ioctl( struct inode * inode, struct file * file,
|
|||||||
anslcd_write_byte_ctrl ( ch );
|
anslcd_write_byte_ctrl ( ch );
|
||||||
__get_user(ch, temp);
|
__get_user(ch, temp);
|
||||||
}
|
}
|
||||||
return 0;
|
break;
|
||||||
case ANSLCD_SETSHORTDELAY:
|
case ANSLCD_SETSHORTDELAY:
|
||||||
if (!capable(CAP_SYS_ADMIN))
|
if (!capable(CAP_SYS_ADMIN))
|
||||||
return -EACCES;
|
ret =-EACCES;
|
||||||
anslcd_short_delay=arg;
|
else
|
||||||
return 0;
|
anslcd_short_delay=arg;
|
||||||
|
break;
|
||||||
case ANSLCD_SETLONGDELAY:
|
case ANSLCD_SETLONGDELAY:
|
||||||
if (!capable(CAP_SYS_ADMIN))
|
if (!capable(CAP_SYS_ADMIN))
|
||||||
return -EACCES;
|
ret = -EACCES;
|
||||||
anslcd_long_delay=arg;
|
else
|
||||||
return 0;
|
anslcd_long_delay=arg;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return -EINVAL;
|
ret = -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mutex_unlock(&anslcd_mutex);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
anslcd_open( struct inode * inode, struct file * file )
|
anslcd_open( struct inode * inode, struct file * file )
|
||||||
{
|
{
|
||||||
cycle_kernel_lock();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct file_operations anslcd_fops = {
|
const struct file_operations anslcd_fops = {
|
||||||
.write = anslcd_write,
|
.write = anslcd_write,
|
||||||
.ioctl = anslcd_ioctl,
|
.unlocked_ioctl = anslcd_ioctl,
|
||||||
.open = anslcd_open,
|
.open = anslcd_open,
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct miscdevice anslcd_dev = {
|
static struct miscdevice anslcd_dev = {
|
||||||
@ -168,6 +177,7 @@ anslcd_init(void)
|
|||||||
printk(KERN_DEBUG "LCD: init\n");
|
printk(KERN_DEBUG "LCD: init\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
mutex_lock(&anslcd_mutex);
|
||||||
anslcd_write_byte_ctrl ( 0x38 );
|
anslcd_write_byte_ctrl ( 0x38 );
|
||||||
anslcd_write_byte_ctrl ( 0x0c );
|
anslcd_write_byte_ctrl ( 0x0c );
|
||||||
anslcd_write_byte_ctrl ( 0x06 );
|
anslcd_write_byte_ctrl ( 0x06 );
|
||||||
@ -176,6 +186,7 @@ anslcd_init(void)
|
|||||||
for(a=0;a<80;a++) {
|
for(a=0;a<80;a++) {
|
||||||
anslcd_write_byte_data(anslcd_logo[a]);
|
anslcd_write_byte_data(anslcd_logo[a]);
|
||||||
}
|
}
|
||||||
|
mutex_unlock(&anslcd_mutex);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user