#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;
};
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;
{
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;
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;
}
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)
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;
sspt_file_add_ip(file, i_ip);
}
}
- read_unlock(&i_proc->rwlock);
+ mutex_unlock(&i_proc->files.mtx);
}
/**
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 */