Skip to content

Commit 53fe8b9

Browse files
committed
apparmor: fix sparse warnings
Fix a couple of warning reported by sparse Signed-off-by: John Johansen <john.johansen@canonical.com>
1 parent 41d1b3e commit 53fe8b9

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

‎security/apparmor/include/file.h‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,6 @@ static inline void aa_free_file_rules(struct aa_file_rules *rules)
186186
aa_free_domain_entries(&rules->trans);
187187
}
188188

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-
194189
/**
195190
* aa_map_file_perms - map file flags to AppArmor permissions
196191
* @file: open file to map flags to AppArmor permissions
@@ -199,8 +194,13 @@ static inline void aa_free_file_rules(struct aa_file_rules *rules)
199194
*/
200195
static inline u32 aa_map_file_to_perms(struct file *file)
201196
{
202-
int flags = MAP_OPEN_FLAGS(file->f_flags);
203-
u32 perms = ACC_FMODE(file->f_mode);
197+
int flags = file->f_flags;
198+
u32 perms = 0;
199+
200+
if (file->f_mode & FMODE_WRITE)
201+
perms |= MAY_WRITE;
202+
if (file->f_mode & FMODE_READ)
203+
perms |= MAY_READ;
204204

205205
if ((flags & O_APPEND) && (perms & MAY_WRITE))
206206
perms = (perms & ~MAY_WRITE) | MAY_APPEND;

‎security/apparmor/lsm.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -909,8 +909,11 @@ static int __init apparmor_init(void)
909909

910910
error = register_security(&apparmor_ops);
911911
if (error) {
912+
struct cred *cred = (struct cred *)current->real_cred;
913+
aa_free_task_context(cred->security);
914+
cred->security = NULL;
912915
AA_ERROR("Unable to register AppArmor\n");
913-
goto set_init_cxt_out;
916+
goto register_security_out;
914917
}
915918

916919
/* Report that AppArmor successfully initialized */
@@ -924,9 +927,6 @@ static int __init apparmor_init(void)
924927

925928
return error;
926929

927-
set_init_cxt_out:
928-
aa_free_task_context(current->real_cred->security);
929-
930930
register_security_out:
931931
aa_free_root_ns();
932932

0 commit comments

Comments
 (0)