Skip to contentSkip to conversation

xfsprogs: fix compile warnings in libxfs

PATCH New Dave Chinner 1 participant 4 messages Jan 14, 2010

lore
Share & tools
lore
#1 lore raw

PATCH 1/3 xfsprogs: fix sign warnings in libxfs

The directory naming is a mix of char and uchar_t and the compiler warns wheter they cross over. Cast the pointers according to the destination requirements as it doesn't seem to matter to avoid the warnings.

---
 include/xfs_types.h     |    2 +-
 libxfs/xfs_attr.c       |   10 +++++-----
 libxfs/xfs_attr_leaf.c  |   10 +++++-----
 libxfs/xfs_dir2.c       |    2 +-
 libxfs/xfs_dir2_block.c |    8 ++++----
 libxfs/xfs_dir2_leaf.c  |    4 ++--
 libxfs/xfs_dir2_node.c  |    4 ++--
 libxfs/xfs_dir2_sf.c    |   13 +++++++------
 8 files changed, 27 insertions(+), 26 deletions(-)
include/xfs_types.h +1 -1
index 0f51916..6f566ff 100644
@@ -161,7 +161,7 @@ typedef enum {
 } xfs_btnum_t;
 
 struct xfs_name {
-	const char	*name;
+	const uchar_t	*name;
 	int		len;
 };
 
libxfs/xfs_attr.c +5 -5
index 7ab37ff..5bd3c2a 100644
@@ -64,7 +64,7 @@ xfs_attr_name_to_xname(
 {
 	if (!aname)
 		return EINVAL;
-	xname->name = aname;
+	xname->name = (const uchar_t *)aname;
 	xname->len = strlen(aname);
 	if (xname->len >= MAXNAMELEN)
 		return EFAULT;		/* match IRIX behaviour */
@@ -103,7 +103,7 @@ xfs_attr_fetch(xfs_inode_t *ip, struct xfs_name *name,
 	memset((char *)&args, 0, sizeof(args));
 	args.name = name->name;
 	args.namelen = name->len;
-	args.value = value;
+	args.value = (uchar_t *)value;
 	args.valuelen = *valuelenp;
 	args.flags = flags;
 	args.hashval = xfs_da_hashname(args.name, args.namelen);
@@ -233,7 +233,7 @@ xfs_attr_set_int(xfs_inode_t *dp, struct xfs_name *name,
 	memset((char *)&args, 0, sizeof(args));
 	args.name = name->name;
 	args.namelen = name->len;
-	args.value = value;
+	args.value = (uchar_t *)value;
 	args.valuelen = valuelen;
 	args.flags = flags;
 	args.hashval = xfs_da_hashname(args.name, args.namelen);
@@ -1545,7 +1545,7 @@ xfs_attr_rmtval_get(xfs_da_args_t *args)
 	ASSERT(!(args->flags & ATTR_KERNOVAL));
 
 	mp = args->dp->i_mount;
-	dst = args->value;
+	dst = (xfs_caddr_t)args->value;
 	valuelen = args->valuelen;
 	lblkno = args->rmtblkno;
 	while (valuelen > 0) {
@@ -1601,7 +1601,7 @@ xfs_attr_rmtval_set(xfs_da_args_t *args)
 
 	dp = args->dp;
 	mp = dp->i_mount;
-	src = args->value;
+	src = (xfs_caddr_t)args->value;
 
 	/*
 	 * Find a "hole" in the attribute address space large enough for
libxfs/xfs_attr_leaf.c +5 -5
index f8f926f..d535752 100644
@@ -476,11 +476,11 @@ xfs_attr_shortform_to_leaf(xfs_da_args_t *args)
 
 	sfe = &sf->list[0];
 	for (i = 0; i < sf->hdr.count; i++) {
-		nargs.name = (char *)sfe->nameval;
+		nargs.name = (uchar_t *)sfe->nameval;
 		nargs.namelen = sfe->namelen;
-		nargs.value = (char *)&sfe->nameval[nargs.namelen];
+		nargs.value = (uchar_t *)&sfe->nameval[nargs.namelen];
 		nargs.valuelen = sfe->valuelen;
-		nargs.hashval = xfs_da_hashname((char *)sfe->nameval,
+		nargs.hashval = xfs_da_hashname((uchar_t *)sfe->nameval,
 						sfe->namelen);
 		nargs.flags = XFS_ATTR_NSP_ONDISK_TO_ARGS(sfe->flags);
 		error = xfs_attr_leaf_lookup_int(bp, &nargs); /* set a->index */
@@ -610,9 +610,9 @@ xfs_attr_leaf_to_shortform(xfs_dabuf_t *bp, xfs_da_args_t *args, int forkoff)
 			continue;
 		ASSERT(entry->flags & XFS_ATTR_LOCAL);
 		name_loc = XFS_ATTR_LEAF_NAME_LOCAL(leaf, i);
-		nargs.name = (char *)name_loc->nameval;
+		nargs.name = (uchar_t *)name_loc->nameval;
 		nargs.namelen = name_loc->namelen;
-		nargs.value = (char *)&name_loc->nameval[nargs.namelen];
+		nargs.value = (uchar_t *)&name_loc->nameval[nargs.namelen];
 		nargs.valuelen = be16_to_cpu(name_loc->valuelen);
 		nargs.hashval = be32_to_cpu(entry->hashval);
 		nargs.flags = XFS_ATTR_NSP_ONDISK_TO_ARGS(entry->flags);
libxfs/xfs_dir2.c +1 -1
index 71134f8..2d2abd1 100644
@@ -18,7 +18,7 @@
 
 #include <xfs.h>
 
-struct xfs_name xfs_name_dotdot = {"..", 2};
+struct xfs_name xfs_name_dotdot = {(uchar_t *)"..", 2};
 
 extern const struct xfs_nameops xfs_default_nameops;
 
libxfs/xfs_dir2_block.c +4 -4
index d197b0b..d286000 100644
@@ -36,8 +36,8 @@ static xfs_dahash_t xfs_dir_hash_dot, xfs_dir_hash_dotdot;
 void
 xfs_dir_startup(void)
 {
-	xfs_dir_hash_dot = xfs_da_hashname(".", 1);
-	xfs_dir_hash_dotdot = xfs_da_hashname("..", 2);
+	xfs_dir_hash_dot = xfs_da_hashname((uchar_t *)".", 1);
+	xfs_dir_hash_dotdot = xfs_da_hashname((uchar_t *)"..", 2);
 }
 
 /*
@@ -489,7 +489,7 @@ xfs_dir2_block_lookup(
 	 * Fill in inode number, CI name if appropriate, release the block.
 	 */
 	args->inumber = be64_to_cpu(dep->inumber);
-	error = xfs_dir_cilookup_result(args, dep->name, dep->namelen);
+	error = xfs_dir_cilookup_result(args, (char *)dep->name, dep->namelen);
 	xfs_da_brelse(args->trans, bp);
 	return XFS_ERROR(error);
 }
@@ -576,7 +576,7 @@ xfs_dir2_block_lookup_int(
 		 * and buffer. If it's the first case-insensitive match, store
 		 * the index and buffer and continue looking for an exact match.
 		 */
-		cmp = mp->m_dirnameops->compname(args, dep->name, dep->namelen);
+		cmp = mp->m_dirnameops->compname(args, (char *)dep->name, dep->namelen);
 		if (cmp != XFS_CMP_DIFFERENT && cmp != args->cmpresult) {
 			args->cmpresult = cmp;
 			*bpp = bp;
libxfs/xfs_dir2_leaf.c +2 -2
index 9a1aace..356b541 100644
@@ -906,7 +906,7 @@ xfs_dir2_leaf_lookup(
 	 * Return the found inode number & CI name if appropriate
 	 */
 	args->inumber = be64_to_cpu(dep->inumber);
-	error = xfs_dir_cilookup_result(args, dep->name, dep->namelen);
+	error = xfs_dir_cilookup_result(args, (char *)dep->name, dep->namelen);
 	xfs_da_brelse(tp, dbp);
 	xfs_da_brelse(tp, lbp);
 	return XFS_ERROR(error);
@@ -1000,7 +1000,7 @@ xfs_dir2_leaf_lookup_int(
 		 * and buffer. If it's the first case-insensitive match, store
 		 * the index and buffer and continue looking for an exact match.
 		 */
-		cmp = mp->m_dirnameops->compname(args, dep->name, dep->namelen);
+		cmp = mp->m_dirnameops->compname(args, (char *)dep->name, dep->namelen);
 		if (cmp != XFS_CMP_DIFFERENT && cmp != args->cmpresult) {
 			args->cmpresult = cmp;
 			*indexp = index;
libxfs/xfs_dir2_node.c +2 -2
index db88adc..6a92f13 100644
@@ -612,7 +612,7 @@ xfs_dir2_leafn_lookup_for_entry(
 		 * EEXIST immediately. If it's the first case-insensitive
 		 * match, store the block & inode number and continue looking.
 		 */
-		cmp = mp->m_dirnameops->compname(args, dep->name, dep->namelen);
+		cmp = mp->m_dirnameops->compname(args, (char *)dep->name, dep->namelen);
 		if (cmp != XFS_CMP_DIFFERENT && cmp != args->cmpresult) {
 			/* If there is a CI match block, drop it */
 			if (args->cmpresult != XFS_CMP_DIFFERENT &&
@@ -1821,7 +1821,7 @@ xfs_dir2_node_lookup(
 
 		dep = (xfs_dir2_data_entry_t *)((char *)state->extrablk.bp->
 						data + state->extrablk.index);
-		rval = xfs_dir_cilookup_result(args, dep->name, dep->namelen);
+		rval = xfs_dir_cilookup_result(args, (char *)dep->name, dep->namelen);
 	}
 	/*
 	 * Release the btree blocks and leaf block.
libxfs/xfs_dir2_sf.c +7 -6
index 77f30de..06e076d 100644
@@ -732,8 +732,8 @@ xfs_dir2_sf_lookup(
 		 * number. If it's the first case-insensitive match, store the
 		 * inode number and continue looking for an exact match.
 		 */
-		cmp = dp->i_mount->m_dirnameops->compname(args, sfep->name,
-								sfep->namelen);
+		cmp = dp->i_mount->m_dirnameops->compname(args,
+					(char *)sfep->name, sfep->namelen);
 		if (cmp != XFS_CMP_DIFFERENT && cmp != args->cmpresult) {
 			args->cmpresult = cmp;
 			args->inumber = xfs_dir2_sf_get_inumber(sfp,
@@ -751,7 +751,8 @@ xfs_dir2_sf_lookup(
 	if (!ci_sfep)
 		return XFS_ERROR(ENOENT);
 	/* otherwise process the CI match as required by the caller */
-	error = xfs_dir_cilookup_result(args, ci_sfep->name, ci_sfep->namelen);
+	error = xfs_dir_cilookup_result(args, (char *)ci_sfep->name,
+						ci_sfep->namelen);
 	return XFS_ERROR(error);
 }
 
@@ -793,7 +794,7 @@ xfs_dir2_sf_removename(
 	 */
 	for (i = 0, sfep = xfs_dir2_sf_firstentry(sfp); i < sfp->hdr.count;
 				i++, sfep = xfs_dir2_sf_nextentry(sfp, sfep)) {
-		if (xfs_da_compname(args, sfep->name, sfep->namelen) ==
+		if (xfs_da_compname(args, (char *)sfep->name, sfep->namelen) ==
 								XFS_CMP_EXACT) {
 			ASSERT(xfs_dir2_sf_get_inumber(sfp,
 						xfs_dir2_sf_inumberp(sfep)) ==
@@ -928,8 +929,8 @@ xfs_dir2_sf_replace(
 		for (i = 0, sfep = xfs_dir2_sf_firstentry(sfp);
 				i < sfp->hdr.count;
 				i++, sfep = xfs_dir2_sf_nextentry(sfp, sfep)) {
-			if (xfs_da_compname(args, sfep->name, sfep->namelen) ==
-								XFS_CMP_EXACT) {
+			if (xfs_da_compname(args, (char *)sfep->name,
+					sfep->namelen) == XFS_CMP_EXACT) {
 #if XFS_BIG_INUMS || defined(DEBUG)
 				ino = xfs_dir2_sf_get_inumber(sfp,
 					xfs_dir2_sf_inumberp(sfep));
Signature · 6 lines
1.6.5

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#2 lore raw

PATCH 2/3 xfsprogs: Fix miscellaneous warnings in libxfs

In reply to Dave Chinner

These are questionable fixes but they do shut up the warnings with as little change as possible. The first couple are questionable because they are a result of the compiler (gcc 4.3.4) trying to be smart but failing.

The uninitialised variable warnings in xfs_bmapi() is spurious, as certain fields are unused in certain situations but gcc can't work that out. It is easily suppressed by initialising the structure to zero.

xfs_mod_sb() is dumping out an array subscript bound warning that is spurious. The code is correct and will assert fail on out of bounds indexes. A simple reorder of the first and last offset calculations makes the warning go away (a good sign of compiler fail if ever there was one).

Changing xfs_alloc_mark_busy() from a macro to a static inline definition is needed for the compiler to see that variables passed to that function are actually used.

---
 libxfs/xfs.h       |    5 +++--
 libxfs/xfs_bmap.c  |    2 +-
 libxfs/xfs_mount.c |    9 ++++-----
 3 files changed, 8 insertions(+), 8 deletions(-)
libxfs/xfs.h +3 -2
index 8e94dad..abe8700 100644
@@ -288,9 +288,10 @@ roundup_pow_of_two(uint v)
 #define xfs_ilock(ip,mode)				((void) 0)
 #define xfs_iunlock(ip,mode)				((void) 0)
 
-/* space allocation */
+/* space allocation - use static inlines to avoid unused var warnings */
 #define xfs_alloc_search_busy(tp,ag,b,len)	((void) 0)
-#define xfs_alloc_mark_busy(tp,ag,b,len)	((void) 0)
+static inline void xfs_alloc_mark_busy(xfs_trans_t *tp,
+	xfs_agnumber_t agno, xfs_agblock_t bno, xfs_extlen_t len) {}
 #define xfs_rotorstep				1
 #define xfs_bmap_rtalloc(a)			(ENOSYS)
 #define xfs_rtpick_extent(mp,tp,len,p)		(ENOSYS)
libxfs/xfs_bmap.c +1 -1
index cf1123a..4cc6431 100644
@@ -4274,7 +4274,7 @@ xfs_bmapi(
 	xfs_fsblock_t	abno;		/* allocated block number */
 	xfs_extlen_t	alen;		/* allocated extent length */
 	xfs_fileoff_t	aoff;		/* allocated file offset */
-	xfs_bmalloca_t	bma;		/* args for xfs_bmap_alloc */
+	xfs_bmalloca_t	bma = { 0 };	/* args for xfs_bmap_alloc */
 	xfs_btree_cur_t	*cur;		/* bmap btree cursor */
 	xfs_fileoff_t	end;		/* end of mapped file region */
 	int		eof;		/* we've hit the end of extents */
libxfs/xfs_mount.c +4 -5
index 02bff42..662c8d2 100644
@@ -400,15 +400,14 @@ xfs_mod_sb(xfs_trans_t *tp, __int64_t fields)
 
 	xfs_sb_to_disk(XFS_BUF_TO_SBP(bp), &mp->m_sb, fields);
 
-	/* find modified range */
+	/* find modified range - get last first to avoid spurious warning */
+	f = (xfs_sb_field_t)xfs_highbit64((__uint64_t)fields);
+	ASSERT((1LL << f) & XFS_SB_MOD_BITS);
+	last = xfs_sb_info[f + 1].offset - 1;
 
 	f = (xfs_sb_field_t)xfs_lowbit64((__uint64_t)fields);
 	ASSERT((1LL << f) & XFS_SB_MOD_BITS);
 	first = xfs_sb_info[f].offset;
 
-	f = (xfs_sb_field_t)xfs_highbit64((__uint64_t)fields);
-	ASSERT((1LL << f) & XFS_SB_MOD_BITS);
-	last = xfs_sb_info[f + 1].offset - 1;
-
 	xfs_trans_log_buf(tp, bp, first, last);
 }
Signature · 6 lines
1.6.5

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#3 lore raw

PATCH 3/3 xfsprogs: fix missing error check in xfs_rtfree_range in libxfs

In reply to Dave Chinner

When xfs_rtfind_forw() returns an error, the block is returned uninitialised. xfs_rtfree_range() is not checking the error return, so could be using an uninitialised block number for modifying bitmap summary info.

---
 libxfs/xfs_rtalloc.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
libxfs/xfs_rtalloc.c +2 -0
index 6c3da52..4fbdaa9 100644
@@ -466,6 +466,8 @@ xfs_rtfree_range(
 	 */
 	error = xfs_rtfind_forw(mp, tp, end, mp->m_sb.sb_rextents - 1,
 		&postblock);
+	if (error)
+		return error;
 	/*
 	 * If there are blocks not being freed at the front of the
 	 * old extent, add summary data for them to be allocated.
Signature · 6 lines
1.6.5

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs