Subject: Re: [PATCH v2] tsm-mr: Fix init breakage after bin_attrs constification by scoping non-const pointers to init phase

From: Thomas Weißschuh <[email-masked]>
Date: Tue, 13 May 2025 18:49:17 +0200

On 2025-05-13 11:41:54-0500, Cedric Xing wrote:
> Commit 9bec944506fa ("sysfs: constify attribute_group::bin_attrs") enforced
> the ro-after-init principle by making elements of bin_attrs_new 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 when assigning
> to bin_attrs_new.
> 
> Signed-off-by: Cedric Xing <[email-masked]>
> ---
>  drivers/virt/coco/tsm-mr.c | 30 +++++++++++++++---------------
>  1 file changed, 15 insertions(+), 15 deletions(-)

<snip>

> @@ -244,7 +244,7 @@ EXPORT_SYMBOL_GPL(tsm_mr_create_attribute_group);
>  void tsm_mr_free_attribute_group(const struct attribute_group *attr_grp)
>  {
>  	if (!IS_ERR_OR_NULL(attr_grp)) {
> -		kfree(attr_grp->bin_attrs);
> +		kfree(attr_grp->bin_attrs_new);

This is good, but the assignment also needs to be done to .bin_attrs_new.
That is the code I can find on LKML:
https://lore.kernel.org/lkml/[email-masked]/

>  		kfree(container_of(attr_grp, struct tm_context, agrp));
>  	}
>  }
> 
> base-commit: 7c3f259dfe03f5dcd898126602818a8fbe94d3c5
> --
> 2.43.0
>