Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 5 Feb 2018 14:30:27 +0000 (UTC)
From:      "Pedro F. Giffuni" <pfg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r328882 - head/sys/fs/ext2fs
Message-ID:  <201802051430.w15EURWm070273@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pfg
Date: Mon Feb  5 14:30:27 2018
New Revision: 328882
URL: https://svnweb.freebsd.org/changeset/base/328882

Log:
  ext2fs: Cleanup variable assignments for extents.
  
  Delay the initialization of variables until the are needed.
  
  In the case of ext4_ext_rm_leaf(), make sure 'error' value is not
  undefined.
  
  Reported by:		Clang's static analyzer
  Differential Revision:	https://reviews.freebsd.org/D14193

Modified:
  head/sys/fs/ext2fs/ext2_extents.c

Modified: head/sys/fs/ext2fs/ext2_extents.c
==============================================================================
--- head/sys/fs/ext2fs/ext2_extents.c	Mon Feb  5 14:19:36 2018	(r328881)
+++ head/sys/fs/ext2fs/ext2_extents.c	Mon Feb  5 14:30:27 2018	(r328882)
@@ -1159,14 +1159,13 @@ ext4_new_blocks(struct inode *ip, daddr_t lbn, e4fs_da
 	struct m_ext2fs *fs;
 	e4fs_daddr_t newblk;
 
-	fs = ip->i_e2fs;
-
 	/*
 	 * We will allocate only single block for now.
 	 */
 	if (*count > 1)
 		return (0);
 
+	fs = ip->i_e2fs;
 	EXT2_LOCK(ip->i_ump);
 	*perror = ext2_alloc(ip, lbn, pref, (int)fs->e2fs_bsize, cred, &newblk);
 	if (*perror)
@@ -1193,13 +1192,12 @@ ext4_ext_get_blocks(struct inode *ip, e4fs_daddr_t ibl
 	unsigned long allocated = 0;
 	int error = 0, depth;
 
-	fs = ip->i_e2fs;
-	*pallocated = 0;
-	path = NULL;
 	if(bpp)
 		*bpp = NULL;
+	*pallocated = 0;
 
 	/* Check cache. */
+	path = NULL;
 	if ((bpref = ext4_ext_in_cache(ip, iblk, &newex))) {
 		if (bpref == EXT4_EXT_CACHE_IN) {
 			/* Block is already allocated. */
@@ -1271,6 +1269,7 @@ out:
 
 	if (bpp)
 	{
+		fs = ip->i_e2fs;
 		error = bread(ip->i_devvp, fsbtodb(fs, newblk),
 		    fs->e2fs_bsize, cred, &bp);
 		if (error) {
@@ -1304,7 +1303,7 @@ static inline struct ext4_extent_header *
 ext4_ext_header(struct inode *ip)
 {
 
-	return (struct ext4_extent_header *)ip->i_db;
+	return ((struct ext4_extent_header *)ip->i_db);
 }
 
 static int
@@ -1345,19 +1344,15 @@ static int
 ext4_ext_rm_leaf(struct inode *ip, struct ext4_extent_path *path,
     uint64_t start)
 {
-	struct m_ext2fs *fs;
-	int depth;
 	struct ext4_extent_header *eh;
+	struct ext4_extent *ex;
 	unsigned int a, b, block, num;
 	unsigned long ex_blk;
 	unsigned short ex_len;
-	struct ext4_extent *ex;
+	int depth;
 	int error, correct_index;
 
-	fs = ip->i_e2fs;
 	depth = ext4_ext_inode_depth(ip);
-	correct_index = 0;
-
 	if (!path[depth].ep_header) {
 		if (path[depth].ep_data == NULL)
 			return (EINVAL);
@@ -1367,7 +1362,8 @@ ext4_ext_rm_leaf(struct inode *ip, struct ext4_extent_
 
 	eh = path[depth].ep_header;
 	if (!eh) {
-		ext2_fserr(fs, ip->i_uid, "bad header => extent corrupted");
+		ext2_fserr(ip->i_e2fs, ip->i_uid,
+		    "bad header => extent corrupted");
 		return (EIO);
 	}
 
@@ -1375,6 +1371,8 @@ ext4_ext_rm_leaf(struct inode *ip, struct ext4_extent_
 	ex_blk = ex->e_blk;
 	ex_len = ext4_ext_get_actual_len(ex);
 
+	error = 0;
+	correct_index = 0;
 	while (ex >= EXT_FIRST_EXTENT(eh) && ex_blk + ex_len > start) {
 		path[depth].ep_ext = ex;
 		a = ex_blk > start ? ex_blk : start;
@@ -1442,7 +1440,6 @@ ext4_read_extent_tree_block(struct inode *ip, e4fs_dad
 	int error;
 
 	fs = ip->i_e2fs;
-
 	error = bread(ip->i_devvp, fsbtodb(fs, pblk),
 	    fs->e2fs_bsize, NOCRED, &bp);
 	if (error) {
@@ -1506,10 +1503,10 @@ ext4_ext_remove_space(struct inode *ip, off_t length, 
 	if (!path)
 		return (ENOMEM);
 
-	i = 0;
 	path[0].ep_header = ehp;
 	path[0].ep_depth = depth;
-	while (i >= 0 && error == 0) {
+	i = 0;
+	while (error == 0 && i >= 0) {
 		if (i == depth) {
 			/* This is leaf. */
 			error = ext4_ext_rm_leaf(ip, path, length);
@@ -1568,7 +1565,6 @@ ext4_ext_remove_space(struct inode *ip, off_t length, 
 		 ext4_ext_header(ip)->eh_depth = 0;
 		 ext4_ext_header(ip)->eh_max = ext4_ext_space_root(ip);
 		 ext4_ext_dirty(ip, path);
-
 	}
 
 	ext4_ext_drop_refs(path);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201802051430.w15EURWm070273>