@@ -269,8 +269,13 @@ hpet_read(struct file *file, char __user *buf, size_t count, loff_t * ppos)
269
269
if (!devp -> hd_ireqfreq )
270
270
return - EIO ;
271
271
272
- if (count < sizeof (unsigned long ))
273
- return - EINVAL ;
272
+ if (in_compat_syscall ()) {
273
+ if (count < sizeof (compat_ulong_t ))
274
+ return - EINVAL ;
275
+ } else {
276
+ if (count < sizeof (unsigned long ))
277
+ return - EINVAL ;
278
+ }
274
279
275
280
add_wait_queue (& devp -> hd_waitqueue , & wait );
276
281
@@ -294,9 +299,16 @@ hpet_read(struct file *file, char __user *buf, size_t count, loff_t * ppos)
294
299
schedule ();
295
300
}
296
301
297
- retval = put_user (data , (unsigned long __user * )buf );
298
- if (!retval )
299
- retval = sizeof (unsigned long );
302
+ if (in_compat_syscall ()) {
303
+ retval = put_user (data , (compat_ulong_t __user * )buf );
304
+ if (!retval )
305
+ retval = sizeof (compat_ulong_t );
306
+ } else {
307
+ retval = put_user (data , (unsigned long __user * )buf );
308
+ if (!retval )
309
+ retval = sizeof (unsigned long );
310
+ }
311
+
300
312
out :
301
313
__set_current_state (TASK_RUNNING );
302
314
remove_wait_queue (& devp -> hd_waitqueue , & wait );
@@ -651,12 +663,24 @@ struct compat_hpet_info {
651
663
unsigned short hi_timer ;
652
664
};
653
665
666
+ /* 32-bit types would lead to different command codes which should be
667
+ * translated into 64-bit ones before passed to hpet_ioctl_common
668
+ */
669
+ #define COMPAT_HPET_INFO _IOR('h', 0x03, struct compat_hpet_info)
670
+ #define COMPAT_HPET_IRQFREQ _IOW('h', 0x6, compat_ulong_t)
671
+
654
672
static long
655
673
hpet_compat_ioctl (struct file * file , unsigned int cmd , unsigned long arg )
656
674
{
657
675
struct hpet_info info ;
658
676
int err ;
659
677
678
+ if (cmd == COMPAT_HPET_INFO )
679
+ cmd = HPET_INFO ;
680
+
681
+ if (cmd == COMPAT_HPET_IRQFREQ )
682
+ cmd = HPET_IRQFREQ ;
683
+
660
684
mutex_lock (& hpet_mutex );
661
685
err = hpet_ioctl_common (file -> private_data , cmd , arg , & info );
662
686
mutex_unlock (& hpet_mutex );
0 commit comments