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+
679739static 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
0 commit comments