Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace the recently abolished first parameter of macro "access_ok"?

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?

like image 320
Justin Lee Avatar asked Jan 25 '23 13:01

Justin Lee


1 Answers

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;

like image 154
Justin Lee Avatar answered Feb 09 '23 01:02

Justin Lee