From: Cedric Xing <cedric.xing@intel.com>
To: linux@weissschuh.net, dan.j.williams@intel.com
Cc: sfr@canb.auug.org.au, sathyanarayanan.kuppuswamy@linux.intel.com,
yilun.xu@intel.com, sameo@rivosinc.com, aik@amd.com,
suzuki.poulose@arm.com, steven.price@arm.com, lukas@wunner.de,
greg@kroah.com, linux-next@vger.kernel.org,
Cedric Xing <cedric.xing@intel.com>
Subject: [PATCH] tsm-mr: Fix init breakage after bin_attrs constification by scoping non-const pointers to init phase
Date: Tue, 13 May 2025 10:47:42 -0500 [thread overview]
Message-ID: <20250513154742.9548-1-cedric.xing@intel.com> (raw)
Commit 9bec944506fa ("sysfs: constify attribute_group::bin_attrs") enforced
the ro-after-init principle by making elements of bin_attrs pointing to
const.
To align with this change, introduce a temporary variable `bap` within the
initialization loop. This improves code clarity by explicitly marking the
initialization scope and eliminates the need for type casts after bin_attrs
was constified.
Signed-off-by: Cedric Xing <cedric.xing@intel.com>
---
drivers/virt/coco/tsm-mr.c | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/drivers/virt/coco/tsm-mr.c b/drivers/virt/coco/tsm-mr.c
index 1f0c43a516fb..a6362b144e8b 100644
--- a/drivers/virt/coco/tsm-mr.c
+++ b/drivers/virt/coco/tsm-mr.c
@@ -173,7 +173,7 @@ tsm_mr_create_attribute_group(const struct tsm_measurements *tm)
* so that we don't have to free MR names one-by-one in
* tsm_mr_free_attribute_group()
*/
- const struct bin_attribute * const *attrs __free(kfree) =
+ const struct bin_attribute **attrs __free(kfree) =
kzalloc(sizeof(*attrs) * (tm->nr_mrs + 1) + nlen, GFP_KERNEL);
struct tm_context *ctx __free(kfree) =
kzalloc(struct_size(ctx, mrs, tm->nr_mrs), GFP_KERNEL);
@@ -187,16 +187,14 @@ tsm_mr_create_attribute_group(const struct tsm_measurements *tm)
end = name + nlen;
for (size_t i = 0; i < tm->nr_mrs; ++i) {
- /* break const for init */
- struct bin_attribute **bas = (struct bin_attribute **)attrs;
+ struct bin_attribute *bap = &ctx->mrs[i];
- bas[i] = &ctx->mrs[i];
- sysfs_bin_attr_init(bas[i]);
+ sysfs_bin_attr_init(bap);
if (tm->mrs[i].mr_flags & TSM_MR_F_NOHASH)
- bas[i]->attr.name = tm->mrs[i].mr_name;
+ bap->attr.name = tm->mrs[i].mr_name;
else if (name < end) {
- bas[i]->attr.name = name;
+ bap->attr.name = name;
name += snprintf(name, end - name, "%s:%s",
tm->mrs[i].mr_name,
hash_algo_name[tm->mrs[i].mr_hash]);
@@ -206,21 +204,23 @@ tsm_mr_create_attribute_group(const struct tsm_measurements *tm)
/* check for duplicated MR definitions */
for (size_t j = 0; j < i; ++j)
- if (!strcmp(bas[i]->attr.name, bas[j]->attr.name))
+ if (!strcmp(bap->attr.name, attrs[j]->attr.name))
return ERR_PTR(-EINVAL);
if (tm->mrs[i].mr_flags & TSM_MR_F_READABLE) {
- bas[i]->attr.mode |= 0444;
- bas[i]->read_new = tm_digest_read;
+ bap->attr.mode |= 0444;
+ bap->read_new = tm_digest_read;
}
if (tm->mrs[i].mr_flags & TSM_MR_F_WRITABLE) {
- bas[i]->attr.mode |= 0200;
- bas[i]->write_new = tm_digest_write;
+ bap->attr.mode |= 0200;
+ bap->write_new = tm_digest_write;
}
- bas[i]->size = tm->mrs[i].mr_size;
- bas[i]->private = ctx;
+ bap->size = tm->mrs[i].mr_size;
+ bap->private = ctx;
+
+ attrs[i] = bap;
}
if (name != end)
base-commit: 7c3f259dfe03f5dcd898126602818a8fbe94d3c5
--
2.43.0
next reply other threads:[~2025-05-13 15:48 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-13 15:47 Cedric Xing [this message]
2025-05-13 16:24 ` [PATCH] tsm-mr: Fix init breakage after bin_attrs constification by scoping non-const pointers to init phase Thomas Weißschuh
2025-05-13 16:41 ` [PATCH v2] " Cedric Xing
2025-05-13 16:49 ` Thomas Weißschuh
2025-05-13 17:27 ` dan.j.williams
2025-05-13 17:29 ` dan.j.williams
2025-05-13 18:25 ` Thomas Weißschuh
2025-05-13 18:37 ` Dan Williams
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=20250513154742.9548-1-cedric.xing@intel.com \
--to=cedric.xing@intel.com \
--cc=aik@amd.com \
--cc=dan.j.williams@intel.com \
--cc=greg@kroah.com \
--cc=linux-next@vger.kernel.org \
--cc=linux@weissschuh.net \
--cc=lukas@wunner.de \
--cc=sameo@rivosinc.com \
--cc=sathyanarayanan.kuppuswamy@linux.intel.com \
--cc=sfr@canb.auug.org.au \
--cc=steven.price@arm.com \
--cc=suzuki.poulose@arm.com \
--cc=yilun.xu@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