Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

autofs: improve ioctl sbi checks

Al Viro made some suggestions to improve the implementation of commit
0633da48f0 ("fix autofs_sbi() does not check super block type").

The check is unnecessary in all cases except for ioctl usage so placing
the check in the super block accessor function adds a small overhead to
the common case where it isn't needed.

So it's sufficient to do this in the ioctl code only.

Also the check in the ioctl code is needlessly complex.

[akpm@linux-foundation.org: declare autofs_fs_type in .h, not .c]
Link: http://lkml.kernel.org/r/154296970987.9889.1597442413573683096.stgit@pluto-themaw-net
Signed-off-by: Ian Kent <raven@themaw.net>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Ian Kent and committed by
Linus Torvalds
55f0d820 7c8f7193

+9 -21
+3 -2
fs/autofs/autofs_i.h
··· 42 42 #endif 43 43 #define pr_fmt(fmt) KBUILD_MODNAME ":pid:%d:%s: " fmt, current->pid, __func__ 44 44 45 + extern struct file_system_type autofs_fs_type; 46 + 45 47 /* 46 48 * Unified info structure. This is pointed to by both the dentry and 47 49 * inode structures. Each file in the filesystem has an instance of this ··· 128 126 129 127 static inline struct autofs_sb_info *autofs_sbi(struct super_block *sb) 130 128 { 131 - return sb->s_magic != AUTOFS_SUPER_MAGIC ? 132 - NULL : (struct autofs_sb_info *)(sb->s_fs_info); 129 + return (struct autofs_sb_info *)(sb->s_fs_info); 133 130 } 134 131 135 132 static inline struct autofs_info *autofs_dentry_ino(struct dentry *dentry)
+5 -18
fs/autofs/dev-ioctl.c
··· 151 151 return err; 152 152 } 153 153 154 - /* 155 - * Get the autofs super block info struct from the file opened on 156 - * the autofs mount point. 157 - */ 158 - static struct autofs_sb_info *autofs_dev_ioctl_sbi(struct file *f) 159 - { 160 - struct autofs_sb_info *sbi = NULL; 161 - struct inode *inode; 162 - 163 - if (f) { 164 - inode = file_inode(f); 165 - sbi = autofs_sbi(inode->i_sb); 166 - } 167 - return sbi; 168 - } 169 - 170 154 /* Return autofs dev ioctl version */ 171 155 static int autofs_dev_ioctl_version(struct file *fp, 172 156 struct autofs_sb_info *sbi, ··· 642 658 if (cmd != AUTOFS_DEV_IOCTL_VERSION_CMD && 643 659 cmd != AUTOFS_DEV_IOCTL_OPENMOUNT_CMD && 644 660 cmd != AUTOFS_DEV_IOCTL_CLOSEMOUNT_CMD) { 661 + struct super_block *sb; 662 + 645 663 fp = fget(param->ioctlfd); 646 664 if (!fp) { 647 665 if (cmd == AUTOFS_DEV_IOCTL_ISMOUNTPOINT_CMD) ··· 652 666 goto out; 653 667 } 654 668 655 - sbi = autofs_dev_ioctl_sbi(fp); 656 - if (!sbi || sbi->magic != AUTOFS_SBI_MAGIC) { 669 + sb = file_inode(fp)->i_sb; 670 + if (sb->s_type != &autofs_fs_type) { 657 671 err = -EINVAL; 658 672 fput(fp); 659 673 goto out; 660 674 } 675 + sbi = autofs_sbi(sb); 661 676 662 677 /* 663 678 * Admin needs to be able to set the mount catatonic in
+1 -1
fs/autofs/init.c
··· 16 16 return mount_nodev(fs_type, flags, data, autofs_fill_super); 17 17 } 18 18 19 - static struct file_system_type autofs_fs_type = { 19 + struct file_system_type autofs_fs_type = { 20 20 .owner = THIS_MODULE, 21 21 .name = "autofs", 22 22 .mount = autofs_mount,