2 * drivers/staging/android/ion/compat_ion.c
4 * Copyright (C) 2013 Google, Inc.
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
17 #include <linux/compat.h>
19 #include <linux/uaccess.h>
22 #include "compat_ion.h"
24 /* See drivers/staging/android/uapi/ion.h for the definition of these structs */
25 struct compat_ion_allocation_data {
28 compat_uint_t heap_id_mask;
33 struct compat_ion_custom_data {
38 static int compat_get_ion_allocation_data(
39 struct compat_ion_allocation_data __user *data32,
40 struct ion_allocation_data __user *data)
47 err = get_user(s, &data32->len);
48 err |= put_user(s, &data->len);
49 err |= get_user(s, &data32->align);
50 err |= put_user(s, &data->align);
51 err |= get_user(u, &data32->heap_id_mask);
52 err |= put_user(u, &data->heap_id_mask);
53 err |= get_user(u, &data32->flags);
54 err |= put_user(u, &data->flags);
55 err |= get_user(i, &data32->handle);
56 err |= put_user(i, &data->handle);
61 static int compat_put_ion_allocation_data(
62 struct compat_ion_allocation_data __user *data32,
63 struct ion_allocation_data __user *data)
70 err = get_user(s, &data->len);
71 err |= put_user(s, &data32->len);
72 err |= get_user(s, &data->align);
73 err |= put_user(s, &data32->align);
74 err |= get_user(u, &data->heap_id_mask);
75 err |= put_user(u, &data32->heap_id_mask);
76 err |= get_user(u, &data->flags);
77 err |= put_user(u, &data32->flags);
78 err |= get_user(i, &data->handle);
79 err |= put_user(i, &data32->handle);
84 static int compat_get_ion_custom_data(
85 struct compat_ion_custom_data __user *data32,
86 struct ion_custom_data __user *data)
92 err = get_user(cmd, &data32->cmd);
93 err |= put_user(cmd, &data->cmd);
94 err |= get_user(arg, &data32->arg);
95 err |= put_user(arg, &data->arg);
100 long compat_ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
104 if (!filp->f_op || !filp->f_op->unlocked_ioctl)
110 struct compat_ion_allocation_data __user *data32;
111 struct ion_allocation_data __user *data;
114 data32 = compat_ptr(arg);
115 data = compat_alloc_user_space(sizeof(*data));
119 err = compat_get_ion_allocation_data(data32, data);
123 ret = filp->f_op->unlocked_ioctl(filp, cmd,
124 (unsigned long)data);
125 err = compat_put_ion_allocation_data(data32, data);
126 return ret ? ret : err;
130 struct compat_ion_allocation_data __user *data32;
131 struct ion_allocation_data __user *data;
134 data32 = compat_ptr(arg);
135 data = compat_alloc_user_space(sizeof(*data));
139 err = compat_get_ion_allocation_data(data32, data);
143 return filp->f_op->unlocked_ioctl(filp, cmd,
144 (unsigned long)data);
146 case ION_IOC_CUSTOM: {
147 struct compat_ion_custom_data __user *data32;
148 struct ion_custom_data __user *data;
151 data32 = compat_ptr(arg);
152 data = compat_alloc_user_space(sizeof(*data));
156 err = compat_get_ion_custom_data(data32, data);
160 return filp->f_op->unlocked_ioctl(filp, cmd,
161 (unsigned long)data);
167 return filp->f_op->unlocked_ioctl(filp, cmd,
168 (unsigned long)compat_ptr(arg));