Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1392318

[PATCH 10/13] staging/android: move sw_sync related code to sw_sync.c

From Gustavo Padovan <gustavo@padovan.org>
Newsgroups linux.kernel
Subject [PATCH 10/13] staging/android: move sw_sync related code to sw_sync.c
Date 2016-05-02 17:50 +0200
Message-ID <ruogG-66V-9@gated-at.bofh.it> (permalink)
References <runXl-5Ww-21@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

Split sync_debug and sw_sync in two different files.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/staging/android/Makefile     |   1 +
 drivers/staging/android/sw_sync.c    | 136 +++++++++++++++++++++++++++++++++++
 drivers/staging/android/sync.h       |   2 +
 drivers/staging/android/sync_debug.c | 115 -----------------------------
 4 files changed, 139 insertions(+), 115 deletions(-)
 create mode 100644 drivers/staging/android/sw_sync.c

diff --git a/drivers/staging/android/Makefile b/drivers/staging/android/Makefile
index bf45967..980d6dc 100644
--- a/drivers/staging/android/Makefile
+++ b/drivers/staging/android/Makefile
@@ -5,3 +5,4 @@ obj-y					+= ion/
 obj-$(CONFIG_ASHMEM)			+= ashmem.o
 obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER)	+= lowmemorykiller.o
 obj-$(CONFIG_SYNC)			+= sync.o sync_debug.o
+obj-$(CONFIG_SW_SYNC)			+= sw_sync.o
diff --git a/drivers/staging/android/sw_sync.c b/drivers/staging/android/sw_sync.c
new file mode 100644
index 0000000..90e3ee5
--- /dev/null
+++ b/drivers/staging/android/sw_sync.c
@@ -0,0 +1,136 @@
+/*
+ * drivers/dma-buf/sw_sync.c
+ *
+ * Copyright (C) 2012 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/file.h>
+#include <linux/fs.h>
+#include <linux/uaccess.h>
+#include <linux/sync_file.h>
+
+#include "uapi/sw_sync.h"
+#include "sync.h"
+
+/*
+ * *WARNING*
+ *
+ * improper use of this can result in deadlocking kernel drivers from userspace.
+ */
+
+/* opening sw_sync create a new sync obj */
+static int sw_sync_debugfs_open(struct inode *inode, struct file *file)
+{
+	struct sync_timeline *obj;
+	char task_comm[TASK_COMM_LEN];
+
+	get_task_comm(task_comm, current);
+
+	obj = sync_timeline_create("sw_sync", task_comm);
+	if (!obj)
+		return -ENOMEM;
+
+	file->private_data = obj;
+
+	return 0;
+}
+
+static int sw_sync_debugfs_release(struct inode *inode, struct file *file)
+{
+	struct sync_timeline *obj = file->private_data;
+
+	sync_timeline_destroy(obj);
+	return 0;
+}
+
+static long sw_sync_ioctl_create_fence(struct sync_timeline *obj,
+				       unsigned long arg)
+{
+	int fd = get_unused_fd_flags(O_CLOEXEC);
+	int err;
+	struct sync_pt *pt;
+	struct sync_file *sync_file;
+	struct sw_sync_create_fence_data data;
+
+	if (fd < 0)
+		return fd;
+
+	if (copy_from_user(&data, (void __user *)arg, sizeof(data))) {
+		err = -EFAULT;
+		goto err;
+	}
+
+	pt = sync_pt_create(obj, sizeof(*pt), data.value);
+	if (!pt) {
+		err = -ENOMEM;
+		goto err;
+	}
+
+	sync_file = sync_file_create(&pt->base);
+	if (!sync_file) {
+		fence_put(&pt->base);
+		err = -ENOMEM;
+		goto err;
+	}
+
+	data.fence = fd;
+	if (copy_to_user((void __user *)arg, &data, sizeof(data))) {
+		fput(sync_file->file);
+		err = -EFAULT;
+		goto err;
+	}
+
+	fd_install(fd, sync_file->file);
+
+	return 0;
+
+err:
+	put_unused_fd(fd);
+	return err;
+}
+
+static long sw_sync_ioctl_inc(struct sync_timeline *obj, unsigned long arg)
+{
+	u32 value;
+
+	if (copy_from_user(&value, (void __user *)arg, sizeof(value)))
+		return -EFAULT;
+
+	sync_timeline_signal(obj, value);
+
+	return 0;
+}
+
+static long sw_sync_ioctl(struct file *file, unsigned int cmd,
+			  unsigned long arg)
+{
+	struct sync_timeline *obj = file->private_data;
+
+	switch (cmd) {
+	case SW_SYNC_IOC_CREATE_FENCE:
+		return sw_sync_ioctl_create_fence(obj, arg);
+
+	case SW_SYNC_IOC_INC:
+		return sw_sync_ioctl_inc(obj, arg);
+
+	default:
+		return -ENOTTY;
+	}
+}
+
+const struct file_operations sw_sync_debugfs_fops = {
+	.open           = sw_sync_debugfs_open,
+	.release        = sw_sync_debugfs_release,
+	.unlocked_ioctl = sw_sync_ioctl,
+	.compat_ioctl	= sw_sync_ioctl,
+};
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index 14b61cb..02ecf44 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -132,6 +132,8 @@ struct sync_pt *sync_pt_create(struct sync_timeline *parent, int size,
 
 #ifdef CONFIG_DEBUG_FS
 
+extern const struct file_operations sw_sync_debugfs_fops;
+
 void sync_timeline_debug_add(struct sync_timeline *obj);
 void sync_timeline_debug_remove(struct sync_timeline *obj);
 void sync_file_debug_add(struct sync_file *fence);
diff --git a/drivers/staging/android/sync_debug.c b/drivers/staging/android/sync_debug.c
index 703f198..2733cc3 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -203,121 +203,6 @@ static const struct file_operations sync_info_debugfs_fops = {
 	.release        = single_release,
 };
 
-#if IS_ENABLED(CONFIG_SW_SYNC)
-/*
- * *WARNING*
- *
- * improper use of this can result in deadlocking kernel drivers from userspace.
- */
-
-/* opening sw_sync create a new sync obj */
-static int sw_sync_debugfs_open(struct inode *inode, struct file *file)
-{
-	struct sync_timeline *obj;
-	char task_comm[TASK_COMM_LEN];
-
-	get_task_comm(task_comm, current);
-
-	obj = sync_timeline_create("sw_sync", task_comm);
-	if (!obj)
-		return -ENOMEM;
-
-	file->private_data = obj;
-
-	return 0;
-}
-
-static int sw_sync_debugfs_release(struct inode *inode, struct file *file)
-{
-	struct sync_timeline *obj = file->private_data;
-
-	sync_timeline_destroy(obj);
-	return 0;
-}
-
-static long sw_sync_ioctl_create_fence(struct sync_timeline *obj,
-				       unsigned long arg)
-{
-	int fd = get_unused_fd_flags(O_CLOEXEC);
-	int err;
-	struct sync_pt *pt;
-	struct sync_file *sync_file;
-	struct sw_sync_create_fence_data data;
-
-	if (fd < 0)
-		return fd;
-
-	if (copy_from_user(&data, (void __user *)arg, sizeof(data))) {
-		err = -EFAULT;
-		goto err;
-	}
-
-	pt = sync_pt_create(obj, sizeof(*pt), data.value);
-	if (!pt) {
-		err = -ENOMEM;
-		goto err;
-	}
-
-	sync_file = sync_file_create(&pt->base);
-	if (!sync_file) {
-		fence_put(&pt->base);
-		err = -ENOMEM;
-		goto err;
-	}
-
-	data.fence = fd;
-	if (copy_to_user((void __user *)arg, &data, sizeof(data))) {
-		fput(sync_file->file);
-		err = -EFAULT;
-		goto err;
-	}
-
-	fd_install(fd, sync_file->file);
-
-	return 0;
-
-err:
-	put_unused_fd(fd);
-	return err;
-}
-
-static long sw_sync_ioctl_inc(struct sync_timeline *obj, unsigned long arg)
-{
-	u32 value;
-
-	if (copy_from_user(&value, (void __user *)arg, sizeof(value)))
-		return -EFAULT;
-
-	sync_timeline_signal(obj, value);
-
-	return 0;
-}
-
-static long sw_sync_ioctl(struct file *file, unsigned int cmd,
-			  unsigned long arg)
-{
-	struct sync_timeline *obj = file->private_data;
-
-	switch (cmd) {
-	case SW_SYNC_IOC_CREATE_FENCE:
-		return sw_sync_ioctl_create_fence(obj, arg);
-
-	case SW_SYNC_IOC_INC:
-		return sw_sync_ioctl_inc(obj, arg);
-
-	default:
-		return -ENOTTY;
-	}
-}
-
-static const struct file_operations sw_sync_debugfs_fops = {
-	.open           = sw_sync_debugfs_open,
-	.release        = sw_sync_debugfs_release,
-	.unlocked_ioctl = sw_sync_ioctl,
-	.compat_ioctl = sw_sync_ioctl,
-};
-#endif
-
 static __init int sync_debugfs_init(void)
 {
 	dbgfs = debugfs_create_dir("sync", NULL);
-- 
2.5.5

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 00/13] staging/android: clean up SW_SYNC Gustavo Padovan <gustavo@padovan.org> - 2016-05-02 17:30 +0200
  [PATCH 09/13] staging/android: bring struct sync_pt back Gustavo Padovan <gustavo@padovan.org> - 2016-05-02 17:30 +0200
  [PATCH 13/13] staging/android: make sw_ioctl info internal to sw_sync.c Gustavo Padovan <gustavo@padovan.org> - 2016-05-02 17:30 +0200
  [PATCH 07/13] staging/android: remove unnecessary check for fence Gustavo Padovan <gustavo@padovan.org> - 2016-05-02 17:30 +0200
  [PATCH 01/13] staging/android: store last signaled value on sync timeline Gustavo Padovan <gustavo@padovan.org> - 2016-05-02 17:40 +0200
  [PATCH 10/13] staging/android: move sw_sync related code to sw_sync.c Gustavo Padovan <gustavo@padovan.org> - 2016-05-02 17:50 +0200
  [PATCH 05/13] staging/android: remove sw_sync.[ch] files Gustavo Padovan <gustavo@padovan.org> - 2016-05-02 17:50 +0200
  [PATCH 12/13] staging/android: make sync_timeline internal to sw_sync Gustavo Padovan <gustavo@padovan.org> - 2016-05-02 17:50 +0200
  [PATCH 02/13] staging/android: remove .{fence,timeline}_value_str() from timeline_ops Gustavo Padovan <gustavo@padovan.org> - 2016-05-02 18:20 +0200
  [PATCH 06/13] staging/android: rename android_fence to timeline_fence Gustavo Padovan <gustavo@padovan.org> - 2016-05-02 18:30 +0200
  [PATCH 03/13] staging/android: remove struct sync_timeline_ops Gustavo Padovan <gustavo@padovan.org> - 2016-05-02 18:30 +0200
  [PATCH 04/13] staging/android: remove sw_sync_timeline and sw_sync_pt Gustavo Padovan <gustavo@padovan.org> - 2016-05-02 18:40 +0200

csiph-web