/*
* ioctl32.c: Conversion between 32bit and 64bit native ioctls.
* Separated from fs stuff by Arnd Bergmann <arnd@arndb.de>
*
* Copyright (C) 1997-2000 Jakub Jelinek (jakub@redhat.com)
* Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be)
* Copyright (C) 2001,2002 Andi Kleen, SuSE Labs
* Copyright (C) 2003 Pavel Machek (pavel@ucw.cz)
* Copyright (C) 2005 Philippe De Muyter (phdm@macqel.be)
* Copyright (C) 2008 Hans Verkuil <hverkuil@xs4all.nl>
*
* These routines maintain argument size conversion between 32bit and 64bit
* ioctls.
*/
#include <linux/compat.h>
#include <linux/module.h>
#include <linux/videodev2.h>
#include <linux/v4l2-subdev.h>
#include <media/v4l2-dev.h>
#include <media/v4l2-fh.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-ioctl.h>
/**
* assign_in_user() - Copy from one __user var to another one
*
* @to: __user var where data will be stored
* @from: __user var where data will be retrieved.
*
* As this code very often needs to allocate userspace memory, it is easier
* to have a macro that will do both get_user() and put_user() at once.
*
* This function complements the macros defined at asm-generic/uaccess.h.
* It uses the same argument order as copy_in_user()
*/
#define assign_in_user(to, from) \
({ \
typeof(*from) __assign_tmp; \
\
get_user(__assign_tmp, from) || put_user(__assign_tmp, to); \
})
/**
* get_user_cast() - Stores at a kernelspace local var the contents from a
* pointer with userspace data that is not tagged with __user.
*
* @__x: var where data will be stored
* @__ptr: var where data will be retrieved.
*
* Sometimes we need to declare a pointer without __user because it
* comes from a pointer struct field that will be retrieved from userspace
* by the 64-bit native ioctl handler. This function ensures that the
* @__ptr will be cast to __user before calling get_user() in order to
* avoid warnings with static code analyzers like smatch.
*/
#define get_user_cast(__x, __ptr) \
({ \
get_user(__x, (typeof(*__ptr) __user *)(__ptr)); \
})
/**
* put_user_force() - Stores the contents of a kernelspace local var
* into a userspace pointer, removing any __user cast.
*
* @__x: var where data will be stored
* @__ptr: var where data will be retrieved.
*
* Sometimes we need to remove the __user attribute from some data,
* by passing the __force macro. This function ensures that the
* @__ptr will be cast with __force before calling put_user(), in order to
* avoid warnings with static code analyzers like smatch.
*/
#define put_user_force(__x, __ptr) \
({ \
put_user((typeof(*__x) __force *)(__x), __ptr); \
})
/**
* assign_in_user_cast() - Copy from one __user var to another one
*
* @to: __user var where data will be stored
* @from: var where data will be retrieved that needs to be cast to __user.
*