[PATCH 1/2] audit: Quit audit_free_names() early if name list empty
From: Waiman Long
Date: Tue Jan 20 2026 - 21:36:19 EST
Optimize audit_free_names() by quitting early if the name list is empty.
This eliminates the need to acquire and release the fs_struct spinlock
in path_put().
Signed-off-by: Waiman Long <longman@xxxxxxxxxx>
---
kernel/auditsc.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/kernel/auditsc.c b/kernel/auditsc.c
index dd0563a8e0be..824b6fd98561 100644
--- a/kernel/auditsc.c
+++ b/kernel/auditsc.c
@@ -931,6 +931,9 @@ static inline void audit_free_names(struct audit_context *context)
{
struct audit_names *n, *next;
+ if (list_empty(&context->names_list))
+ return; /* audit_alloc_name() has not been called */
+
list_for_each_entry_safe(n, next, &context->names_list, list) {
list_del(&n->list);
if (n->name)
--
2.52.0