[PATCH v7 43/49] x86/resctrl: Prefer alloc(sizeof(*foo)) idiom in rdt_init_fs_context()

James Morse posted 49 patches 11 months, 2 weeks ago
There is a newer version of this series
[PATCH v7 43/49] x86/resctrl: Prefer alloc(sizeof(*foo)) idiom in rdt_init_fs_context()
Posted by James Morse 11 months, 2 weeks ago
From: Dave Martin <Dave.Martin@arm.com>

rdt_init_fs_context() sizes a typed allocation using an explicit
sizeof(type) expression, which checkpatch.pl complains about.

Since this code is about to be factored out and made generic, this
is a good opportunity to fix the code to size the allocation based
on the target pointer instead, to reduce the chance of future mis-
maintenance.

Fix it.

No functional change.

Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Signed-off-by: James Morse <james.morse@arm.com>
---
Changes since v6:
 * This patch is new.
---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index f03432e1b1f6..0976cee041c2 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -2929,7 +2929,7 @@ static int rdt_init_fs_context(struct fs_context *fc)
 {
 	struct rdt_fs_context *ctx;
 
-	ctx = kzalloc(sizeof(struct rdt_fs_context), GFP_KERNEL);
+	ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
 	if (!ctx)
 		return -ENOMEM;
 
-- 
2.39.5
Re: [PATCH v7 43/49] x86/resctrl: Prefer alloc(sizeof(*foo)) idiom in rdt_init_fs_context()
Posted by Reinette Chatre 11 months, 1 week ago
Hi James,

On 2/28/25 11:59 AM, James Morse wrote:
> From: Dave Martin <Dave.Martin@arm.com>
> 
> rdt_init_fs_context() sizes a typed allocation using an explicit
> sizeof(type) expression, which checkpatch.pl complains about.
> 
> Since this code is about to be factored out and made generic, this
> is a good opportunity to fix the code to size the allocation based
> on the target pointer instead, to reduce the chance of future mis-
> maintenance.
> 
> Fix it.
> 
> No functional change.
> 
> Signed-off-by: Dave Martin <Dave.Martin@arm.com>
> Signed-off-by: James Morse <james.morse@arm.com>
> ---

Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>

Reinette
Re: [PATCH v7 43/49] x86/resctrl: Prefer alloc(sizeof(*foo)) idiom in rdt_init_fs_context()
Posted by Fenghua Yu 11 months, 1 week ago
On 2/28/25 11:59, James Morse wrote:
> From: Dave Martin <Dave.Martin@arm.com>
>
> rdt_init_fs_context() sizes a typed allocation using an explicit
> sizeof(type) expression, which checkpatch.pl complains about.
>
> Since this code is about to be factored out and made generic, this
> is a good opportunity to fix the code to size the allocation based
> on the target pointer instead, to reduce the chance of future mis-
> maintenance.
>
> Fix it.
>
> No functional change.
>
> Signed-off-by: Dave Martin <Dave.Martin@arm.com>
> Signed-off-by: James Morse <james.morse@arm.com>

Reviewed-by: Fenghua Yu <fenghuay@nvidia.com>

Thanks.

-Fenghua