* [PATCH] EDAC/ecs: simplify allocation for context
@ 2026-04-30 21:52 Rosen Penev
0 siblings, 0 replies; only message in thread
From: Rosen Penev @ 2026-04-30 21:52 UTC (permalink / raw)
To: linux-edac
Cc: Borislav Petkov, Tony Luck, Kees Cook, Gustavo A. R. Silva,
open list,
open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b
Use a flexible array member to combine allocations
Add __counted_by for extra runtime analysis.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/edac/ecs.c | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/drivers/edac/ecs.c b/drivers/edac/ecs.c
index 51c451c7f0f0..f0833080c5cc 100644
--- a/drivers/edac/ecs.c
+++ b/drivers/edac/ecs.c
@@ -33,7 +33,7 @@ struct edac_ecs_fru_context {
struct edac_ecs_context {
u16 num_media_frus;
- struct edac_ecs_fru_context *fru_ctxs;
+ struct edac_ecs_fru_context fru_ctxs[] __counted_by(num_media_frus);
};
#define TO_ECS_DEV_ATTR(_dev_attr) \
@@ -149,17 +149,11 @@ static int ecs_create_desc(struct device *ecs_dev, const struct attribute_group
struct edac_ecs_context *ecs_ctx;
u32 fru;
- ecs_ctx = devm_kzalloc(ecs_dev, sizeof(*ecs_ctx), GFP_KERNEL);
+ ecs_ctx = devm_kzalloc(ecs_dev, struct_size(ecs_ctx, fru_ctxs, num_media_frus), GFP_KERNEL);
if (!ecs_ctx)
return -ENOMEM;
ecs_ctx->num_media_frus = num_media_frus;
- ecs_ctx->fru_ctxs = devm_kcalloc(ecs_dev, num_media_frus,
- sizeof(*ecs_ctx->fru_ctxs),
- GFP_KERNEL);
- if (!ecs_ctx->fru_ctxs)
- return -ENOMEM;
-
for (fru = 0; fru < num_media_frus; fru++) {
struct edac_ecs_fru_context *fru_ctx = &ecs_ctx->fru_ctxs[fru];
struct attribute_group *group = &fru_ctx->group;
--
2.54.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-04-30 21:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-30 21:52 [PATCH] EDAC/ecs: simplify allocation for context Rosen Penev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox