Skip to contentSkip to conversation

fs/anon_inodes.c: Remove unnecessary IS_ERR(anon_inode_inode)

PATCH In review Eric Biggers 3 participants 7 messages Oct 12, 2014 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 fs/anon_inodes.c: Remove unnecessary IS_ERR(anon_inode_inode)

anon_inode_inode is allocated by anon_inode_init(), which is fs_initcall and will panic if it couldn't be allocated.

---
 fs/anon_inodes.c | 3 ---
 1 file changed, 3 deletions(-)
fs/anon_inodes.c +0 -3
index 80ef38c..1faff09 100644
@@ -75,9 +75,6 @@ struct file *anon_inode_getfile(const char *name,
 	struct path path;
 	struct file *file;
 
-	if (IS_ERR(anon_inode_inode))
-		return ERR_PTR(-ENODEV);
-
 	if (fops->owner && !try_module_get(fops->owner))
 		return ERR_PTR(-ENOENT);
 
Signature · 1 line
2.1.2
#1 lore raw

PATCH 2/5 fs/anon_inodes.c: Simplify control flow in anon_inode_getfd()

---
 fs/anon_inodes.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
fs/anon_inodes.c +6 -12
index 1faff09..268153a 100644
@@ -136,26 +136,20 @@ EXPORT_SYMBOL_GPL(anon_inode_getfile);
 int anon_inode_getfd(const char *name, const struct file_operations *fops,
 		     void *priv, int flags)
 {
-	int error, fd;
+	int fd;
 	struct file *file;
 
-	error = get_unused_fd_flags(flags);
-	if (error < 0)
-		return error;
-	fd = error;
+	fd = get_unused_fd_flags(flags);
+	if (fd < 0)
+		return fd;
 
 	file = anon_inode_getfile(name, fops, priv, flags);
 	if (IS_ERR(file)) {
-		error = PTR_ERR(file);
-		goto err_put_unused_fd;
+		put_unused_fd(fd);
+		return PTR_ERR(file);
 	}
 	fd_install(fd, file);
-
 	return fd;
-
-err_put_unused_fd:
-	put_unused_fd(fd);
-	return error;
 }
 EXPORT_SYMBOL_GPL(anon_inode_getfd);
 
Signature · 1 line
2.1.2
maintainer
#2 lore raw

Re: [PATCH 2/5] fs/anon_inodes.c: Simplify control flow in anon_inode_getfd()

fs/anon_inodes.c EXPORT_SYMBOL_GPL(anon_inode_getfile); · line 151

Quoted 8 lines · Eric Biggers
fs/anon_inodes.c +2 -2
 	file = anon_inode_getfile(name, fops, priv, flags);
 	if (IS_ERR(file)) {
-		error = PTR_ERR(file);
-		goto err_put_unused_fd;
+		put_unused_fd(fd);
+		return PTR_ERR(file);
 	}
 	fd_install(fd, file);

at least slap unlikely() on that if (IS_ERR(...))...

#3 lore raw

Re: [PATCH 2/5] fs/anon_inodes.c: Simplify control flow in anon_inode_getfd()

Quoted 11 lines · Al Viro

fs/anon_inodes.c EXPORT_SYMBOL_GPL(anon_inode_getfile); · line 151

Quoted 8 lines · Eric Biggers
fs/anon_inodes.c +2 -2
 	file = anon_inode_getfile(name, fops, priv, flags);
 	if (IS_ERR(file)) {
-		error = PTR_ERR(file);
-		goto err_put_unused_fd;
+		put_unused_fd(fd);
+		return PTR_ERR(file);
 	}
 	fd_install(fd, file);

at least slap unlikely() on that if (IS_ERR(...))...

That shouldn't be necessary, as far as I can tell; linux/err.h has:

#define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
...
static inline bool __must_check IS_ERR(__force const void *ptr)

{
	return IS_ERR_VALUE((unsigned long)ptr);
}

So unless GCC fails to propagate expected-value handling through static inline functions, you should never need to write unlikely(IS_ERR(...)).

- Josh Triplett

#4 lore raw

PATCH 3/5 fs/anon_inodes.c: Mark anon_inode_inode __read_mostly

In reply to Eric Biggers

At least, for consistency with anon_inode_mnt.

---
 fs/anon_inodes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/anon_inodes.c +1 -1
index 268153a..444a705 100644
@@ -23,7 +23,7 @@
 #include <asm/uaccess.h>
 
 static struct vfsmount *anon_inode_mnt __read_mostly;
-static struct inode *anon_inode_inode;
+static struct inode *anon_inode_inode __read_mostly;
 
 /*
  * anon_inodefs_dname() is called from d_path().
Signature · 1 line
2.1.2
#5 lore raw

PATCH 4/5 fs/anon_inodes.c: Remove unneeded #includes

In reply to Eric Biggers
---
 fs/anon_inodes.c | 5 -----
 1 file changed, 5 deletions(-)
fs/anon_inodes.c +0 -5
index 444a705..bbfa038 100644
@@ -8,10 +8,7 @@
  *
  */
 
-#include <linux/cred.h>
 #include <linux/file.h>
-#include <linux/poll.h>
-#include <linux/sched.h>
 #include <linux/init.h>
 #include <linux/fs.h>
 #include <linux/mount.h>
@@ -20,8 +17,6 @@
 #include <linux/magic.h>
 #include <linux/anon_inodes.h>
 
-#include <asm/uaccess.h>
-
 static struct vfsmount *anon_inode_mnt __read_mostly;
 static struct inode *anon_inode_inode __read_mostly;
 
Signature · 1 line
2.1.2
#6 lore raw

PATCH 5/5 fs/anon_inodes.c: Remove incorrect information in comment

In reply to Eric Biggers

Dentries for the anonymous inode are *not* named based on the inode sequence number.

---
 fs/anon_inodes.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
fs/anon_inodes.c +1 -4
index bbfa038..ee81409 100644
@@ -73,10 +73,7 @@ struct file *anon_inode_getfile(const char *name,
 	if (fops->owner && !try_module_get(fops->owner))
 		return ERR_PTR(-ENOENT);
 
-	/*
-	 * Link the inode to a directory entry by creating a unique name
-	 * using the inode sequence number.
-	 */
+	/* Create a dentry for the new file.  */
 	file = ERR_PTR(-ENOMEM);
 	this.name = name;
 	this.len = strlen(name);
Signature · 1 line
2.1.2