Commit 82c65897 authored by Federico Vaga's avatar Federico Vaga

sw:drv: make it build above Linux 5.0

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 10258176
......@@ -26,6 +26,8 @@
#include <linux/tty.h>
#include <linux/platform_device.h>
#include <linux/mod_devicetable.h>
#include <linux/uaccess.h>
#include <linux/version.h>
#include <mockturtle/hw/mockturtle_cpu_csr.h>
#include <mockturtle/hw/mockturtle_queue.h>
......@@ -254,11 +256,14 @@ static long trtl_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
if (_IOC_TYPE(cmd) != TRTL_IOCTL_MAGIC)
return -ENOTTY;
/* Validate user pointer */
#if KERNEL_VERSION(5, 0, 0) <= LINUX_VERSION_CODE
err = !access_ok(uarg, _IOC_SIZE(cmd));
#else
if (_IOC_DIR(cmd) & _IOC_READ)
err = !access_ok(VERIFY_WRITE, uarg, _IOC_SIZE(cmd));
if (_IOC_DIR(cmd) & _IOC_WRITE)
err = !access_ok(VERIFY_READ, uarg, _IOC_SIZE(cmd));
#endif
if (err)
return -EFAULT;
......
......@@ -16,6 +16,8 @@
#include <linux/sched.h>
#include <linux/delay.h>
#include <linux/circ_buf.h>
#include <linux/uaccess.h>
#include <linux/version.h>
#include <mockturtle/hw/mockturtle_queue.h>
#include <mockturtle/hw/mockturtle_cpu_csr.h>
......@@ -723,11 +725,14 @@ static long trtl_hmq_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
if (_IOC_TYPE(cmd) != TRTL_IOCTL_MAGIC)
return -ENOTTY;
/* Validate user pointer */
#if KERNEL_VERSION(5, 0, 0) <= LINUX_VERSION_CODE
err = !access_ok(uarg, _IOC_SIZE(cmd));
#else
if (_IOC_DIR(cmd) & _IOC_READ)
err = !access_ok(VERIFY_WRITE, uarg, _IOC_SIZE(cmd));
if (_IOC_DIR(cmd) & _IOC_WRITE)
err = !access_ok(VERIFY_READ, uarg, _IOC_SIZE(cmd));
#endif
if (err)
return -EFAULT;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment