Reformat the existing code a bit to make it easier for further patching. Signed-off-by: Pavel Emelyanov <xemul@xxxxxxxxxxxxx> --- fs/userfaultfd.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index b4c7f25..6c9a2d6 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -61,6 +61,23 @@ struct userfaultfd_wake_range { unsigned long len; }; +static const struct file_operations userfaultfd_fops; + +static struct userfaultfd_ctx *userfaultfd_ctx_alloc(void) +{ + struct userfaultfd_ctx *ctx; + + ctx = kmalloc(sizeof(*ctx), GFP_KERNEL); + if (ctx) { + atomic_set(&ctx->refcount, 1); + init_waitqueue_head(&ctx->fault_wqh); + init_waitqueue_head(&ctx->fd_wqh); + ctx->released = false; + } + + return ctx; +} + static int userfaultfd_wake_function(wait_queue_t *wq, unsigned mode, int wake_flags, void *key) { @@ -307,15 +324,15 @@ static int userfaultfd_release(struct inode *inode, struct file *file) return 0; } -static inline unsigned int find_userfault(struct userfaultfd_ctx *ctx, +static inline unsigned int do_find_userfault(wait_queue_head_t *wqh, struct userfaultfd_wait_queue **uwq) { wait_queue_t *wq; struct userfaultfd_wait_queue *_uwq; unsigned int ret = 0; - spin_lock(&ctx->fault_wqh.lock); - list_for_each_entry(wq, &ctx->fault_wqh.task_list, task_list) { + spin_lock(&wqh->lock); + list_for_each_entry(wq, &wqh->task_list, task_list) { _uwq = container_of(wq, struct userfaultfd_wait_queue, wq); if (_uwq->pending) { ret = POLLIN; @@ -324,11 +341,17 @@ static inline unsigned int find_userfault(struct userfaultfd_ctx *ctx, break; } } - spin_unlock(&ctx->fault_wqh.lock); + spin_unlock(&wqh->lock); return ret; } +static inline unsigned int find_userfault(struct userfaultfd_ctx *ctx, + struct userfaultfd_wait_queue **uwq) +{ + return do_find_userfault(&ctx->fault_wqh, uwq); +} + static unsigned int userfaultfd_poll(struct file *file, poll_table *wait) { struct userfaultfd_ctx *ctx = file->private_data; @@ -1080,16 +1103,12 @@ static struct file *userfaultfd_file_create(int flags) goto out; file = ERR_PTR(-ENOMEM); - ctx = kmalloc(sizeof(*ctx), GFP_KERNEL); + ctx = userfaultfd_ctx_alloc(); if (!ctx) goto out; - atomic_set(&ctx->refcount, 1); - init_waitqueue_head(&ctx->fault_wqh); - init_waitqueue_head(&ctx->fd_wqh); ctx->flags = flags; ctx->state = UFFD_STATE_WAIT_API; - ctx->released = false; ctx->mm = current->mm; /* prevent the mm struct to be freed */ atomic_inc(&ctx->mm->mm_count); -- 1.8.4.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@xxxxxxxxx. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@xxxxxxxxx"> email@xxxxxxxxx </a>