mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-05-16 07:51:31 -04:00
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>
This commit is contained in:
18
fs/xattr.c
18
fs/xattr.c
@@ -152,12 +152,20 @@ xattr_permission(struct mnt_idmap *idmap, struct inode *inode,
|
||||
* privileged users can write attributes.
|
||||
*/
|
||||
if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
|
||||
if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode))
|
||||
return xattr_permission_error(mask);
|
||||
if (S_ISDIR(inode->i_mode) && (inode->i_mode & S_ISVTX) &&
|
||||
(mask & MAY_WRITE) &&
|
||||
!inode_owner_or_capable(idmap, inode))
|
||||
switch (inode->i_mode & S_IFMT) {
|
||||
case S_IFREG:
|
||||
break;
|
||||
case S_IFDIR:
|
||||
if (!(inode->i_mode & S_ISVTX))
|
||||
break;
|
||||
if (!(mask & MAY_WRITE))
|
||||
break;
|
||||
if (inode_owner_or_capable(idmap, inode))
|
||||
break;
|
||||
return -EPERM;
|
||||
default:
|
||||
return xattr_permission_error(mask);
|
||||
}
|
||||
}
|
||||
|
||||
return inode_permission(idmap, inode, mask);
|
||||
|
||||
Reference in New Issue
Block a user