From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Eric W. Biederman" Subject: [PATCH 22/26] sysfs: Normalize error handling in sysfs_fill_inode Date: Fri, 29 May 2009 13:19:32 -0700 Message-ID: <1243628376-22905-22-git-send-email-ebiederm@xmission.com> References: Cc: , Tejun Heo , Cornelia Huck , , Kay Sievers , Greg KH , "Eric W. Biederman" , "Eric W. Biederman" To: Andrew Morton , Greg Kroah-Hartman Return-path: Received: from out02.mta.xmission.com ([166.70.13.232]:45222 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1763415AbZE2UT4 (ORCPT ); Fri, 29 May 2009 16:19:56 -0400 In-Reply-To: Sender: linux-fsdevel-owner@vger.kernel.org List-ID: From: Eric W. Biederman Use a single error exit path instead of doing whatever is the required cleanup at each point we find the error. Ultimately this should make the code more maintainable. Acked-by: Tejun Heo Signed-off-by: Eric W. Biederman --- fs/sysfs/mount.c | 16 +++++++++++----- 1 files changed, 11 insertions(+), 5 deletions(-) diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c index 0cb1088..1dd023a 100644 --- a/fs/sysfs/mount.c +++ b/fs/sysfs/mount.c @@ -41,8 +41,9 @@ struct sysfs_dirent sysfs_root = { static int sysfs_fill_super(struct super_block *sb, void *data, int silent) { - struct inode *inode; - struct dentry *root; + struct inode *inode = NULL; + struct dentry *root = NULL; + int error; sb->s_blocksize = PAGE_CACHE_SIZE; sb->s_blocksize_bits = PAGE_CACHE_SHIFT; @@ -51,24 +52,29 @@ static int sysfs_fill_super(struct super_block *sb, void *data, int silent) sb->s_time_gran = 1; /* get root inode, initialize and unlock it */ + error = -ENOMEM; mutex_lock(&sysfs_mutex); inode = sysfs_get_inode(sb, &sysfs_root); mutex_unlock(&sysfs_mutex); if (!inode) { pr_debug("sysfs: could not get root inode\n"); - return -ENOMEM; + goto err_out; } /* instantiate and link root dentry */ + error = -ENOMEM; root = d_alloc_root(inode); if (!root) { pr_debug("%s: could not get root dentry!\n",__func__); - iput(inode); - return -ENOMEM; + goto err_out; } root->d_fsdata = &sysfs_root; sb->s_root = root; return 0; +err_out: + dput(root); + iput(inode); + return error; } static int sysfs_get_sb(struct file_system_type *fs_type, -- 1.6.3.1.54.g99dd.dirty