* [PATCH] eventfs: Use kcalloc() instead of kzalloc()
@ 2024-01-14 10:53 Erick Archer
2024-01-15 10:06 ` Mark Rutland
0 siblings, 1 reply; 2+ messages in thread
From: Erick Archer @ 2024-01-14 10:53 UTC (permalink / raw)
To: Steven Rostedt, Masami Hiramatsu, Gustavo A. R. Silva
Cc: Erick Archer, Mathieu Desnoyers, linux-kernel, linux-trace-kernel,
linux-hardening
Use 2-factor multiplication argument form kcalloc() instead
of kzalloc().
Link: https://github.com/KSPP/linux/issues/162
Signed-off-by: Erick Archer <erick.archer@gmx.com>
---
fs/tracefs/event_inode.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c
index fdff53d5a1f8..f8196289692c 100644
--- a/fs/tracefs/event_inode.c
+++ b/fs/tracefs/event_inode.c
@@ -93,7 +93,7 @@ static int eventfs_set_attr(struct mnt_idmap *idmap, struct dentry *dentry,
/* Preallocate the children mode array if necessary */
if (!(dentry->d_inode->i_mode & S_IFDIR)) {
if (!ei->entry_attrs) {
- ei->entry_attrs = kzalloc(sizeof(*ei->entry_attrs) * ei->nr_entries,
+ ei->entry_attrs = kcalloc(ei->nr_entries, sizeof(*ei->entry_attrs),
GFP_NOFS);
if (!ei->entry_attrs) {
ret = -ENOMEM;
@@ -874,7 +874,7 @@ struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode
}
if (size) {
- ei->d_children = kzalloc(sizeof(*ei->d_children) * size, GFP_KERNEL);
+ ei->d_children = kcalloc(size, sizeof(*ei->d_children), GFP_KERNEL);
if (!ei->d_children) {
kfree_const(ei->name);
kfree(ei);
@@ -941,7 +941,7 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry
goto fail;
if (size) {
- ei->d_children = kzalloc(sizeof(*ei->d_children) * size, GFP_KERNEL);
+ ei->d_children = kcalloc(size, sizeof(*ei->d_children), GFP_KERNEL);
if (!ei->d_children)
goto fail;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] eventfs: Use kcalloc() instead of kzalloc()
2024-01-14 10:53 [PATCH] eventfs: Use kcalloc() instead of kzalloc() Erick Archer
@ 2024-01-15 10:06 ` Mark Rutland
0 siblings, 0 replies; 2+ messages in thread
From: Mark Rutland @ 2024-01-15 10:06 UTC (permalink / raw)
To: Erick Archer
Cc: Steven Rostedt, Masami Hiramatsu, Gustavo A. R. Silva,
Mathieu Desnoyers, linux-kernel, linux-trace-kernel,
linux-hardening
On Sun, Jan 14, 2024 at 11:53:40AM +0100, Erick Archer wrote:
> Use 2-factor multiplication argument form kcalloc() instead
> of kzalloc().
>
> Link: https://github.com/KSPP/linux/issues/162
> Signed-off-by: Erick Archer <erick.archer@gmx.com>
Could you put something in the commit message explaining *why* this change
should be made?
I assume that this is so that overflows during multiplication can be caught and
handled in some way, but the commit message doesn't say that, and nor does the
linked github page.
The patch itself looks fine.
Thanks,
Mark.
> ---
> fs/tracefs/event_inode.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c
> index fdff53d5a1f8..f8196289692c 100644
> --- a/fs/tracefs/event_inode.c
> +++ b/fs/tracefs/event_inode.c
> @@ -93,7 +93,7 @@ static int eventfs_set_attr(struct mnt_idmap *idmap, struct dentry *dentry,
> /* Preallocate the children mode array if necessary */
> if (!(dentry->d_inode->i_mode & S_IFDIR)) {
> if (!ei->entry_attrs) {
> - ei->entry_attrs = kzalloc(sizeof(*ei->entry_attrs) * ei->nr_entries,
> + ei->entry_attrs = kcalloc(ei->nr_entries, sizeof(*ei->entry_attrs),
> GFP_NOFS);
> if (!ei->entry_attrs) {
> ret = -ENOMEM;
> @@ -874,7 +874,7 @@ struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode
> }
>
> if (size) {
> - ei->d_children = kzalloc(sizeof(*ei->d_children) * size, GFP_KERNEL);
> + ei->d_children = kcalloc(size, sizeof(*ei->d_children), GFP_KERNEL);
> if (!ei->d_children) {
> kfree_const(ei->name);
> kfree(ei);
> @@ -941,7 +941,7 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry
> goto fail;
>
> if (size) {
> - ei->d_children = kzalloc(sizeof(*ei->d_children) * size, GFP_KERNEL);
> + ei->d_children = kcalloc(size, sizeof(*ei->d_children), GFP_KERNEL);
> if (!ei->d_children)
> goto fail;
> }
> --
> 2.25.1
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-01-15 10:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-14 10:53 [PATCH] eventfs: Use kcalloc() instead of kzalloc() Erick Archer
2024-01-15 10:06 ` Mark Rutland
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox