1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
--- a/compat/drivers-base-dma-buf.c
+++ b/compat/drivers-base-dma-buf.c
@@ -28,6 +28,10 @@
#include <linux/dma-buf.h>
#include <linux/anon_inodes.h>
#include <linux/export.h>
+#include <linux/file.h>
+#include <linux/fdtable.h>
+#include <linux/bitops.h>
+#include <linux/sched.h>
#include <linux/debugfs.h>
#include <linux/seq_file.h>
@@ -180,6 +184,27 @@ struct dma_buf *dma_buf_export_named(voi
}
EXPORT_SYMBOL_GPL(dma_buf_export_named);
+static void dma_buf_fd_set_flag(int fd, int flags)
+{
+ struct fdtable *fdt;
+ struct files_struct *files = current->files;
+
+ spin_lock(&files->file_lock);
+ fdt = files_fdtable(files);
+ if (flags & O_CLOEXEC)
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
+ __set_bit(fd, fdt->close_on_exec);
+#else
+ FD_SET(fd, fdt->close_on_exec);
+#endif
+ else
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
+ __clear_bit(fd, fdt->close_on_exec);
+#else
+ FD_CLR(fd, fdt->close_on_exec);
+#endif
+ spin_unlock(&files->file_lock);
+}
/**
* dma_buf_fd - returns a file descriptor for the given dma_buf
@@ -195,9 +220,10 @@ int dma_buf_fd(struct dma_buf *dmabuf, i
if (!dmabuf || !dmabuf->file)
return -EINVAL;
- fd = get_unused_fd_flags(flags);
+ fd = get_unused_fd();
if (fd < 0)
return fd;
+ dma_buf_fd_set_flag(fd, flags);
fd_install(fd, dmabuf->file);
@@ -725,17 +751,15 @@ static inline void dma_buf_uninit_debugf
}
#endif
-static int __init dma_buf_init(void)
+int __init dma_buf_init(void)
{
mutex_init(&db_list.lock);
INIT_LIST_HEAD(&db_list.head);
dma_buf_init_debugfs();
return 0;
}
-subsys_initcall(dma_buf_init);
-static void __exit dma_buf_deinit(void)
+void __exit dma_buf_deinit(void)
{
dma_buf_uninit_debugfs();
}
-__exitcall(dma_buf_deinit);
|