From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f196.google.com ([209.85.192.196]:45471 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933401AbeGHVFp (ORCPT ); Sun, 8 Jul 2018 17:05:45 -0400 From: Eric Biggers To: David Howells , Alexander Viro , linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Eric Biggers Subject: [PATCH 14/18] fsopen,fspick: factor out log allocation Date: Sun, 8 Jul 2018 14:01:50 -0700 Message-Id: <20180708210154.10423-15-ebiggers3@gmail.com> In-Reply-To: <20180708210154.10423-1-ebiggers3@gmail.com> References: <20180708210154.10423-1-ebiggers3@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: From: Eric Biggers Signed-off-by: Eric Biggers --- fs/fsopen.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/fs/fsopen.c b/fs/fsopen.c index b3a22848f8eec..02edb4705fac2 100644 --- a/fs/fsopen.c +++ b/fs/fsopen.c @@ -223,6 +223,16 @@ static int fsopen_create_fd(struct fs_context *fc, unsigned int o_flags) return fd; } +static int fscontext_alloc_log(struct fs_context *fc) +{ + fc->log = kzalloc(sizeof(*fc->log), GFP_KERNEL); + if (!fc->log) + return -ENOMEM; + refcount_set(&fc->log->usage, 1); + fc->log->owner = fc->fs_type->owner; + return 0; +} + /* * Open a filesystem by name so that it can be configured for mounting. * @@ -257,14 +267,12 @@ SYSCALL_DEFINE2(fsopen, const char __user *, _fs_name, unsigned int, flags) if (IS_ERR(fc)) return PTR_ERR(fc); - ret = -ENOMEM; - fc->log = kzalloc(sizeof(*fc->log), GFP_KERNEL); - if (!fc->log) + fc->phase = FS_CONTEXT_CREATE_PARAMS; + + ret = fscontext_alloc_log(fc); + if (ret < 0) goto err_fc; - refcount_set(&fc->log->usage, 1); - fc->log->owner = fs_type->owner; - fc->phase = FS_CONTEXT_CREATE_PARAMS; return fsopen_create_fd(fc, flags & FSOPEN_CLOEXEC ? O_CLOEXEC : 0); err_fc: @@ -315,12 +323,9 @@ SYSCALL_DEFINE3(fspick, int, dfd, const char __user *, path, unsigned int, flags fc->phase = FS_CONTEXT_RECONF_PARAMS; - ret = -ENOMEM; - fc->log = kzalloc(sizeof(*fc->log), GFP_KERNEL); - if (!fc->log) + ret = fscontext_alloc_log(fc); + if (ret < 0) goto err_fc; - refcount_set(&fc->log->usage, 1); - fc->log->owner = fc->fs_type->owner; path_put(&target); return fsopen_create_fd(fc, flags & FSPICK_CLOEXEC ? O_CLOEXEC : 0); -- 2.18.0