Skip to contentSkip to conversation

tomoyo: replace tomoyo_round2() with kmalloc_size_roundup()

PATCH In review Vlastimil Babka 2 participants 2 messages Feb 28, 2023 – Mar 1, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tomoyo: replace tomoyo_round2() with kmalloc_size_roundup()

It seems tomoyo has had its own implementation of what kmalloc_size_roundup() does today. Remove the function tomoyo_round2() and replace it with kmalloc_size_roundup(). It provides more accurate results and doesn't contain a while loop.

---
 security/tomoyo/audit.c  |  6 +++---
 security/tomoyo/common.c |  2 +-
 security/tomoyo/common.h | 44 ----------------------------------------
 3 files changed, 4 insertions(+), 48 deletions(-)
security/tomoyo/audit.c +3 -3
index 7cf8fdbb29bf..610c1536cf70 100644
@@ -271,7 +271,7 @@ char *tomoyo_init_log(struct tomoyo_request_info *r, int len, const char *fmt,
 		/* +18 is for " symlink.target=\"%s\"" */
 		len += 18 + strlen(symlink);
 	}
-	len = tomoyo_round2(len);
+	len = kmalloc_size_roundup(len);
 	buf = kzalloc(len, GFP_NOFS);
 	if (!buf)
 		goto out;
@@ -382,12 +382,12 @@ void tomoyo_write_log2(struct tomoyo_request_info *r, int len, const char *fmt,
 		goto out;
 	}
 	entry->log = buf;
-	len = tomoyo_round2(strlen(buf) + 1);
+	len = kmalloc_size_roundup(strlen(buf) + 1);
 	/*
 	 * The entry->size is used for memory quota checks.
 	 * Don't go beyond strlen(entry->log).
 	 */
-	entry->size = len + tomoyo_round2(sizeof(*entry));
+	entry->size = len + kmalloc_size_roundup(sizeof(*entry));
 	spin_lock(&tomoyo_log_lock);
 	if (tomoyo_memory_quota[TOMOYO_MEMORY_AUDIT] &&
 	    tomoyo_memory_used[TOMOYO_MEMORY_AUDIT] + entry->size >=
security/tomoyo/common.c +1 -1
index f4cd9b58b205..969d4aa6fd55 100644
@@ -2094,7 +2094,7 @@ int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...)
 		tomoyo_add_entry(r->domain, entry.query);
 		goto out;
 	}
-	len = tomoyo_round2(entry.query_len);
+	len = kmalloc_size_roundup(entry.query_len);
 	entry.domain = r->domain;
 	spin_lock(&tomoyo_query_list_lock);
 	if (tomoyo_memory_quota[TOMOYO_MEMORY_QUERY] &&
security/tomoyo/common.h +0 -44

50 lines not on this page · raw message

Signature · 1 line
2.39.2
maintainer
#1 lore raw
Quoted 5 lines · Vlastimil Babka

It seems tomoyo has had its own implementation of what kmalloc_size_roundup() does today. Remove the function tomoyo_round2() and replace it with kmalloc_size_roundup(). It provides more accurate results and doesn't contain a while loop.

Quoted 7 lines
---
 security/tomoyo/audit.c  |  6 +++---
 security/tomoyo/common.c |  2 +-
 security/tomoyo/common.h | 44 ----------------------------------------
 3 files changed, 4 insertions(+), 48 deletions(-)

Applied as https://osdn.net/projects/tomoyo/scm/git/tomoyo-test1/commits/c120c98486c2 .

Thank you.