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

apparmor: fix sparse warnings

Fix a couple of warning reported by sparse

Signed-off-by: John Johansen <john.johansen@canonical.com>

+11 -11
+7 -7
security/apparmor/include/file.h
··· 186 186 aa_free_domain_entries(&rules->trans); 187 187 } 188 188 189 - #define ACC_FMODE(x) (("\000\004\002\006"[(x)&O_ACCMODE]) | (((x) << 1) & 0x40)) 190 - 191 - /* from namei.c */ 192 - #define MAP_OPEN_FLAGS(x) ((((x) + 1) & O_ACCMODE) ? (x) + 1 : (x)) 193 - 194 189 /** 195 190 * aa_map_file_perms - map file flags to AppArmor permissions 196 191 * @file: open file to map flags to AppArmor permissions ··· 194 199 */ 195 200 static inline u32 aa_map_file_to_perms(struct file *file) 196 201 { 197 - int flags = MAP_OPEN_FLAGS(file->f_flags); 198 - u32 perms = ACC_FMODE(file->f_mode); 202 + int flags = file->f_flags; 203 + u32 perms = 0; 204 + 205 + if (file->f_mode & FMODE_WRITE) 206 + perms |= MAY_WRITE; 207 + if (file->f_mode & FMODE_READ) 208 + perms |= MAY_READ; 199 209 200 210 if ((flags & O_APPEND) && (perms & MAY_WRITE)) 201 211 perms = (perms & ~MAY_WRITE) | MAY_APPEND;
+4 -4
security/apparmor/lsm.c
··· 909 909 910 910 error = register_security(&apparmor_ops); 911 911 if (error) { 912 + struct cred *cred = (struct cred *)current->real_cred; 913 + aa_free_task_context(cred->security); 914 + cred->security = NULL; 912 915 AA_ERROR("Unable to register AppArmor\n"); 913 - goto set_init_cxt_out; 916 + goto register_security_out; 914 917 } 915 918 916 919 /* Report that AppArmor successfully initialized */ ··· 926 923 aa_info_message("AppArmor initialized"); 927 924 928 925 return error; 929 - 930 - set_init_cxt_out: 931 - aa_free_task_context(current->real_cred->security); 932 926 933 927 register_security_out: 934 928 aa_free_root_ns();