[IMPROVE] remove atomic context for img_proc.filse
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Thu, 31 Mar 2016 19:22:07 +0000 (22:22 +0300)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Tue, 12 Apr 2016 08:07:37 +0000 (11:07 +0300)
Change-Id: I52f848ebbd0c62c5335793ab35254ca5250ce05d
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
us_manager/img/img_proc.c

index 6132af7..5f0c70c 100644 (file)
@@ -25,7 +25,7 @@
 
 #include <linux/slab.h>
 #include <linux/list.h>
-#include <linux/spinlock.h>
+#include <linux/mutex.h>
 #include <us_manager/sspt/sspt_proc.h>
 #include <us_manager/sspt/sspt_file.h>
 #include "img_ip.h"
 
 struct img_proc {
        /* img_file */
-       struct list_head file_head;
-       rwlock_t rwlock;
+       struct {
+               struct list_head head;
+               struct mutex mtx;
+       } files;
 };
 
 
@@ -53,8 +55,8 @@ struct img_proc *img_proc_create(void)
 
        proc = kmalloc(sizeof(*proc), GFP_ATOMIC);
        if (proc) {
-               INIT_LIST_HEAD(&proc->file_head);
-               rwlock_init(&proc->rwlock);
+               INIT_LIST_HEAD(&proc->files.head);
+               mutex_init(&proc->files.mtx);
        }
 
        return proc;
@@ -70,39 +72,37 @@ void img_proc_free(struct img_proc *proc)
 {
        struct img_file *file, *tmp;
 
-       write_lock(&proc->rwlock);
-       list_for_each_entry_safe(file, tmp, &proc->file_head, list) {
+       mutex_lock(&proc->files.mtx);
+       list_for_each_entry_safe(file, tmp, &proc->files.head, list) {
                img_del_file_by_list(file);
                img_file_put(file);
        }
-       write_unlock(&proc->rwlock);
+       mutex_unlock(&proc->files.mtx);
 
        kfree(proc);
 }
 
-/* called with write_[lock/unlock](&proc->rwlock) */
+/* called with mutex_[lock/unlock](&proc->files.mtx) */
 static void img_add_file_by_list(struct img_proc *proc, struct img_file *file)
 {
-       list_add(&file->list, &proc->file_head);
+       list_add(&file->list, &proc->files.head);
 }
 
-/* called with write_[lock/unlock](&proc->rwlock) */
+/* called with mutex_[lock/unlock](&proc->files.mtx) */
 static void img_del_file_by_list(struct img_file *file)
 {
        list_del(&file->list);
 }
 
-/* called with read_[lock/unlock](&proc->rwlock) */
-static struct img_file *img_file_find_get(struct img_proc *proc,
-                                         struct dentry *dentry)
+/* called with mutex_[lock/unlock](&proc->files.mtx) */
+static struct img_file *img_file_find(struct img_proc *proc,
+                                     struct dentry *dentry)
 {
        struct img_file *file;
 
-       list_for_each_entry(file, &proc->file_head, list) {
-               if (file->dentry == dentry) {
-                       img_file_get(file);
+       list_for_each_entry(file, &proc->files.head, list) {
+               if (file->dentry == dentry)
                        return file;
-               }
        }
 
        return NULL;
@@ -123,26 +123,24 @@ int img_proc_add_ip(struct img_proc *proc, struct dentry *dentry,
        int ret;
        struct img_file *file;
 
-       write_lock(&proc->rwlock);
-       file = img_file_find_get(proc, dentry);
-       write_unlock(&proc->rwlock);
+       mutex_lock(&proc->files.mtx);
+       file = img_file_find(proc, dentry);
 
        if (!file) {
                file = img_file_create(dentry);
-               if (!file)
+               if (!file) {
+                       mutex_unlock(&proc->files.mtx);
                        return -ENOMEM;
+               }
 
-               img_file_get(file);
-               write_lock(&proc->rwlock);
                img_add_file_by_list(proc, file);
-               write_unlock(&proc->rwlock);
        }
+       mutex_unlock(&proc->files.mtx);
 
        ret = img_file_add_ip(file, addr, pd);
        if (ret)
                printk(KERN_INFO "Cannot add ip to img file\n");
 
-       img_file_put(file);
        return ret;
 }
 
@@ -159,27 +157,21 @@ int img_proc_del_ip(struct img_proc *proc,
                    unsigned long addr,
                    struct probe_desc *pd)
 {
-       int ret;
+       int ret = -EINVAL;
        struct img_file *file;
 
-       write_lock(&proc->rwlock);
-       file = img_file_find_get(proc, dentry);
-       write_unlock(&proc->rwlock);
-
-       if (!file)
-               return -EINVAL;
-
-       ret = img_file_del_ip(file, addr, pd);
-       if (ret == 0 && img_file_empty(file)) {
-               write_lock(&proc->rwlock);
-               img_del_file_by_list(file);
-               write_unlock(&proc->rwlock);
-               img_file_put(file);
+       mutex_lock(&proc->files.mtx);
+       file = img_file_find(proc, dentry);
+       if (file) {
+               ret = img_file_del_ip(file, addr, pd);
+               if (img_file_empty(file)) {
+                       img_del_file_by_list(file);
+                       img_file_put(file);
+               }
        }
+       mutex_unlock(&proc->files.mtx);
 
-       img_file_put(file);
-
-       return 0;
+       return ret;
 }
 
 void img_proc_copy_to_sspt(struct img_proc *i_proc, struct sspt_proc *proc)
@@ -187,8 +179,8 @@ void img_proc_copy_to_sspt(struct img_proc *i_proc, struct sspt_proc *proc)
        struct sspt_file *file;
        struct img_file *i_file;
 
-       read_lock(&i_proc->rwlock);
-       list_for_each_entry(i_file, &i_proc->file_head, list) {
+       mutex_lock(&i_proc->files.mtx);
+       list_for_each_entry(i_file, &i_proc->files.head, list) {
                file = sspt_proc_find_file_or_new(proc, i_file->dentry);
                if (file) {
                        struct img_ip *i_ip;
@@ -197,7 +189,7 @@ void img_proc_copy_to_sspt(struct img_proc *i_proc, struct sspt_proc *proc)
                                sspt_file_add_ip(file, i_ip);
                }
        }
-       read_unlock(&i_proc->rwlock);
+       mutex_unlock(&i_proc->files.mtx);
 }
 
 /**
@@ -214,10 +206,10 @@ void img_proc_print(struct img_proc *proc)
 
        printk(KERN_INFO "### img_proc_print:\n");
 
-       read_lock(&proc->rwlock);
-       list_for_each_entry(file, &proc->file_head, list) {
+       mutex_lock(&proc->files.mtx);
+       list_for_each_entry(file, &proc->files.head, list) {
                img_file_print(file);
        }
-       read_unlock(&proc->rwlock);
+       mutex_unlock(&proc->files.mtx);
 }
 /* debug */