fs/inode.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
Similar to may_open().
No functional changes.
Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
---
fs/inode.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/fs/inode.c b/fs/inode.c
index 01ebdc40021e..8c520a22afba 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -2519,21 +2519,28 @@ void __init inode_init(void)
void init_special_inode(struct inode *inode, umode_t mode, dev_t rdev)
{
inode->i_mode = mode;
- if (S_ISCHR(mode)) {
+ switch (inode->i_mode & S_IFMT) {
+ case S_IFCHR:
inode->i_fop = &def_chr_fops;
inode->i_rdev = rdev;
- } else if (S_ISBLK(mode)) {
+ break;
+ case S_IFBLK:
if (IS_ENABLED(CONFIG_BLOCK))
inode->i_fop = &def_blk_fops;
inode->i_rdev = rdev;
- } else if (S_ISFIFO(mode))
+ break;
+ case S_IFIFO:
inode->i_fop = &pipefifo_fops;
- else if (S_ISSOCK(mode))
- ; /* leave it no_open_fops */
- else
+ break;
+ case S_IFSOCK:
+ /* leave it no_open_fops */
+ break;
+ default:
printk(KERN_DEBUG "init_special_inode: bogus i_mode (%o) for"
" inode %s:%lu\n", mode, inode->i_sb->s_id,
inode->i_ino);
+ break;
+ }
}
EXPORT_SYMBOL(init_special_inode);
--
2.43.0
On Tue, 09 Sep 2025 09:54:58 +0200, Mateusz Guzik wrote: > Similar to may_open(). > > No functional changes. > > Applied to the vfs-6.18.misc branch of the vfs/vfs.git tree. Patches in the vfs-6.18.misc branch should appear in linux-next soon. Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it. It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated. Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch. tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs-6.18.misc [1/1] fs: use the switch statement in init_special_inode() https://git.kernel.org/vfs/vfs/c/4635c2c8bd5c
On Tue 09-09-25 09:54:58, Mateusz Guzik wrote: > Similar to may_open(). > > No functional changes. > > Signed-off-by: Mateusz Guzik <mjguzik@gmail.com> Looks sane. Just one style nit below. Feel free to add: Reviewed-by: Jan Kara <jack@suse.cz> > - else if (S_ISSOCK(mode)) > - ; /* leave it no_open_fops */ > - else > + break; > + case S_IFSOCK: > + /* leave it no_open_fops */ > + break; > + default: > printk(KERN_DEBUG "init_special_inode: bogus i_mode (%o) for" > " inode %s:%lu\n", mode, inode->i_sb->s_id, > inode->i_ino); > + break; We usually don't bother with 'break' for the 'default' label. Honza -- Jan Kara <jack@suse.com> SUSE Labs, CR
© 2016 - 2025 Red Hat, Inc.