Commit b0c7cb26 authored by Laura Abbott's avatar Laura Abbott Committed by Greg Kroah-Hartman

staging: android: ion: Break the ABI in the name of forward progress

Several of the Ion ioctls were designed in such a way that they
necessitate compat ioctls. We're breaking a bunch of other ABIs and
cleaning stuff up anyway so let's follow the ioctl guidelines and clean
things up while everyone is busy converting things over anyway. As part
of this, also remove the useless alignment field from the allocation
structure.
Signed-off-by: default avatarLaura Abbott <labbott@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 62b3a094
...@@ -2,6 +2,3 @@ obj-$(CONFIG_ION) += ion.o ion-ioctl.o ion_heap.o \ ...@@ -2,6 +2,3 @@ obj-$(CONFIG_ION) += ion.o ion-ioctl.o ion_heap.o \
ion_page_pool.o ion_system_heap.o \ ion_page_pool.o ion_system_heap.o \
ion_carveout_heap.o ion_chunk_heap.o ion_carveout_heap.o ion_chunk_heap.o
obj-$(CONFIG_ION_CMA_HEAP) += ion_cma_heap.o obj-$(CONFIG_ION_CMA_HEAP) += ion_cma_heap.o
ifdef CONFIG_COMPAT
obj-$(CONFIG_ION) += compat_ion.o
endif
/*
* drivers/staging/android/ion/compat_ion.c
*
* Copyright (C) 2013 Google, Inc.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <linux/compat.h>
#include <linux/fs.h>
#include <linux/uaccess.h>
#include "ion.h"
#include "compat_ion.h"
/* See drivers/staging/android/uapi/ion.h for the definition of these structs */
struct compat_ion_allocation_data {
compat_size_t len;
compat_size_t align;
compat_uint_t heap_id_mask;
compat_uint_t flags;
compat_int_t handle;
};
struct compat_ion_handle_data {
compat_int_t handle;
};
#define COMPAT_ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \
struct compat_ion_allocation_data)
#define COMPAT_ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, \
struct compat_ion_handle_data)
static int compat_get_ion_allocation_data(
struct compat_ion_allocation_data __user *data32,
struct ion_allocation_data __user *data)
{
compat_size_t s;
compat_uint_t u;
compat_int_t i;
int err;
err = get_user(s, &data32->len);
err |= put_user(s, &data->len);
err |= get_user(s, &data32->align);
err |= put_user(s, &data->align);
err |= get_user(u, &data32->heap_id_mask);
err |= put_user(u, &data->heap_id_mask);
err |= get_user(u, &data32->flags);
err |= put_user(u, &data->flags);
err |= get_user(i, &data32->handle);
err |= put_user(i, &data->handle);
return err;
}
static int compat_get_ion_handle_data(
struct compat_ion_handle_data __user *data32,
struct ion_handle_data __user *data)
{
compat_int_t i;
int err;
err = get_user(i, &data32->handle);
err |= put_user(i, &data->handle);
return err;
}
static int compat_put_ion_allocation_data(
struct compat_ion_allocation_data __user *data32,
struct ion_allocation_data __user *data)
{
compat_size_t s;
compat_uint_t u;
compat_int_t i;
int err;
err = get_user(s, &data->len);
err |= put_user(s, &data32->len);
err |= get_user(s, &data->align);
err |= put_user(s, &data32->align);
err |= get_user(u, &data->heap_id_mask);
err |= put_user(u, &data32->heap_id_mask);
err |= get_user(u, &data->flags);
err |= put_user(u, &data32->flags);
err |= get_user(i, &data->handle);
err |= put_user(i, &data32->handle);
return err;
}
long compat_ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
long ret;
if (!filp->f_op->unlocked_ioctl)
return -ENOTTY;
switch (cmd) {
case COMPAT_ION_IOC_ALLOC:
{
struct compat_ion_allocation_data __user *data32;
struct ion_allocation_data __user *data;
int err;
data32 = compat_ptr(arg);
data = compat_alloc_user_space(sizeof(*data));
if (!data)
return -EFAULT;
err = compat_get_ion_allocation_data(data32, data);
if (err)
return err;
ret = filp->f_op->unlocked_ioctl(filp, ION_IOC_ALLOC,
(unsigned long)data);
err = compat_put_ion_allocation_data(data32, data);
return ret ? ret : err;
}
case COMPAT_ION_IOC_FREE:
{
struct compat_ion_handle_data __user *data32;
struct ion_handle_data __user *data;
int err;
data32 = compat_ptr(arg);
data = compat_alloc_user_space(sizeof(*data));
if (!data)
return -EFAULT;
err = compat_get_ion_handle_data(data32, data);
if (err)
return err;
return filp->f_op->unlocked_ioctl(filp, ION_IOC_FREE,
(unsigned long)data);
}
case ION_IOC_SHARE:
return filp->f_op->unlocked_ioctl(filp, cmd,
(unsigned long)compat_ptr(arg));
default:
return -ENOIOCTLCMD;
}
}
/*
* drivers/staging/android/ion/compat_ion.h
*
* Copyright (C) 2013 Google, Inc.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef _LINUX_COMPAT_ION_H
#define _LINUX_COMPAT_ION_H
#if IS_ENABLED(CONFIG_COMPAT)
long compat_ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
#else
#define compat_ion_ioctl NULL
#endif /* CONFIG_COMPAT */
#endif /* _LINUX_COMPAT_ION_H */
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include "ion.h" #include "ion.h"
#include "ion_priv.h" #include "ion_priv.h"
#include "compat_ion.h"
union ion_ioctl_arg { union ion_ioctl_arg {
struct ion_fd_data fd; struct ion_fd_data fd;
......
...@@ -40,7 +40,6 @@ ...@@ -40,7 +40,6 @@
#include "ion.h" #include "ion.h"
#include "ion_priv.h" #include "ion_priv.h"
#include "compat_ion.h"
bool ion_buffer_cached(struct ion_buffer *buffer) bool ion_buffer_cached(struct ion_buffer *buffer)
{ {
...@@ -1065,7 +1064,9 @@ static const struct file_operations ion_fops = { ...@@ -1065,7 +1064,9 @@ static const struct file_operations ion_fops = {
.open = ion_open, .open = ion_open,
.release = ion_release, .release = ion_release,
.unlocked_ioctl = ion_ioctl, .unlocked_ioctl = ion_ioctl,
.compat_ioctl = compat_ion_ioctl, #ifdef CONFIG_COMPAT
.compat_ioctl = ion_ioctl,
#endif
}; };
static size_t ion_debug_heap_total(struct ion_client *client, static size_t ion_debug_heap_total(struct ion_client *client,
......
...@@ -20,8 +20,6 @@ ...@@ -20,8 +20,6 @@
#include <linux/ioctl.h> #include <linux/ioctl.h>
#include <linux/types.h> #include <linux/types.h>
typedef int ion_user_handle_t;
/** /**
* enum ion_heap_types - list of all possible types of heaps * enum ion_heap_types - list of all possible types of heaps
* @ION_HEAP_TYPE_SYSTEM: memory allocated via vmalloc * @ION_HEAP_TYPE_SYSTEM: memory allocated via vmalloc
...@@ -76,7 +74,6 @@ enum ion_heap_type { ...@@ -76,7 +74,6 @@ enum ion_heap_type {
/** /**
* struct ion_allocation_data - metadata passed from userspace for allocations * struct ion_allocation_data - metadata passed from userspace for allocations
* @len: size of the allocation * @len: size of the allocation
* @align: required alignment of the allocation
* @heap_id_mask: mask of heap ids to allocate from * @heap_id_mask: mask of heap ids to allocate from
* @flags: flags passed to heap * @flags: flags passed to heap
* @handle: pointer that will be populated with a cookie to use to * @handle: pointer that will be populated with a cookie to use to
...@@ -85,11 +82,11 @@ enum ion_heap_type { ...@@ -85,11 +82,11 @@ enum ion_heap_type {
* Provided by userspace as an argument to the ioctl * Provided by userspace as an argument to the ioctl
*/ */
struct ion_allocation_data { struct ion_allocation_data {
size_t len; __u64 len;
size_t align; __u32 heap_id_mask;
unsigned int heap_id_mask; __u32 flags;
unsigned int flags; __u32 handle;
ion_user_handle_t handle; __u32 unused;
}; };
/** /**
...@@ -103,8 +100,8 @@ struct ion_allocation_data { ...@@ -103,8 +100,8 @@ struct ion_allocation_data {
* provides the file descriptor and the kernel returns the handle. * provides the file descriptor and the kernel returns the handle.
*/ */
struct ion_fd_data { struct ion_fd_data {
ion_user_handle_t handle; __u32 handle;
int fd; __u32 fd;
}; };
/** /**
...@@ -112,7 +109,7 @@ struct ion_fd_data { ...@@ -112,7 +109,7 @@ struct ion_fd_data {
* @handle: a handle * @handle: a handle
*/ */
struct ion_handle_data { struct ion_handle_data {
ion_user_handle_t handle; __u32 handle;
}; };
#define MAX_HEAP_NAME 32 #define MAX_HEAP_NAME 32
......
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