Trying to merge a vintage driver from kernel 2.6 to the latest kernel 5.8.
And encountered the following error:
macro "access_ok" passed 3 arguments, but takes just 2
The access_ok
is a macro defined in asm/uaccess.h
Here's the code fragment:
#include <asm/uaccess.h>
if (_IOC_DIR(cmd) & _IOC_READ)
err = !access_ok(VERIFY_WRITE, (void __user *)arg, _IOC_SIZE(cmd));
else if (_IOC_DIR(cmd) & _IOC_WRITE)
err = !access_ok(VERIFY_READ, (void __user *)arg, _IOC_SIZE(cmd));
if (err) return -EFAULT;
I did some googling but they all told me to switch to a lower version kernel that supports an access_ok
that takes in 3 arguments, obviously this didn't solve my problem.
So I want to know which macro could I replace access_ok
with?
According to Torvalds' reply, The type
argument was removed from access_ok()
function(or macro), and the only thing you need to do to adapt the mentioned code fragment to the latest kernel(5.8 for now), is to simply remove the first argument(eg. VERIFY_WRITE
or VERIFY_READ
)
And here's the fragment after the amendment.
#include <asm/uaccess.h>
if (_IOC_DIR(cmd) & _IOC_READ)
err = !access_ok((void __user *)arg, _IOC_SIZE(cmd));
else if (_IOC_DIR(cmd) & _IOC_WRITE)
err = !access_ok((void __user *)arg, _IOC_SIZE(cmd));
if (err) return -EFAULT;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With