IB/ucm: convert semaphore to mutex
Convert semaphore in ib_ucm_file to a real mutex. Signed-off-by: Sean Hefty <sean.hefty@intel.com> Signed-off-by: Roland Dreier <rolandd@cisco.com>
This commit is contained in:
committed by
Roland Dreier
parent
6bfa24fa3e
commit
4be10c1e6d
@@ -64,7 +64,7 @@ struct ib_ucm_device {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct ib_ucm_file {
|
struct ib_ucm_file {
|
||||||
struct semaphore mutex;
|
struct mutex file_mutex;
|
||||||
struct file *filp;
|
struct file *filp;
|
||||||
struct ib_ucm_device *device;
|
struct ib_ucm_device *device;
|
||||||
|
|
||||||
@@ -153,7 +153,7 @@ static void ib_ucm_cleanup_events(struct ib_ucm_context *ctx)
|
|||||||
{
|
{
|
||||||
struct ib_ucm_event *uevent;
|
struct ib_ucm_event *uevent;
|
||||||
|
|
||||||
down(&ctx->file->mutex);
|
mutex_lock(&ctx->file->file_mutex);
|
||||||
list_del(&ctx->file_list);
|
list_del(&ctx->file_list);
|
||||||
while (!list_empty(&ctx->events)) {
|
while (!list_empty(&ctx->events)) {
|
||||||
|
|
||||||
@@ -168,7 +168,7 @@ static void ib_ucm_cleanup_events(struct ib_ucm_context *ctx)
|
|||||||
|
|
||||||
kfree(uevent);
|
kfree(uevent);
|
||||||
}
|
}
|
||||||
up(&ctx->file->mutex);
|
mutex_unlock(&ctx->file->file_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct ib_ucm_context *ib_ucm_ctx_alloc(struct ib_ucm_file *file)
|
static struct ib_ucm_context *ib_ucm_ctx_alloc(struct ib_ucm_file *file)
|
||||||
@@ -375,11 +375,11 @@ static int ib_ucm_event_handler(struct ib_cm_id *cm_id,
|
|||||||
if (result)
|
if (result)
|
||||||
goto err2;
|
goto err2;
|
||||||
|
|
||||||
down(&ctx->file->mutex);
|
mutex_lock(&ctx->file->file_mutex);
|
||||||
list_add_tail(&uevent->file_list, &ctx->file->events);
|
list_add_tail(&uevent->file_list, &ctx->file->events);
|
||||||
list_add_tail(&uevent->ctx_list, &ctx->events);
|
list_add_tail(&uevent->ctx_list, &ctx->events);
|
||||||
wake_up_interruptible(&ctx->file->poll_wait);
|
wake_up_interruptible(&ctx->file->poll_wait);
|
||||||
up(&ctx->file->mutex);
|
mutex_unlock(&ctx->file->file_mutex);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err2:
|
err2:
|
||||||
@@ -405,7 +405,7 @@ static ssize_t ib_ucm_event(struct ib_ucm_file *file,
|
|||||||
if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
|
if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
|
|
||||||
down(&file->mutex);
|
mutex_lock(&file->file_mutex);
|
||||||
while (list_empty(&file->events)) {
|
while (list_empty(&file->events)) {
|
||||||
|
|
||||||
if (file->filp->f_flags & O_NONBLOCK) {
|
if (file->filp->f_flags & O_NONBLOCK) {
|
||||||
@@ -420,9 +420,9 @@ static ssize_t ib_ucm_event(struct ib_ucm_file *file,
|
|||||||
|
|
||||||
prepare_to_wait(&file->poll_wait, &wait, TASK_INTERRUPTIBLE);
|
prepare_to_wait(&file->poll_wait, &wait, TASK_INTERRUPTIBLE);
|
||||||
|
|
||||||
up(&file->mutex);
|
mutex_unlock(&file->file_mutex);
|
||||||
schedule();
|
schedule();
|
||||||
down(&file->mutex);
|
mutex_lock(&file->file_mutex);
|
||||||
|
|
||||||
finish_wait(&file->poll_wait, &wait);
|
finish_wait(&file->poll_wait, &wait);
|
||||||
}
|
}
|
||||||
@@ -482,7 +482,7 @@ static ssize_t ib_ucm_event(struct ib_ucm_file *file,
|
|||||||
kfree(uevent->info);
|
kfree(uevent->info);
|
||||||
kfree(uevent);
|
kfree(uevent);
|
||||||
done:
|
done:
|
||||||
up(&file->mutex);
|
mutex_unlock(&file->file_mutex);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -501,9 +501,9 @@ static ssize_t ib_ucm_create_id(struct ib_ucm_file *file,
|
|||||||
if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
|
if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
|
|
||||||
down(&file->mutex);
|
mutex_lock(&file->file_mutex);
|
||||||
ctx = ib_ucm_ctx_alloc(file);
|
ctx = ib_ucm_ctx_alloc(file);
|
||||||
up(&file->mutex);
|
mutex_unlock(&file->file_mutex);
|
||||||
if (!ctx)
|
if (!ctx)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
@@ -1177,7 +1177,7 @@ static int ib_ucm_open(struct inode *inode, struct file *filp)
|
|||||||
INIT_LIST_HEAD(&file->ctxs);
|
INIT_LIST_HEAD(&file->ctxs);
|
||||||
init_waitqueue_head(&file->poll_wait);
|
init_waitqueue_head(&file->poll_wait);
|
||||||
|
|
||||||
init_MUTEX(&file->mutex);
|
mutex_init(&file->file_mutex);
|
||||||
|
|
||||||
filp->private_data = file;
|
filp->private_data = file;
|
||||||
file->filp = filp;
|
file->filp = filp;
|
||||||
@@ -1191,11 +1191,11 @@ static int ib_ucm_close(struct inode *inode, struct file *filp)
|
|||||||
struct ib_ucm_file *file = filp->private_data;
|
struct ib_ucm_file *file = filp->private_data;
|
||||||
struct ib_ucm_context *ctx;
|
struct ib_ucm_context *ctx;
|
||||||
|
|
||||||
down(&file->mutex);
|
mutex_lock(&file->file_mutex);
|
||||||
while (!list_empty(&file->ctxs)) {
|
while (!list_empty(&file->ctxs)) {
|
||||||
ctx = list_entry(file->ctxs.next,
|
ctx = list_entry(file->ctxs.next,
|
||||||
struct ib_ucm_context, file_list);
|
struct ib_ucm_context, file_list);
|
||||||
up(&file->mutex);
|
mutex_unlock(&file->file_mutex);
|
||||||
|
|
||||||
mutex_lock(&ctx_id_mutex);
|
mutex_lock(&ctx_id_mutex);
|
||||||
idr_remove(&ctx_id_table, ctx->id);
|
idr_remove(&ctx_id_table, ctx->id);
|
||||||
@@ -1205,9 +1205,9 @@ static int ib_ucm_close(struct inode *inode, struct file *filp)
|
|||||||
ib_ucm_cleanup_events(ctx);
|
ib_ucm_cleanup_events(ctx);
|
||||||
kfree(ctx);
|
kfree(ctx);
|
||||||
|
|
||||||
down(&file->mutex);
|
mutex_lock(&file->file_mutex);
|
||||||
}
|
}
|
||||||
up(&file->mutex);
|
mutex_unlock(&file->file_mutex);
|
||||||
kfree(file);
|
kfree(file);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user