Skip to content

Commit 3695669

Browse files
committed
lp: move compat_ioctl handling into lp.c
Handling for LPSETTIMEOUT can easily be done in lp_ioctl, which is the only user. As a positive side-effect, push the BKL into the ioctl methods. Signed-off-by: Arnd Bergmann <arnd@arndb.de> Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent 43c6e7b commit 3695669

2 files changed

Lines changed: 89 additions & 59 deletions

File tree

‎drivers/char/lp.c‎

Lines changed: 89 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
#include <linux/wait.h>
128128
#include <linux/jiffies.h>
129129
#include <linux/smp_lock.h>
130+
#include <linux/compat.h>
130131

131132
#include <linux/parport.h>
132133
#undef LP_STATS
@@ -571,13 +572,11 @@ static int lp_release(struct inode * inode, struct file * file)
571572
return 0;
572573
}
573574

574-
static int lp_ioctl(struct inode *inode, struct file *file,
575-
unsigned int cmd, unsigned long arg)
575+
static int lp_do_ioctl(unsigned int minor, unsigned int cmd,
576+
unsigned long arg, void __user *argp)
576577
{
577-
unsigned int minor = iminor(inode);
578578
int status;
579579
int retval = 0;
580-
void __user *argp = (void __user *)arg;
581580

582581
#ifdef LP_DEBUG
583582
printk(KERN_DEBUG "lp%d ioctl, cmd: 0x%x, arg: 0x%lx\n", minor, cmd, arg);
@@ -587,9 +586,6 @@ static int lp_ioctl(struct inode *inode, struct file *file,
587586
if ((LP_F(minor) & LP_EXIST) == 0)
588587
return -ENODEV;
589588
switch ( cmd ) {
590-
struct timeval par_timeout;
591-
long to_jiffies;
592-
593589
case LPTIME:
594590
LP_TIME(minor) = arg * HZ/100;
595591
break;
@@ -652,34 +648,101 @@ static int lp_ioctl(struct inode *inode, struct file *file,
652648
return -EFAULT;
653649
break;
654650

655-
case LPSETTIMEOUT:
656-
if (copy_from_user (&par_timeout, argp,
657-
sizeof (struct timeval))) {
658-
return -EFAULT;
659-
}
660-
/* Convert to jiffies, place in lp_table */
661-
if ((par_timeout.tv_sec < 0) ||
662-
(par_timeout.tv_usec < 0)) {
663-
return -EINVAL;
664-
}
665-
to_jiffies = DIV_ROUND_UP(par_timeout.tv_usec, 1000000/HZ);
666-
to_jiffies += par_timeout.tv_sec * (long) HZ;
667-
if (to_jiffies <= 0) {
668-
return -EINVAL;
669-
}
670-
lp_table[minor].timeout = to_jiffies;
671-
break;
672-
673651
default:
674652
retval = -EINVAL;
675653
}
676654
return retval;
677655
}
678656

657+
static int lp_set_timeout(unsigned int minor, struct timeval *par_timeout)
658+
{
659+
long to_jiffies;
660+
661+
/* Convert to jiffies, place in lp_table */
662+
if ((par_timeout->tv_sec < 0) ||
663+
(par_timeout->tv_usec < 0)) {
664+
return -EINVAL;
665+
}
666+
to_jiffies = DIV_ROUND_UP(par_timeout->tv_usec, 1000000/HZ);
667+
to_jiffies += par_timeout->tv_sec * (long) HZ;
668+
if (to_jiffies <= 0) {
669+
return -EINVAL;
670+
}
671+
lp_table[minor].timeout = to_jiffies;
672+
return 0;
673+
}
674+
675+
static long lp_ioctl(struct file *file, unsigned int cmd,
676+
unsigned long arg)
677+
{
678+
unsigned int minor;
679+
struct timeval par_timeout;
680+
int ret;
681+
682+
minor = iminor(file->f_path.dentry->d_inode);
683+
lock_kernel();
684+
switch (cmd) {
685+
case LPSETTIMEOUT:
686+
if (copy_from_user(&par_timeout, (void __user *)arg,
687+
sizeof (struct timeval))) {
688+
ret = -EFAULT;
689+
break;
690+
}
691+
ret = lp_set_timeout(minor, &par_timeout);
692+
break;
693+
default:
694+
ret = lp_do_ioctl(minor, cmd, arg, (void __user *)arg);
695+
break;
696+
}
697+
unlock_kernel();
698+
699+
return ret;
700+
}
701+
702+
#ifdef CONFIG_COMPAT
703+
static long lp_compat_ioctl(struct file *file, unsigned int cmd,
704+
unsigned long arg)
705+
{
706+
unsigned int minor;
707+
struct timeval par_timeout;
708+
struct compat_timeval __user *tc;
709+
int ret;
710+
711+
minor = iminor(file->f_path.dentry->d_inode);
712+
lock_kernel();
713+
switch (cmd) {
714+
case LPSETTIMEOUT:
715+
tc = compat_ptr(arg);
716+
if (get_user(par_timeout.tv_sec, &tc->tv_sec) ||
717+
get_user(par_timeout.tv_usec, &tc->tv_usec)) {
718+
ret = -EFAULT;
719+
break;
720+
}
721+
ret = lp_set_timeout(minor, &par_timeout);
722+
break;
723+
#ifdef LP_STATS
724+
case LPGETSTATS:
725+
/* FIXME: add an implementation if you set LP_STATS */
726+
ret = -EINVAL;
727+
break;
728+
#endif
729+
default:
730+
ret = lp_do_ioctl(minor, cmd, arg, compat_ptr(arg));
731+
break;
732+
}
733+
unlock_kernel();
734+
735+
return ret;
736+
}
737+
#endif
738+
679739
static const struct file_operations lp_fops = {
680740
.owner = THIS_MODULE,
681741
.write = lp_write,
682-
.ioctl = lp_ioctl,
742+
.unlocked_ioctl = lp_ioctl,
743+
#ifdef CONFIG_COMPAT
744+
.compat_ioctl = lp_compat_ioctl,
745+
#endif
683746
.open = lp_open,
684747
.release = lp_release,
685748
#ifdef CONFIG_PARPORT_1284

‎fs/compat_ioctl.c‎

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -953,20 +953,6 @@ static int rtc_ioctl(unsigned fd, unsigned cmd, void __user *argp)
953953
return -ENOIOCTLCMD;
954954
}
955955

956-
static int
957-
lp_timeout_trans(unsigned int fd, unsigned int cmd,
958-
struct compat_timeval __user *tc)
959-
{
960-
struct timeval __user *tn = compat_alloc_user_space(sizeof(struct timeval));
961-
struct timeval ts;
962-
if (get_user(ts.tv_sec, &tc->tv_sec) ||
963-
get_user(ts.tv_usec, &tc->tv_usec) ||
964-
put_user(ts.tv_sec, &tn->tv_sec) ||
965-
put_user(ts.tv_usec, &tn->tv_usec))
966-
return -EFAULT;
967-
return sys_ioctl(fd, cmd, (unsigned long)tn);
968-
}
969-
970956
/* on ia32 l_start is on a 32-bit boundary */
971957
#if defined(CONFIG_IA64) || defined(CONFIG_X86_64)
972958
struct space_resv_32 {
@@ -1212,8 +1198,6 @@ COMPATIBLE_IOCTL(PPPIOCGCHAN)
12121198
/* PPPOX */
12131199
COMPATIBLE_IOCTL(PPPOEIOCSFWD)
12141200
COMPATIBLE_IOCTL(PPPOEIOCDFWD)
1215-
/* LP */
1216-
COMPATIBLE_IOCTL(LPGETSTATUS)
12171201
/* ppdev */
12181202
COMPATIBLE_IOCTL(PPSETMODE)
12191203
COMPATIBLE_IOCTL(PPRSTATUS)
@@ -1623,19 +1607,6 @@ COMPATIBLE_IOCTL(TIOCSTOP)
16231607
/* Usbdevfs */
16241608
COMPATIBLE_IOCTL(USBDEVFS_IOCTL32)
16251609

1626-
/* parport */
1627-
COMPATIBLE_IOCTL(LPTIME)
1628-
COMPATIBLE_IOCTL(LPCHAR)
1629-
COMPATIBLE_IOCTL(LPABORTOPEN)
1630-
COMPATIBLE_IOCTL(LPCAREFUL)
1631-
COMPATIBLE_IOCTL(LPWAIT)
1632-
COMPATIBLE_IOCTL(LPSETIRQ)
1633-
COMPATIBLE_IOCTL(LPGETSTATUS)
1634-
COMPATIBLE_IOCTL(LPGETSTATUS)
1635-
COMPATIBLE_IOCTL(LPRESET)
1636-
/*LPGETSTATS not implemented, but no kernels seem to compile it in anyways*/
1637-
COMPATIBLE_IOCTL(LPGETFLAGS)
1638-
16391610
/* fat 'r' ioctls. These are handled by fat with ->compat_ioctl,
16401611
but we don't want warnings on other file systems. So declare
16411612
them as compatible here. */
@@ -1734,10 +1705,6 @@ static long do_ioctl_trans(int fd, unsigned int cmd,
17341705
return do_video_stillpicture(fd, cmd, argp);
17351706
case VIDEO_SET_SPU_PALETTE:
17361707
return do_video_set_spu_palette(fd, cmd, argp);
1737-
1738-
/* lp */
1739-
case LPSETTIMEOUT:
1740-
return lp_timeout_trans(fd, cmd, argp);
17411708
}
17421709

17431710
/*

0 commit comments

Comments
 (0)