Skip to content

Commit 94f9481

Browse files
Jiri Slabygregkh
authored andcommitted
tty_audit: invert the condition in tty_audit_log()
If we cannot obtain an audit buffer in tty_audit_log(), simply return from the function. Apart this is mostly preferred in the kernel, it allows to merge the split audit string while still keeping it readable. Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org> Link: https://lore.kernel.org/r/20230621101611.10580-4-jirislaby@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e148851 commit 94f9481

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

drivers/tty/tty_audit.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,20 @@ static void tty_audit_log(const char *description, dev_t dev,
6666
uid_t uid = from_kuid(&init_user_ns, task_uid(current));
6767
uid_t loginuid = from_kuid(&init_user_ns, audit_get_loginuid(current));
6868
unsigned int sessionid = audit_get_sessionid(current);
69+
char name[TASK_COMM_LEN];
6970

7071
ab = audit_log_start(audit_context(), GFP_KERNEL, AUDIT_TTY);
71-
if (ab) {
72-
char name[TASK_COMM_LEN];
73-
74-
audit_log_format(ab, "%s pid=%u uid=%u auid=%u ses=%u major=%d"
75-
" minor=%d comm=", description, pid, uid,
76-
loginuid, sessionid, MAJOR(dev), MINOR(dev));
77-
get_task_comm(name, current);
78-
audit_log_untrustedstring(ab, name);
79-
audit_log_format(ab, " data=");
80-
audit_log_n_hex(ab, data, size);
81-
audit_log_end(ab);
82-
}
72+
if (!ab)
73+
return;
74+
75+
audit_log_format(ab, "%s pid=%u uid=%u auid=%u ses=%u major=%d minor=%d comm=",
76+
description, pid, uid, loginuid, sessionid,
77+
MAJOR(dev), MINOR(dev));
78+
get_task_comm(name, current);
79+
audit_log_untrustedstring(ab, name);
80+
audit_log_format(ab, " data=");
81+
audit_log_n_hex(ab, data, size);
82+
audit_log_end(ab);
8383
}
8484

8585
/*

0 commit comments

Comments
 (0)