2023-06-21 10:28:01

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 0/6] tty_audit: random cleanups

These are random clean up patches which I came up with while doing more
invasive cleanup over the tty layer (to be sent later).

Jiri Slaby (SUSE) (6):
tty_audit: use TASK_COMM_LEN for task comm
tty_audit: use kzalloc() in tty_audit_buf_alloc()
tty_audit: invert the condition in tty_audit_log()
tty_audit: make icanon a bool
tty_audit: make tty pointers in exposed functions const
tty_audit: make data of tty_audit_log() const

drivers/tty/tty.h | 11 ++++++-----
drivers/tty/tty_audit.c | 43 +++++++++++++++++++++--------------------
2 files changed, 28 insertions(+), 26 deletions(-)

--
2.41.0



2023-06-21 10:29:30

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 6/6] tty_audit: make data of tty_audit_log() const

'data' are only read (passed down to audit_log_n_hex()), so they can be
const -- the same what is expected in audit_log_n_hex(). Only a minor
cleanup to be consistent.

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
---
drivers/tty/tty_audit.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/tty_audit.c b/drivers/tty/tty_audit.c
index 5cbe28ac1763..24d010589379 100644
--- a/drivers/tty/tty_audit.c
+++ b/drivers/tty/tty_audit.c
@@ -59,7 +59,7 @@ static void tty_audit_buf_free(struct tty_audit_buf *buf)
}

static void tty_audit_log(const char *description, dev_t dev,
- unsigned char *data, size_t size)
+ const unsigned char *data, size_t size)
{
struct audit_buffer *ab;
pid_t pid = task_pid_nr(current);
--
2.41.0


2023-06-21 10:29:45

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 2/6] tty_audit: use kzalloc() in tty_audit_buf_alloc()

tty_audit_buf_alloc() manually erases most of the entries after
kmalloc(). So use kzalloc() and remove the manual sets to zero.

That way, we are sure that we do not omit anything.

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
---
drivers/tty/tty_audit.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/tty_audit.c b/drivers/tty/tty_audit.c
index b98b1aef5f6f..43f34465b9df 100644
--- a/drivers/tty/tty_audit.c
+++ b/drivers/tty/tty_audit.c
@@ -33,16 +33,16 @@ static struct tty_audit_buf *tty_audit_buf_alloc(void)
{
struct tty_audit_buf *buf;

- buf = kmalloc(sizeof(*buf), GFP_KERNEL);
+ buf = kzalloc(sizeof(*buf), GFP_KERNEL);
if (!buf)
goto err;
+
buf->data = kmalloc(N_TTY_BUF_SIZE, GFP_KERNEL);
if (!buf->data)
goto err_buf;
+
mutex_init(&buf->mutex);
- buf->dev = MKDEV(0, 0);
- buf->icanon = 0;
- buf->valid = 0;
+
return buf;

err_buf:
--
2.41.0