Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

compat_ioctl: move drivers to compat_ptr_ioctl

Each of these drivers has a copy of the same trivial helper function to
convert the pointer argument and then call the native ioctl handler.

We now have a generic implementation of that, so use it.

Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: David S. Miller <davem@davemloft.net>
Acked-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Reviewed-by: Jason Gunthorpe <jgg@mellanox.com>
Reviewed-by: Jiri Kosina <jkosina@suse.cz>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>

+20 -237
+1 -11
drivers/char/ppdev.c
··· 670 670 return ret; 671 671 } 672 672 673 - #ifdef CONFIG_COMPAT 674 - static long pp_compat_ioctl(struct file *file, unsigned int cmd, 675 - unsigned long arg) 676 - { 677 - return pp_ioctl(file, cmd, (unsigned long)compat_ptr(arg)); 678 - } 679 - #endif 680 - 681 673 static int pp_open(struct inode *inode, struct file *file) 682 674 { 683 675 unsigned int minor = iminor(inode); ··· 778 786 .write = pp_write, 779 787 .poll = pp_poll, 780 788 .unlocked_ioctl = pp_ioctl, 781 - #ifdef CONFIG_COMPAT 782 - .compat_ioctl = pp_compat_ioctl, 783 - #endif 789 + .compat_ioctl = compat_ptr_ioctl, 784 790 .open = pp_open, 785 791 .release = pp_release, 786 792 };
+1 -11
drivers/char/tpm/tpm_vtpm_proxy.c
··· 670 670 } 671 671 } 672 672 673 - #ifdef CONFIG_COMPAT 674 - static long vtpmx_fops_compat_ioctl(struct file *f, unsigned int ioctl, 675 - unsigned long arg) 676 - { 677 - return vtpmx_fops_ioctl(f, ioctl, (unsigned long)compat_ptr(arg)); 678 - } 679 - #endif 680 - 681 673 static const struct file_operations vtpmx_fops = { 682 674 .owner = THIS_MODULE, 683 675 .unlocked_ioctl = vtpmx_fops_ioctl, 684 - #ifdef CONFIG_COMPAT 685 - .compat_ioctl = vtpmx_fops_compat_ioctl, 686 - #endif 676 + .compat_ioctl = compat_ptr_ioctl, 687 677 .llseek = noop_llseek, 688 678 }; 689 679
+1 -11
drivers/firewire/core-cdev.c
··· 1646 1646 return dispatch_ioctl(file->private_data, cmd, (void __user *)arg); 1647 1647 } 1648 1648 1649 - #ifdef CONFIG_COMPAT 1650 - static long fw_device_op_compat_ioctl(struct file *file, 1651 - unsigned int cmd, unsigned long arg) 1652 - { 1653 - return dispatch_ioctl(file->private_data, cmd, compat_ptr(arg)); 1654 - } 1655 - #endif 1656 - 1657 1649 static int fw_device_op_mmap(struct file *file, struct vm_area_struct *vma) 1658 1650 { 1659 1651 struct client *client = file->private_data; ··· 1787 1795 .mmap = fw_device_op_mmap, 1788 1796 .release = fw_device_op_release, 1789 1797 .poll = fw_device_op_poll, 1790 - #ifdef CONFIG_COMPAT 1791 - .compat_ioctl = fw_device_op_compat_ioctl, 1792 - #endif 1798 + .compat_ioctl = compat_ptr_ioctl, 1793 1799 };
+1 -10
drivers/hid/usbhid/hiddev.c
··· 854 854 return r; 855 855 } 856 856 857 - #ifdef CONFIG_COMPAT 858 - static long hiddev_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 859 - { 860 - return hiddev_ioctl(file, cmd, (unsigned long)compat_ptr(arg)); 861 - } 862 - #endif 863 - 864 857 static const struct file_operations hiddev_fops = { 865 858 .owner = THIS_MODULE, 866 859 .read = hiddev_read, ··· 863 870 .release = hiddev_release, 864 871 .unlocked_ioctl = hiddev_ioctl, 865 872 .fasync = hiddev_fasync, 866 - #ifdef CONFIG_COMPAT 867 - .compat_ioctl = hiddev_compat_ioctl, 868 - #endif 873 + .compat_ioctl = compat_ptr_ioctl, 869 874 .llseek = noop_llseek, 870 875 }; 871 876
+1 -11
drivers/hwtracing/stm/core.c
··· 832 832 return err; 833 833 } 834 834 835 - #ifdef CONFIG_COMPAT 836 - static long 837 - stm_char_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 838 - { 839 - return stm_char_ioctl(file, cmd, (unsigned long)compat_ptr(arg)); 840 - } 841 - #else 842 - #define stm_char_compat_ioctl NULL 843 - #endif 844 - 845 835 static const struct file_operations stm_fops = { 846 836 .open = stm_char_open, 847 837 .release = stm_char_release, 848 838 .write = stm_char_write, 849 839 .mmap = stm_char_mmap, 850 840 .unlocked_ioctl = stm_char_ioctl, 851 - .compat_ioctl = stm_char_compat_ioctl, 841 + .compat_ioctl = compat_ptr_ioctl, 852 842 .llseek = no_llseek, 853 843 }; 854 844
+1 -21
drivers/misc/mei/main.c
··· 533 533 } 534 534 535 535 /** 536 - * mei_compat_ioctl - the compat IOCTL function 537 - * 538 - * @file: pointer to file structure 539 - * @cmd: ioctl command 540 - * @data: pointer to mei message structure 541 - * 542 - * Return: 0 on success , <0 on error 543 - */ 544 - #ifdef CONFIG_COMPAT 545 - static long mei_compat_ioctl(struct file *file, 546 - unsigned int cmd, unsigned long data) 547 - { 548 - return mei_ioctl(file, cmd, (unsigned long)compat_ptr(data)); 549 - } 550 - #endif 551 - 552 - 553 - /** 554 536 * mei_poll - the poll function 555 537 * 556 538 * @file: pointer to file structure ··· 880 898 .owner = THIS_MODULE, 881 899 .read = mei_read, 882 900 .unlocked_ioctl = mei_ioctl, 883 - #ifdef CONFIG_COMPAT 884 - .compat_ioctl = mei_compat_ioctl, 885 - #endif 901 + .compat_ioctl = compat_ptr_ioctl, 886 902 .open = mei_open, 887 903 .release = mei_release, 888 904 .write = mei_write,
+3 -33
drivers/mtd/ubi/cdev.c
··· 1078 1078 return err; 1079 1079 } 1080 1080 1081 - #ifdef CONFIG_COMPAT 1082 - static long vol_cdev_compat_ioctl(struct file *file, unsigned int cmd, 1083 - unsigned long arg) 1084 - { 1085 - unsigned long translated_arg = (unsigned long)compat_ptr(arg); 1086 - 1087 - return vol_cdev_ioctl(file, cmd, translated_arg); 1088 - } 1089 - 1090 - static long ubi_cdev_compat_ioctl(struct file *file, unsigned int cmd, 1091 - unsigned long arg) 1092 - { 1093 - unsigned long translated_arg = (unsigned long)compat_ptr(arg); 1094 - 1095 - return ubi_cdev_ioctl(file, cmd, translated_arg); 1096 - } 1097 - 1098 - static long ctrl_cdev_compat_ioctl(struct file *file, unsigned int cmd, 1099 - unsigned long arg) 1100 - { 1101 - unsigned long translated_arg = (unsigned long)compat_ptr(arg); 1102 - 1103 - return ctrl_cdev_ioctl(file, cmd, translated_arg); 1104 - } 1105 - #else 1106 - #define vol_cdev_compat_ioctl NULL 1107 - #define ubi_cdev_compat_ioctl NULL 1108 - #define ctrl_cdev_compat_ioctl NULL 1109 - #endif 1110 - 1111 1081 /* UBI volume character device operations */ 1112 1082 const struct file_operations ubi_vol_cdev_operations = { 1113 1083 .owner = THIS_MODULE, ··· 1088 1118 .write = vol_cdev_write, 1089 1119 .fsync = vol_cdev_fsync, 1090 1120 .unlocked_ioctl = vol_cdev_ioctl, 1091 - .compat_ioctl = vol_cdev_compat_ioctl, 1121 + .compat_ioctl = compat_ptr_ioctl, 1092 1122 }; 1093 1123 1094 1124 /* UBI character device operations */ ··· 1096 1126 .owner = THIS_MODULE, 1097 1127 .llseek = no_llseek, 1098 1128 .unlocked_ioctl = ubi_cdev_ioctl, 1099 - .compat_ioctl = ubi_cdev_compat_ioctl, 1129 + .compat_ioctl = compat_ptr_ioctl, 1100 1130 }; 1101 1131 1102 1132 /* UBI control character device operations */ 1103 1133 const struct file_operations ubi_ctrl_cdev_operations = { 1104 1134 .owner = THIS_MODULE, 1105 1135 .unlocked_ioctl = ctrl_cdev_ioctl, 1106 - .compat_ioctl = ctrl_cdev_compat_ioctl, 1136 + .compat_ioctl = compat_ptr_ioctl, 1107 1137 .llseek = no_llseek, 1108 1138 };
+1 -11
drivers/net/tap.c
··· 1123 1123 } 1124 1124 } 1125 1125 1126 - #ifdef CONFIG_COMPAT 1127 - static long tap_compat_ioctl(struct file *file, unsigned int cmd, 1128 - unsigned long arg) 1129 - { 1130 - return tap_ioctl(file, cmd, (unsigned long)compat_ptr(arg)); 1131 - } 1132 - #endif 1133 - 1134 1126 static const struct file_operations tap_fops = { 1135 1127 .owner = THIS_MODULE, 1136 1128 .open = tap_open, ··· 1132 1140 .poll = tap_poll, 1133 1141 .llseek = no_llseek, 1134 1142 .unlocked_ioctl = tap_ioctl, 1135 - #ifdef CONFIG_COMPAT 1136 - .compat_ioctl = tap_compat_ioctl, 1137 - #endif 1143 + .compat_ioctl = compat_ptr_ioctl, 1138 1144 }; 1139 1145 1140 1146 static int tap_get_user_xdp(struct tap_queue *q, struct xdp_buff *xdp)
+1 -11
drivers/staging/pi433/pi433_if.c
··· 928 928 return 0; 929 929 } 930 930 931 - #ifdef CONFIG_COMPAT 932 - static long 933 - pi433_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) 934 - { 935 - return pi433_ioctl(filp, cmd, (unsigned long)compat_ptr(arg)); 936 - } 937 - #else 938 - #define pi433_compat_ioctl NULL 939 - #endif /* CONFIG_COMPAT */ 940 - 941 931 /*-------------------------------------------------------------------------*/ 942 932 943 933 static int pi433_open(struct inode *inode, struct file *filp) ··· 1084 1094 .write = pi433_write, 1085 1095 .read = pi433_read, 1086 1096 .unlocked_ioctl = pi433_ioctl, 1087 - .compat_ioctl = pi433_compat_ioctl, 1097 + .compat_ioctl = compat_ptr_ioctl, 1088 1098 .open = pi433_open, 1089 1099 .release = pi433_release, 1090 1100 .llseek = no_llseek,
+1 -15
drivers/usb/core/devio.c
··· 2685 2685 return ret; 2686 2686 } 2687 2687 2688 - #ifdef CONFIG_COMPAT 2689 - static long usbdev_compat_ioctl(struct file *file, unsigned int cmd, 2690 - unsigned long arg) 2691 - { 2692 - int ret; 2693 - 2694 - ret = usbdev_do_ioctl(file, cmd, compat_ptr(arg)); 2695 - 2696 - return ret; 2697 - } 2698 - #endif 2699 - 2700 2688 /* No kernel lock - fine */ 2701 2689 static __poll_t usbdev_poll(struct file *file, 2702 2690 struct poll_table_struct *wait) ··· 2708 2720 .read = usbdev_read, 2709 2721 .poll = usbdev_poll, 2710 2722 .unlocked_ioctl = usbdev_ioctl, 2711 - #ifdef CONFIG_COMPAT 2712 - .compat_ioctl = usbdev_compat_ioctl, 2713 - #endif 2723 + .compat_ioctl = compat_ptr_ioctl, 2714 2724 .mmap = usbdev_mmap, 2715 2725 .open = usbdev_open, 2716 2726 .release = usbdev_release,
+3 -36
drivers/vfio/vfio.c
··· 1184 1184 return ret; 1185 1185 } 1186 1186 1187 - #ifdef CONFIG_COMPAT 1188 - static long vfio_fops_compat_ioctl(struct file *filep, 1189 - unsigned int cmd, unsigned long arg) 1190 - { 1191 - arg = (unsigned long)compat_ptr(arg); 1192 - return vfio_fops_unl_ioctl(filep, cmd, arg); 1193 - } 1194 - #endif /* CONFIG_COMPAT */ 1195 - 1196 1187 static int vfio_fops_open(struct inode *inode, struct file *filep) 1197 1188 { 1198 1189 struct vfio_container *container; ··· 1266 1275 .read = vfio_fops_read, 1267 1276 .write = vfio_fops_write, 1268 1277 .unlocked_ioctl = vfio_fops_unl_ioctl, 1269 - #ifdef CONFIG_COMPAT 1270 - .compat_ioctl = vfio_fops_compat_ioctl, 1271 - #endif 1278 + .compat_ioctl = compat_ptr_ioctl, 1272 1279 .mmap = vfio_fops_mmap, 1273 1280 }; 1274 1281 ··· 1545 1556 return ret; 1546 1557 } 1547 1558 1548 - #ifdef CONFIG_COMPAT 1549 - static long vfio_group_fops_compat_ioctl(struct file *filep, 1550 - unsigned int cmd, unsigned long arg) 1551 - { 1552 - arg = (unsigned long)compat_ptr(arg); 1553 - return vfio_group_fops_unl_ioctl(filep, cmd, arg); 1554 - } 1555 - #endif /* CONFIG_COMPAT */ 1556 - 1557 1559 static int vfio_group_fops_open(struct inode *inode, struct file *filep) 1558 1560 { 1559 1561 struct vfio_group *group; ··· 1600 1620 static const struct file_operations vfio_group_fops = { 1601 1621 .owner = THIS_MODULE, 1602 1622 .unlocked_ioctl = vfio_group_fops_unl_ioctl, 1603 - #ifdef CONFIG_COMPAT 1604 - .compat_ioctl = vfio_group_fops_compat_ioctl, 1605 - #endif 1623 + .compat_ioctl = compat_ptr_ioctl, 1606 1624 .open = vfio_group_fops_open, 1607 1625 .release = vfio_group_fops_release, 1608 1626 }; ··· 1665 1687 return device->ops->mmap(device->device_data, vma); 1666 1688 } 1667 1689 1668 - #ifdef CONFIG_COMPAT 1669 - static long vfio_device_fops_compat_ioctl(struct file *filep, 1670 - unsigned int cmd, unsigned long arg) 1671 - { 1672 - arg = (unsigned long)compat_ptr(arg); 1673 - return vfio_device_fops_unl_ioctl(filep, cmd, arg); 1674 - } 1675 - #endif /* CONFIG_COMPAT */ 1676 - 1677 1690 static const struct file_operations vfio_device_fops = { 1678 1691 .owner = THIS_MODULE, 1679 1692 .release = vfio_device_fops_release, 1680 1693 .read = vfio_device_fops_read, 1681 1694 .write = vfio_device_fops_write, 1682 1695 .unlocked_ioctl = vfio_device_fops_unl_ioctl, 1683 - #ifdef CONFIG_COMPAT 1684 - .compat_ioctl = vfio_device_fops_compat_ioctl, 1685 - #endif 1696 + .compat_ioctl = compat_ptr_ioctl, 1686 1697 .mmap = vfio_device_fops_mmap, 1687 1698 }; 1688 1699
+1 -11
drivers/vhost/net.c
··· 1751 1751 } 1752 1752 } 1753 1753 1754 - #ifdef CONFIG_COMPAT 1755 - static long vhost_net_compat_ioctl(struct file *f, unsigned int ioctl, 1756 - unsigned long arg) 1757 - { 1758 - return vhost_net_ioctl(f, ioctl, (unsigned long)compat_ptr(arg)); 1759 - } 1760 - #endif 1761 - 1762 1754 static ssize_t vhost_net_chr_read_iter(struct kiocb *iocb, struct iov_iter *to) 1763 1755 { 1764 1756 struct file *file = iocb->ki_filp; ··· 1786 1794 .write_iter = vhost_net_chr_write_iter, 1787 1795 .poll = vhost_net_chr_poll, 1788 1796 .unlocked_ioctl = vhost_net_ioctl, 1789 - #ifdef CONFIG_COMPAT 1790 - .compat_ioctl = vhost_net_compat_ioctl, 1791 - #endif 1797 + .compat_ioctl = compat_ptr_ioctl, 1792 1798 .open = vhost_net_open, 1793 1799 .llseek = noop_llseek, 1794 1800 };
+1 -11
drivers/vhost/scsi.c
··· 1727 1727 } 1728 1728 } 1729 1729 1730 - #ifdef CONFIG_COMPAT 1731 - static long vhost_scsi_compat_ioctl(struct file *f, unsigned int ioctl, 1732 - unsigned long arg) 1733 - { 1734 - return vhost_scsi_ioctl(f, ioctl, (unsigned long)compat_ptr(arg)); 1735 - } 1736 - #endif 1737 - 1738 1730 static const struct file_operations vhost_scsi_fops = { 1739 1731 .owner = THIS_MODULE, 1740 1732 .release = vhost_scsi_release, 1741 1733 .unlocked_ioctl = vhost_scsi_ioctl, 1742 - #ifdef CONFIG_COMPAT 1743 - .compat_ioctl = vhost_scsi_compat_ioctl, 1744 - #endif 1734 + .compat_ioctl = compat_ptr_ioctl, 1745 1735 .open = vhost_scsi_open, 1746 1736 .llseek = noop_llseek, 1747 1737 };
+1 -11
drivers/vhost/test.c
··· 302 302 } 303 303 } 304 304 305 - #ifdef CONFIG_COMPAT 306 - static long vhost_test_compat_ioctl(struct file *f, unsigned int ioctl, 307 - unsigned long arg) 308 - { 309 - return vhost_test_ioctl(f, ioctl, (unsigned long)compat_ptr(arg)); 310 - } 311 - #endif 312 - 313 305 static const struct file_operations vhost_test_fops = { 314 306 .owner = THIS_MODULE, 315 307 .release = vhost_test_release, 316 308 .unlocked_ioctl = vhost_test_ioctl, 317 - #ifdef CONFIG_COMPAT 318 - .compat_ioctl = vhost_test_compat_ioctl, 319 - #endif 309 + .compat_ioctl = compat_ptr_ioctl, 320 310 .open = vhost_test_open, 321 311 .llseek = noop_llseek, 322 312 };
+1 -11
drivers/vhost/vsock.c
··· 761 761 } 762 762 } 763 763 764 - #ifdef CONFIG_COMPAT 765 - static long vhost_vsock_dev_compat_ioctl(struct file *f, unsigned int ioctl, 766 - unsigned long arg) 767 - { 768 - return vhost_vsock_dev_ioctl(f, ioctl, (unsigned long)compat_ptr(arg)); 769 - } 770 - #endif 771 - 772 764 static const struct file_operations vhost_vsock_fops = { 773 765 .owner = THIS_MODULE, 774 766 .open = vhost_vsock_dev_open, 775 767 .release = vhost_vsock_dev_release, 776 768 .llseek = noop_llseek, 777 769 .unlocked_ioctl = vhost_vsock_dev_ioctl, 778 - #ifdef CONFIG_COMPAT 779 - .compat_ioctl = vhost_vsock_dev_compat_ioctl, 780 - #endif 770 + .compat_ioctl = compat_ptr_ioctl, 781 771 }; 782 772 783 773 static struct miscdevice vhost_vsock_misc = {
+1 -12
fs/fat/file.c
··· 172 172 } 173 173 } 174 174 175 - #ifdef CONFIG_COMPAT 176 - static long fat_generic_compat_ioctl(struct file *filp, unsigned int cmd, 177 - unsigned long arg) 178 - 179 - { 180 - return fat_generic_ioctl(filp, cmd, (unsigned long)compat_ptr(arg)); 181 - } 182 - #endif 183 - 184 175 static int fat_file_release(struct inode *inode, struct file *filp) 185 176 { 186 177 if ((filp->f_mode & FMODE_WRITE) && ··· 206 215 .mmap = generic_file_mmap, 207 216 .release = fat_file_release, 208 217 .unlocked_ioctl = fat_generic_ioctl, 209 - #ifdef CONFIG_COMPAT 210 - .compat_ioctl = fat_generic_compat_ioctl, 211 - #endif 218 + .compat_ioctl = compat_ptr_ioctl, 212 219 .fsync = fat_file_fsync, 213 220 .splice_read = generic_file_splice_read, 214 221 .splice_write = iter_file_splice_write,