[PATCH v17 03/34] firmware: arm_scmi: Make Clock attributes size deterministic

Jonathan Cameron jonathan.cameron at oss.qualcomm.com
Tue Nov 24 15:20:30 PST 2026


On Tue, 24 Nov 2026 19:48:09 +0000
Cristian Marussi <cristian.marussi at arm.com> wrote:

> SCMI Clock protocol CLOCK_ATTRIBUTES command varied in its reply payload
> size together with the specification evolution.
> 
> Between Clock version 0x10000 and 0x20000 one trailing field was added.
> The current implementation used the maximum possible payload size across
> any protocol version as the rx_size paramenter passed to xfer_get_init:
> such solution works fine but inhibits any possible centralized check on
> the size of the received reply.
> 
> Size the requested reply strictly according to the expected protocol
> version.
> 
> Signed-off-by: Cristian Marussi <cristian.marussi at arm.com>

You could use offsetof() so it doesn't matter if yet more fields
turn up later. In practice though you'll then have 3 options so this
code will change anyway, so meh. This is fine.

Reviewed-by: Jonathan Cameron <jonathan.cameron at oss.qualcomm.com>

Being lazy I didn't check old specs :)



> ---
>  drivers/firmware/arm_scmi/clock.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/firmware/arm_scmi/clock.c b/drivers/firmware/arm_scmi/clock.c
> index 6b5d50b35a48..ed93970c3b87 100644
> --- a/drivers/firmware/arm_scmi/clock.c
> +++ b/drivers/firmware/arm_scmi/clock.c
> @@ -362,10 +362,14 @@ static int scmi_clock_attributes_get(const struct scmi_protocol_handle *ph,
>  	u32 attributes;
>  	struct scmi_xfer *t;
>  	struct scmi_msg_resp_clock_attributes *attr;
> +	size_t rx_size = sizeof(*attr);
>  	struct scmi_clock_info *clk = CLOCK_INFO(cinfo, clk_id);
>  
> +	if (PROTOCOL_REV_MAJOR(ph->version) < 0x2)
> +		rx_size -= sizeof(attr->clock_enable_latency);
> +
>  	ret = ph->xops->xfer_get_init(ph, CLOCK_ATTRIBUTES,
> -				      sizeof(clk_id), sizeof(*attr), &t);
> +				      sizeof(clk_id), rx_size, &t);
>  	if (ret)
>  		return ret;
>  
> @@ -1002,12 +1006,16 @@ scmi_clock_config_get(const struct scmi_protocol_handle *ph, u32 clk_id,
>  	int ret;
>  	struct scmi_xfer *t;
>  	struct scmi_msg_resp_clock_attributes *resp;
> +	size_t rx_size = sizeof(*resp);
>  
>  	if (!enabled)
>  		return -EINVAL;
>  
> +	if (PROTOCOL_REV_MAJOR(ph->version) < 0x2)
> +		rx_size -= sizeof(resp->clock_enable_latency);
> +
>  	ret = ph->xops->xfer_get_init(ph, CLOCK_ATTRIBUTES,
> -				      sizeof(clk_id), sizeof(*resp), &t);
> +				      sizeof(clk_id), rx_size, &t);
>  	if (ret)
>  		return ret;
>  




More information about the linux-arm-kernel mailing list