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: add xattr_permission_error()

Stop repeating the ?: in multiple places and use a simple helper for
this.

Link: https://patch.msgid.link/20260216-work-xattr-socket-v1-7-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>

+9 -2
+9 -2
fs/xattr.c
··· 106 106 return 0; 107 107 } 108 108 109 + static inline int xattr_permission_error(int mask) 110 + { 111 + if (mask & MAY_WRITE) 112 + return -EPERM; 113 + return -ENODATA; 114 + } 115 + 109 116 /* 110 117 * Check permissions for extended attribute access. This is a bit complicated 111 118 * because different namespaces have very different rules. ··· 142 135 */ 143 136 if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) { 144 137 if (!capable(CAP_SYS_ADMIN)) 145 - return (mask & MAY_WRITE) ? -EPERM : -ENODATA; 138 + return xattr_permission_error(mask); 146 139 return 0; 147 140 } 148 141 ··· 153 146 */ 154 147 if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) { 155 148 if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode)) 156 - return (mask & MAY_WRITE) ? -EPERM : -ENODATA; 149 + return xattr_permission_error(mask); 157 150 if (S_ISDIR(inode->i_mode) && (inode->i_mode & S_ISVTX) && 158 151 (mask & MAY_WRITE) && 159 152 !inode_owner_or_capable(idmap, inode))