From: Rosen Penev <rosenp@gmail.com>
To: linux-edac@vger.kernel.org
Cc: Borislav Petkov <bp@alien8.de>, Tony Luck <tony.luck@intel.com>,
Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
linux-kernel@vger.kernel.org (open list),
linux-hardening@vger.kernel.org (open list:KERNEL HARDENING (not
covered by other areas):Keyword:\b__counted_by(_le|_be)?\b)
Subject: [PATCH] EDAC/ecs: simplify allocation for context
Date: Thu, 30 Apr 2026 14:52:16 -0700 [thread overview]
Message-ID: <20260430215216.65803-1-rosenp@gmail.com> (raw)
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
reply other threads:[~2026-04-30 21:52 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260430215216.65803-1-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=bp@alien8.de \
--cc=gustavoars@kernel.org \
--cc=kees@kernel.org \
--cc=linux-edac@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tony.luck@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox