Audit system development
 help / color / mirror / Atom feed
* [PATCH] audit: Use kzalloc instead of kmalloc/memset
@ 2025-11-05 10:36 Gongwei Li
  2025-11-07 21:38 ` Paul Moore
  0 siblings, 1 reply; 2+ messages in thread
From: Gongwei Li @ 2025-11-05 10:36 UTC (permalink / raw)
  To: audit; +Cc: paul, eparis, Gongwei Li

From: Gongwei Li <ligongwei@kylinos.cn>

Replace kmalloc+memset by kzalloc
for better readability and simplicity.

This addresses the warning below:

WARNING: kzalloc should be used for data, instead of kmalloc/memset

Signed-off-by: Gongwei Li <ligongwei@kylinos.cn>
---
 kernel/auditfilter.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c
index f7708fe2c..db014d724 100644
--- a/kernel/auditfilter.c
+++ b/kernel/auditfilter.c
@@ -638,10 +638,9 @@ static struct audit_rule_data *audit_krule_to_data(struct audit_krule *krule)
 	void *bufp;
 	int i;
 
-	data = kmalloc(struct_size(data, buf, krule->buflen), GFP_KERNEL);
+	data = kzalloc(struct_size(data, buf, krule->buflen), GFP_KERNEL);
 	if (unlikely(!data))
 		return NULL;
-	memset(data, 0, sizeof(*data));
 
 	data->flags = krule->flags | krule->listnr;
 	data->action = krule->action;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] audit: Use kzalloc instead of kmalloc/memset
  2025-11-05 10:36 [PATCH] audit: Use kzalloc instead of kmalloc/memset Gongwei Li
@ 2025-11-07 21:38 ` Paul Moore
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Moore @ 2025-11-07 21:38 UTC (permalink / raw)
  To: Gongwei Li, audit; +Cc: eparis, Gongwei Li

On Nov  5, 2025 Gongwei Li <13875017792@163.com> wrote:
> 
> Replace kmalloc+memset by kzalloc
> for better readability and simplicity.
> 
> This addresses the warning below:
> 
> WARNING: kzalloc should be used for data, instead of kmalloc/memset
> 
> Signed-off-by: Gongwei Li <ligongwei@kylinos.cn>
> ---
>  kernel/auditfilter.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)

This change does result in zero'ing out the trailing string buffer,
which isn't done currently, and shouldn't be necessary, but as this bit
of code isn't performance critical, it should be okay.

Merged into audit/dev, thanks.

--
paul-moore.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-11-07 21:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-05 10:36 [PATCH] audit: Use kzalloc instead of kmalloc/memset Gongwei Li
2025-11-07 21:38 ` Paul Moore

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox