ANDROID: ashmem: Add shmem_set_file to mm/shmem.c
authorJohn Stultz <john.stultz@linaro.org>
Fri, 16 Dec 2011 02:51:04 +0000 (18:51 -0800)
committerAmit Pundir <amit.pundir@linaro.org>
Mon, 18 Dec 2017 15:41:22 +0000 (21:11 +0530)
NOT FOR STAGING
This patch re-adds the original shmem_set_file to mm/shmem.c
and converts ashmem.c back to using it.

Change-Id: Ie604c9f8f4d0ee6bc2aae1a96d261c8373a1a2dc
CC: Brian Swetland <swetland@google.com>
CC: Colin Cross <ccross@android.com>
CC: Arve Hjønnevåg <arve@android.com>
CC: Dima Zavin <dima@android.com>
CC: Robert Love <rlove@google.com>
CC: Greg KH <greg@kroah.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
drivers/staging/android/ashmem.c
include/linux/mm.h
mm/shmem.c

index 0f695df14c9d8f0a5c0a95ea8c28dc075c2aa36c..5a7f8431aae7cc9907a288096503680a7ab08151 100644 (file)
@@ -401,22 +401,14 @@ static int ashmem_mmap(struct file *file, struct vm_area_struct *vma)
        }
        get_file(asma->file);
 
-       /*
-        * XXX - Reworked to use shmem_zero_setup() instead of
-        * shmem_set_file while we're in staging. -jstultz
-        */
-       if (vma->vm_flags & VM_SHARED) {
-               ret = shmem_zero_setup(vma);
-               if (ret) {
-                       fput(asma->file);
-                       goto out;
-               }
+       if (vma->vm_flags & VM_SHARED)
+               shmem_set_file(vma, asma->file);
+       else {
+               if (vma->vm_file)
+                       fput(vma->vm_file);
+               vma->vm_file = asma->file;
        }
 
-       if (vma->vm_file)
-               fput(vma->vm_file);
-       vma->vm_file = asma->file;
-
 out:
        mutex_unlock(&ashmem_mutex);
        return ret;
index 43edf659453b2692a618d3d093d1f00262a6e715..ab2cb8f5faadab3aa25632d107c09992a58b2a90 100644 (file)
@@ -1222,6 +1222,8 @@ extern void pagefault_out_of_memory(void);
 
 extern void show_free_areas(unsigned int flags, nodemask_t *nodemask);
 
+void shmem_set_file(struct vm_area_struct *vma, struct file *file);
+
 extern bool can_do_mlock(void);
 extern int user_shm_lock(size_t, struct user_struct *);
 extern void user_shm_unlock(size_t, struct user_struct *);
index 07a1d22807beb7cfb5f85c3343a5eacdc28fb523..4aace97f8a25dc0beafacb6d12dfdde620307516 100644 (file)
@@ -4266,6 +4266,14 @@ struct file *shmem_file_setup(const char *name, loff_t size, unsigned long flags
 }
 EXPORT_SYMBOL_GPL(shmem_file_setup);
 
+void shmem_set_file(struct vm_area_struct *vma, struct file *file)
+{
+       if (vma->vm_file)
+               fput(vma->vm_file);
+       vma->vm_file = file;
+       vma->vm_ops = &shmem_vm_ops;
+}
+
 /**
  * shmem_zero_setup - setup a shared anonymous mapping
  * @vma: the vma to be mmapped is prepared by do_mmap_pgoff
@@ -4285,10 +4293,7 @@ int shmem_zero_setup(struct vm_area_struct *vma)
        if (IS_ERR(file))
                return PTR_ERR(file);
 
-       if (vma->vm_file)
-               fput(vma->vm_file);
-       vma->vm_file = file;
-       vma->vm_ops = &shmem_vm_ops;
+       shmem_set_file(vma, file);
 
        if (IS_ENABLED(CONFIG_TRANSPARENT_HUGE_PAGECACHE) &&
                        ((vma->vm_start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK) <