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.

xattr: switch xattr_permission() to switch statement

Simplify the codeflow by using a switch statement that switches on
S_IFMT.

Link: https://patch.msgid.link/20260216-work-xattr-socket-v1-8-c2efa4f74cb7@kernel.org
Acked-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Christian Brauner <brauner@kernel.org>

+13 -5
+13 -5
fs/xattr.c
··· 152 152 * privileged users can write attributes. 153 153 */ 154 154 if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) { 155 - if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode)) 156 - return xattr_permission_error(mask); 157 - if (S_ISDIR(inode->i_mode) && (inode->i_mode & S_ISVTX) && 158 - (mask & MAY_WRITE) && 159 - !inode_owner_or_capable(idmap, inode)) 155 + switch (inode->i_mode & S_IFMT) { 156 + case S_IFREG: 157 + break; 158 + case S_IFDIR: 159 + if (!(inode->i_mode & S_ISVTX)) 160 + break; 161 + if (!(mask & MAY_WRITE)) 162 + break; 163 + if (inode_owner_or_capable(idmap, inode)) 164 + break; 160 165 return -EPERM; 166 + default: 167 + return xattr_permission_error(mask); 168 + } 161 169 } 162 170 163 171 return inode_permission(idmap, inode, mask);