]> Pileus Git - ~andy/linux/commitdiff
expose a low-level variant of fd_install() for binder
authorAl Viro <viro@zeniv.linux.org.uk>
Thu, 16 Aug 2012 01:06:33 +0000 (21:06 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Thu, 27 Sep 2012 01:08:55 +0000 (21:08 -0400)
Similar situation to that of __alloc_fd(); do not use unless you
really have to.  You should not touch any descriptor table other
than your own; it's a sure sign of a really bad API design.

As with __alloc_fd(), you *must* use a first-class reference to
struct files_struct; something obtained by get_files_struct(some task)
(let alone direct task->files) will not do.  It must be either
current->files, or obtained by get_files_struct(current) by the
owner of that sucker and given to you.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
drivers/staging/android/binder.c
fs/file.c
include/linux/fdtable.h

index 4946d282a35c632f4092f6b51db9ffd13387ee03..9e1a98a360d40dd8b59db99f4c1b4ebfb9daa2dd 100644 (file)
@@ -386,17 +386,8 @@ int task_get_unused_fd_flags(struct binder_proc *proc, int flags)
 static void task_fd_install(
        struct binder_proc *proc, unsigned int fd, struct file *file)
 {
-       struct files_struct *files = proc->files;
-       struct fdtable *fdt;
-
-       if (files == NULL)
-               return;
-
-       spin_lock(&files->file_lock);
-       fdt = files_fdtable(files);
-       BUG_ON(fdt->fd[fd] != NULL);
-       rcu_assign_pointer(fdt->fd[fd], file);
-       spin_unlock(&files->file_lock);
+       if (proc->files)
+               __fd_install(proc->files, fd, file);
 }
 
 /*
index 78cf88f2a0e88b0d265e6dfb95c9269e0a3be3e0..0d1bf05151112d1692eaf3681a3ddfed49e05c2f 100644 (file)
--- a/fs/file.c
+++ b/fs/file.c
@@ -599,11 +599,18 @@ EXPORT_SYMBOL(put_unused_fd);
  *
  * It should never happen - if we allow dup2() do it, _really_ bad things
  * will follow.
+ *
+ * NOTE: __fd_install() variant is really, really low-level; don't
+ * use it unless you are forced to by truly lousy API shoved down
+ * your throat.  'files' *MUST* be either current->files or obtained
+ * by get_files_struct(current) done by whoever had given it to you,
+ * or really bad things will happen.  Normally you want to use
+ * fd_install() instead.
  */
 
-void fd_install(unsigned int fd, struct file *file)
+void __fd_install(struct files_struct *files, unsigned int fd,
+               struct file *file)
 {
-       struct files_struct *files = current->files;
        struct fdtable *fdt;
        spin_lock(&files->file_lock);
        fdt = files_fdtable(files);
@@ -612,4 +619,9 @@ void fd_install(unsigned int fd, struct file *file)
        spin_unlock(&files->file_lock);
 }
 
+void fd_install(unsigned int fd, struct file *file)
+{
+       __fd_install(current->files, fd, file);
+}
+
 EXPORT_SYMBOL(fd_install);
index 3855f4febe706e1dbd24d7bb613d4b0d49593a49..59d4fc7f10c841d99f0d14f241caffdec58083bd 100644 (file)
@@ -121,6 +121,8 @@ struct files_struct *dup_fd(struct files_struct *, int *);
 
 extern int __alloc_fd(struct files_struct *files,
                      unsigned start, unsigned end, unsigned flags);
+extern void __fd_install(struct files_struct *files,
+                     unsigned int fd, struct file *file);
 
 extern struct kmem_cache *files_cachep;