On Thu, 19 Jun 2025 16:16:17 +0100
<shiju.jose@huawei.com> wrote:
> From: Shiju Jose <shiju.jose@huawei.com>
>
> Move the declaration of scrub and ECS feature attributes in cmd_features_set_feature()
> to the local scope where they are used.
>
> Signed-off-by: Shiju Jose <shiju.jose@huawei.com>
Local scope is fine, but I'm fairly sure that style wise these
files always use variable declarations at start of scope (except
for when g_auto_free is in use where it gets more complex).
> ---
> hw/cxl/cxl-mailbox-utils.c | 13 +++++--------
> 1 file changed, 5 insertions(+), 8 deletions(-)
>
> diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
> index 4d0c0b3edc..83668d7d93 100644
> --- a/hw/cxl/cxl-mailbox-utils.c
> +++ b/hw/cxl/cxl-mailbox-utils.c
> @@ -1459,10 +1459,6 @@ static CXLRetCode cmd_features_set_feature(const struct cxl_cmd *cmd,
> CXLCCI *cci)
> {
> CXLSetFeatureInHeader *hdr = (void *)payload_in;
> - CXLMemPatrolScrubWriteAttrs *ps_write_attrs;
> - CXLMemPatrolScrubSetFeature *ps_set_feature;
> - CXLMemECSWriteAttrs *ecs_write_attrs;
> - CXLMemECSSetFeature *ecs_set_feature;
> CXLSetFeatureInfo *set_feat_info;
> uint16_t bytes_to_copy = 0;
> uint8_t data_transfer_flag;
> @@ -1508,8 +1504,9 @@ static CXLRetCode cmd_features_set_feature(const struct cxl_cmd *cmd,
> return CXL_MBOX_UNSUPPORTED;
> }
>
> - ps_set_feature = (void *)payload_in;
> - ps_write_attrs = &ps_set_feature->feat_data;
> + CXLMemPatrolScrubSetFeature *ps_set_feature = (void *)payload_in;
Move the declaration to start of scope.
You can do assignment there as well as I don't think we care if we cast them
to the wrong type as header version isn't what we think it should be.
> + CXLMemPatrolScrubWriteAttrs *ps_write_attrs =
> + &ps_set_feature->feat_data;
>
> if ((uint32_t)hdr->offset + bytes_to_copy >
> sizeof(ct3d->patrol_scrub_wr_attrs)) {
> @@ -1535,8 +1532,8 @@ static CXLRetCode cmd_features_set_feature(const struct cxl_cmd *cmd,
> return CXL_MBOX_UNSUPPORTED;
> }
>
> - ecs_set_feature = (void *)payload_in;
> - ecs_write_attrs = ecs_set_feature->feat_data;
> + CXLMemECSSetFeature *ecs_set_feature = (void *)payload_in;
> + CXLMemECSWriteAttrs *ecs_write_attrs = ecs_set_feature->feat_data;
>
> if ((uint32_t)hdr->offset + bytes_to_copy >
> sizeof(ct3d->ecs_wr_attrs)) {