Commit 8ce03fd7 authored by David Herrmann's avatar David Herrmann Committed by Miklos Szeredi

cuse: use mutex as registration lock instead of spinlocks

We need to check for name-collisions during cuse-device registration. To
avoid race-conditions, this needs to be protected during the whole device
registration. Therefore, replace the spinlocks by mutexes first so we can
safely extend the locked regions to include more expensive or sleeping
code paths.
Signed-off-by: default avatarDavid Herrmann <dh.herrmann@googlemail.com>
Acked-by: default avatarTejun Heo <tj@kernel.org>
Signed-off-by: default avatarMiklos Szeredi <mszeredi@suse.cz>
parent dfdebc24
...@@ -45,7 +45,6 @@ ...@@ -45,7 +45,6 @@
#include <linux/miscdevice.h> #include <linux/miscdevice.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/stat.h> #include <linux/stat.h>
#include <linux/module.h> #include <linux/module.h>
...@@ -63,7 +62,7 @@ struct cuse_conn { ...@@ -63,7 +62,7 @@ struct cuse_conn {
bool unrestricted_ioctl; bool unrestricted_ioctl;
}; };
static DEFINE_SPINLOCK(cuse_lock); /* protects cuse_conntbl */ static DEFINE_MUTEX(cuse_lock); /* protects registration */
static struct list_head cuse_conntbl[CUSE_CONNTBL_LEN]; static struct list_head cuse_conntbl[CUSE_CONNTBL_LEN];
static struct class *cuse_class; static struct class *cuse_class;
...@@ -114,14 +113,14 @@ static int cuse_open(struct inode *inode, struct file *file) ...@@ -114,14 +113,14 @@ static int cuse_open(struct inode *inode, struct file *file)
int rc; int rc;
/* look up and get the connection */ /* look up and get the connection */
spin_lock(&cuse_lock); mutex_lock(&cuse_lock);
list_for_each_entry(pos, cuse_conntbl_head(devt), list) list_for_each_entry(pos, cuse_conntbl_head(devt), list)
if (pos->dev->devt == devt) { if (pos->dev->devt == devt) {
fuse_conn_get(&pos->fc); fuse_conn_get(&pos->fc);
cc = pos; cc = pos;
break; break;
} }
spin_unlock(&cuse_lock); mutex_unlock(&cuse_lock);
/* dead? */ /* dead? */
if (!cc) if (!cc)
...@@ -377,9 +376,9 @@ static void cuse_process_init_reply(struct fuse_conn *fc, struct fuse_req *req) ...@@ -377,9 +376,9 @@ static void cuse_process_init_reply(struct fuse_conn *fc, struct fuse_req *req)
cc->cdev = cdev; cc->cdev = cdev;
/* make the device available */ /* make the device available */
spin_lock(&cuse_lock); mutex_lock(&cuse_lock);
list_add(&cc->list, cuse_conntbl_head(devt)); list_add(&cc->list, cuse_conntbl_head(devt));
spin_unlock(&cuse_lock); mutex_unlock(&cuse_lock);
/* announce device availability */ /* announce device availability */
dev_set_uevent_suppress(dev, 0); dev_set_uevent_suppress(dev, 0);
...@@ -520,9 +519,9 @@ static int cuse_channel_release(struct inode *inode, struct file *file) ...@@ -520,9 +519,9 @@ static int cuse_channel_release(struct inode *inode, struct file *file)
int rc; int rc;
/* remove from the conntbl, no more access from this point on */ /* remove from the conntbl, no more access from this point on */
spin_lock(&cuse_lock); mutex_lock(&cuse_lock);
list_del_init(&cc->list); list_del_init(&cc->list);
spin_unlock(&cuse_lock); mutex_unlock(&cuse_lock);
/* remove device */ /* remove device */
if (cc->dev) if (cc->dev)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment