Skip to contentSkip to conversation

AFS: Fix compilation warning

PATCH In review David Howells 3 participants 9 messages Jul 9, 2009 – Jul 14, 2009 Afs filesystem

lore
Share & tools
lore

David Howells

author maintainer
#0 lore raw

PATCH 1/1 AFS: Fix compilation warning

From: Artem Bityutskiy <[email protected]>

Fix the following warning:

fs/afs/dir.c: In function 'afs_d_revalidate':
fs/afs/dir.c:567: warning: 'fid.vnode' may be used uninitialized in this function fs/afs/dir.c:567: warning: 'fid.unique' may be used uninitialized in this function

by marking the 'fid' variable as an uninitialized_var. The problem is that gcc doesn't always manage to work out that fid is always set on the path through the function that uses it.

---

 fs/afs/dir.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/afs/dir.c +1 -1
index 5272872..790ba9d 100644
@@ -566,7 +566,7 @@ static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry,
 static int afs_d_revalidate(struct dentry *dentry, struct nameidata *nd)
 {
 	struct afs_vnode *vnode, *dir;
-	struct afs_fid fid;
+	struct afs_fid uninitialized_var(fid);
 	struct dentry *parent;
 	struct key *key;
 	void *dir_version;
#1 lore raw
Quoted 12 lines · David Howells

From: Artem Bityutskiy <[email protected]>

Fix the following warning:

fs/afs/dir.c: In function 'afs_d_revalidate':
fs/afs/dir.c:567: warning: 'fid.vnode' may be used uninitialized in this function fs/afs/dir.c:567: warning: 'fid.unique' may be used uninitialized in this function

by marking the 'fid' variable as an uninitialized_var. The problem is that gcc doesn't always manage to work out that fid is always set on the path through the function that uses it.

Quoted 6 lines

---

Have you tried this approach :

fs/afs/dir.c +45 -42
index 9bd7577..09cb5bb 100644
@@ -607,53 +607,56 @@ static int afs_d_revalidate(struct dentry *dentry, struct nameidata *nd)
 
 	/* search the directory for this vnode */
 	ret = afs_do_lookup(&dir->vfs_inode, dentry, &fid, key);
-	switch (ret) {
-	case 0:
-		/* the filename maps to something */
-		if (!dentry->d_inode)
-			goto out_bad;
-		if (is_bad_inode(dentry->d_inode)) {
-			printk("kAFS: afs_d_revalidate: %s/%s has bad inode\n",
-			       parent->d_name.name, dentry->d_name.name);
+	if (ret < 0) {
+		switch (ret) {
+		case -ENOENT:
+			/* the filename is unknown */
+			_debug("%s: dirent not found", dentry->d_name.name);
+			if (dentry->d_inode)
+				goto not_found;
+			goto out_valid;
+
+		default:
+			_debug("failed to iterate dir %s: %d",
+			       parent->d_name.name, ret);
 			goto out_bad;
 		}
+	}
 
-		/* if the vnode ID has changed, then the dirent points to a
-		 * different file */
-		if (fid.vnode != vnode->fid.vnode) {
-			_debug("%s: dirent changed [%u != %u]",
-			       dentry->d_name.name, fid.vnode,
-			       vnode->fid.vnode);
-			goto not_found;
-		}
-
-		/* if the vnode ID uniqifier has changed, then the file has
-		 * been deleted and replaced, and the original vnode ID has
-		 * been reused */
-		if (fid.unique != vnode->fid.unique) {
-			_debug("%s: file deleted (uq %u -> %u I:%llu)",
-			       dentry->d_name.name, fid.unique,
-			       vnode->fid.unique,
-			       (unsigned long long)dentry->d_inode->i_version);
-			spin_lock(&vnode->lock);
-			set_bit(AFS_VNODE_DELETED, &vnode->flags);
-			spin_unlock(&vnode->lock);
-			goto not_found;
-		}
-		goto out_valid;
-
-	case -ENOENT:
-		/* the filename is unknown */
-		_debug("%s: dirent not found", dentry->d_name.name);
-		if (dentry->d_inode)
-			goto not_found;
-		goto out_valid;
-
-	default:
-		_debug("failed to iterate dir %s: %d",
-		       parent->d_name.name, ret);
+	/* the filename maps to something */
+	if (!dentry->d_inode)
 		goto out_bad;
+	if (is_bad_inode(dentry->d_inode)) {
+		printk("kAFS: afs_d_revalidate: %s/%s has bad inode\n",
+		       parent->d_name.name, dentry->d_name.name);
+		goto out_bad;
+	}
+
+	/*
+	 * if the vnode ID has changed, then the dirent points to a
+	 * different file
+	 */
+	if (fid.vnode != vnode->fid.vnode) {
+		_debug("%s: dirent changed [%u != %u]",
+		       dentry->d_name.name, fid.vnode, vnode->fid.vnode);
+		goto not_found;
+	}
+
+	/*
+	 * if the vnode ID uniqifier has changed, then the file has been
+	 * deleted and replaced, and the original vnode ID has been reused
+	 */
+	if (fid.unique != vnode->fid.unique) {
+		_debug("%s: file deleted (uq %u -> %u I:%llu)",
+		       dentry->d_name.name, fid.unique,
+		       vnode->fid.unique,
+		       (unsigned long long)dentry->d_inode->i_version);
+		spin_lock(&vnode->lock);
+		set_bit(AFS_VNODE_DELETED, &vnode->flags);
+		spin_unlock(&vnode->lock);
+		goto not_found;
 	}
+	goto out_valid;
 
 out_valid:
 	dentry->d_fsdata = dir_version;
Quoted 23 lines
 fs/afs/dir.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/afs/dir.c +1 -2
index 5272872..790ba9d 100644
@@ -566,7 +566,7 @@ static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry,
 static int afs_d_revalidate(struct dentry *dentry, struct nameidata *nd)
 {
 	struct afs_vnode *vnode, *dir;
-	struct afs_fid fid;
+	struct afs_fid uninitialized_var(fid);
 	struct dentry *parent;
 	struct key *key;
 	void *dir_version;
 
--

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#2 lore raw
Quoted 112 lines · Jaswinder Singh Rajput
Quoted 12 lines · David Howells

From: Artem Bityutskiy <[email protected]>

Fix the following warning:

fs/afs/dir.c: In function 'afs_d_revalidate':
fs/afs/dir.c:567: warning: 'fid.vnode' may be used uninitialized in this function fs/afs/dir.c:567: warning: 'fid.unique' may be used uninitialized in this function

by marking the 'fid' variable as an uninitialized_var. The problem is that gcc doesn't always manage to work out that fid is always set on the path through the function that uses it.

Quoted 6 lines

---

Have you tried this approach :

fs/afs/dir.c +36 -42
index 9bd7577..09cb5bb 100644
@@ -607,53 +607,56 @@ static int afs_d_revalidate(struct dentry *dentry, struct nameidata *nd)
 
 	/* search the directory for this vnode */
 	ret = afs_do_lookup(&dir->vfs_inode, dentry, &fid, key);
-	switch (ret) {
-	case 0:
-		/* the filename maps to something */
-		if (!dentry->d_inode)
-			goto out_bad;
-		if (is_bad_inode(dentry->d_inode)) {
-			printk("kAFS: afs_d_revalidate: %s/%s has bad inode\n",
-			       parent->d_name.name, dentry->d_name.name);
+	if (ret < 0) {
+		switch (ret) {
+		case -ENOENT:
+			/* the filename is unknown */
+			_debug("%s: dirent not found", dentry->d_name.name);
+			if (dentry->d_inode)
+				goto not_found;
+			goto out_valid;
+
+		default:
+			_debug("failed to iterate dir %s: %d",
+			       parent->d_name.name, ret);
 			goto out_bad;
 		}
+	}
 
-		/* if the vnode ID has changed, then the dirent points to a
-		 * different file */
-		if (fid.vnode != vnode->fid.vnode) {
-			_debug("%s: dirent changed [%u != %u]",
-			       dentry->d_name.name, fid.vnode,
-			       vnode->fid.vnode);
-			goto not_found;
-		}
-
-		/* if the vnode ID uniqifier has changed, then the file has
-		 * been deleted and replaced, and the original vnode ID has
-		 * been reused */
-		if (fid.unique != vnode->fid.unique) {
-			_debug("%s: file deleted (uq %u -> %u I:%llu)",
-			       dentry->d_name.name, fid.unique,
-			       vnode->fid.unique,
-			       (unsigned long long)dentry->d_inode->i_version);
-			spin_lock(&vnode->lock);
-			set_bit(AFS_VNODE_DELETED, &vnode->flags);
-			spin_unlock(&vnode->lock);
-			goto not_found;
-		}
-		goto out_valid;
-
-	case -ENOENT:
-		/* the filename is unknown */
-		_debug("%s: dirent not found", dentry->d_name.name);
-		if (dentry->d_inode)
-			goto not_found;
-		goto out_valid;
-
-	default:
-		_debug("failed to iterate dir %s: %d",
-		       parent->d_name.name, ret);
+	/* the filename maps to something */
+	if (!dentry->d_inode)
 		goto out_bad;
+	if (is_bad_inode(dentry->d_inode)) {
+		printk("kAFS: afs_d_revalidate: %s/%s has bad inode\n",
+		       parent->d_name.name, dentry->d_name.name);
+		goto out_bad;
+	}
+
+	/*
+	 * if the vnode ID has changed, then the dirent points to a
+	 * different file
+	 */
+	if (fid.vnode != vnode->fid.vnode) {
+		_debug("%s: dirent changed [%u != %u]",
+		       dentry->d_name.name, fid.vnode, vnode->fid.vnode);
+		goto not_found;
+	}
+
+	/*
+	 * if the vnode ID uniqifier has changed, then the file has been
+	 * deleted and replaced, and the original vnode ID has been reused
+	 */
+	if (fid.unique != vnode->fid.unique) {

fs/afs/dir.c static int afs_d_revalidate(struct dentry *dentry, struct nameidata *nd) · line 659

Quoted 10 lines
fs/afs/dir.c +9 -0
+		_debug("%s: file deleted (uq %u -> %u I:%llu)",
+		       dentry->d_name.name, fid.unique,
+		       vnode->fid.unique,
+		       (unsigned long long)dentry->d_inode->i_version);
+		spin_lock(&vnode->lock);
+		set_bit(AFS_VNODE_DELETED, &vnode->flags);
+		spin_unlock(&vnode->lock);
+		goto not_found;
 	}
+	goto out_valid;

You can also remove this goto. So by this way, you can get rid of :

1. compiler warning
2. fix 80 column wrap problem
3. remove one goto

Enjoy.
--
JSR

author maintainer
#3 lore raw
Quoted 1 line · Jaswinder Singh Rajput

2. fix 80 column wrap problem

I don't see an 80-column wrap problem that you've removed.

David

#4 lore raw
Quoted 6 lines · David Howells
Quoted 1 line · Jaswinder Singh Rajput

2. fix 80 column wrap problem

I don't see an 80-column wrap problem that you've removed.

ok here it is :

- if (fid.vnode != vnode->fid.vnode) {
- _debug("%s: dirent changed [%u != %u]",
- dentry->d_name.name, fid.vnode,
- vnode->fid.vnode);
- goto not_found;
- }

+ if (fid.vnode != vnode->fid.vnode) {
+ _debug("%s: dirent changed [%u != %u]",
+ dentry->d_name.name, fid.vnode, vnode->fid.vnode);
+ goto not_found;
+ }

- /* if the vnode ID uniqifier has changed, then the file has
- * been deleted and replaced, and the original vnode ID has
- * been reused */

+ /*

+        * if the vnode ID uniqifier has changed, then the file has been
+        * deleted and replaced, and the original vnode ID has been reused
+        */

--
JSR

author maintainer
#5 lore raw

fs/afs/dir.c static int afs_d_revalidate(struct dentry *dentry, struct nameidata *nd) · line 626

Quoted 9 lines · Jaswinder Singh Rajput
Quoted 2 lines

I don't see an 80-column wrap problem that you've removed.

ok here it is :

fs/afs/dir.c +0 -4
-               if (fid.vnode != vnode->fid.vnode) {
-                       _debug("%s: dirent changed [%u != %u]",
-                              dentry->d_name.name, fid.vnode,
-                              vnode->fid.vnode);

Ah, I see. I thought you meant there was a line of >80 chars that got fixed.

David

author maintainer
#6 lore raw
In reply to Jaswinder Singh Rajput

Hi Artem,

Can you try Jaswinder's patch? I don't see the warning even without your patch, so I can't test it.

David
---

fs/afs/dir.c +45 -42
index 9bd7577..09cb5bb 100644
@@ -607,53 +607,56 @@ static int afs_d_revalidate(struct dentry *dentry, struct nameidata *nd)
 
 	/* search the directory for this vnode */
 	ret = afs_do_lookup(&dir->vfs_inode, dentry, &fid, key);
-	switch (ret) {
-	case 0:
-		/* the filename maps to something */
-		if (!dentry->d_inode)
-			goto out_bad;
-		if (is_bad_inode(dentry->d_inode)) {
-			printk("kAFS: afs_d_revalidate: %s/%s has bad inode\n",
-			       parent->d_name.name, dentry->d_name.name);
+	if (ret < 0) {
+		switch (ret) {
+		case -ENOENT:
+			/* the filename is unknown */
+			_debug("%s: dirent not found", dentry->d_name.name);
+			if (dentry->d_inode)
+				goto not_found;
+			goto out_valid;
+
+		default:
+			_debug("failed to iterate dir %s: %d",
+			       parent->d_name.name, ret);
 			goto out_bad;
 		}
+	}
 
-		/* if the vnode ID has changed, then the dirent points to a
-		 * different file */
-		if (fid.vnode != vnode->fid.vnode) {
-			_debug("%s: dirent changed [%u != %u]",
-			       dentry->d_name.name, fid.vnode,
-			       vnode->fid.vnode);
-			goto not_found;
-		}
-
-		/* if the vnode ID uniqifier has changed, then the file has
-		 * been deleted and replaced, and the original vnode ID has
-		 * been reused */
-		if (fid.unique != vnode->fid.unique) {
-			_debug("%s: file deleted (uq %u -> %u I:%llu)",
-			       dentry->d_name.name, fid.unique,
-			       vnode->fid.unique,
-			       (unsigned long long)dentry->d_inode->i_version);
-			spin_lock(&vnode->lock);
-			set_bit(AFS_VNODE_DELETED, &vnode->flags);
-			spin_unlock(&vnode->lock);
-			goto not_found;
-		}
-		goto out_valid;
-
-	case -ENOENT:
-		/* the filename is unknown */
-		_debug("%s: dirent not found", dentry->d_name.name);
-		if (dentry->d_inode)
-			goto not_found;
-		goto out_valid;
-
-	default:
-		_debug("failed to iterate dir %s: %d",
-		       parent->d_name.name, ret);
+	/* the filename maps to something */
+	if (!dentry->d_inode)
 		goto out_bad;
+	if (is_bad_inode(dentry->d_inode)) {
+		printk("kAFS: afs_d_revalidate: %s/%s has bad inode\n",
+		       parent->d_name.name, dentry->d_name.name);
+		goto out_bad;
+	}
+
+	/*
+	 * if the vnode ID has changed, then the dirent points to a
+	 * different file
+	 */
+	if (fid.vnode != vnode->fid.vnode) {
+		_debug("%s: dirent changed [%u != %u]",
+		       dentry->d_name.name, fid.vnode, vnode->fid.vnode);
+		goto not_found;
+	}
+
+	/*
+	 * if the vnode ID uniqifier has changed, then the file has been
+	 * deleted and replaced, and the original vnode ID has been reused
+	 */
+	if (fid.unique != vnode->fid.unique) {
+		_debug("%s: file deleted (uq %u -> %u I:%llu)",
+		       dentry->d_name.name, fid.unique,
+		       vnode->fid.unique,
+		       (unsigned long long)dentry->d_inode->i_version);
+		spin_lock(&vnode->lock);
+		set_bit(AFS_VNODE_DELETED, &vnode->flags);
+		spin_unlock(&vnode->lock);
+		goto not_found;
 	}
+	goto out_valid;
 
 out_valid:
 	dentry->d_fsdata = dir_version;
#7 lore raw

Hi,

Quoted 2 lines · David Howells

Can you try Jaswinder's patch? I don't see the warning even without your patch, so I can't test it.

Linus has already applied my patch which you sent him:

commit dd0d9a46f573b086a67522f819566427dba9c4c7

Author: Artem Bityutskiy <[email protected]>
Date:   Thu Jul 9 10:44:30 2009 +0100

AFS: Fix compilation warning

But this patch applies to both current linux-2.6.git and to pre-"AFS: Fix compilation warning" tree.

I've compile-tested the latter and yes, this patch fixes the warning.

FWIW, if you want to apply this patch, then you probably should first revert my patch, or make this patch undo my "unitinialized_var" changes. And probably this stuff is anyway not 2.6.31 material, because the warning is fixed anyway :-) Anyway, not my area :-)

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
author maintainer
#8 lore raw
Quoted 5 lines · Artem Bityutskiy

FWIW, if you want to apply this patch, then you probably should first revert my patch, or make this patch undo my "unitinialized_var" changes. And probably this stuff is anyway not 2.6.31 material, because the warning is fixed anyway :-) Anyway, not my area :-)

Thanks for testing it. I'll keep it on ice till 2.6.31.

David