[PATCH 2/2] firmware: arm_scmi: Fix pointers arithmetic in Base protocol

Robin Murphy robin.murphy at arm.com
Tue May 31 04:02:53 PDT 2022


On 2022-05-30 12:52, Cristian Marussi wrote:
> Fix a possible undefined behaviour involving pointer arithmetic in Base
> protocol scmi_base_implementation_list_get().
> 
> cppcheck complains with:
> 
> drivers/firmware/arm_scmi/base.c:190:19: warning: 't->rx.buf' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]
>   list = t->rx.buf + sizeof(*num_ret);

Except we use GNU C, where it is well-defined[1]. We use void pointer 
arithmetic *all over* Linux, so there really isn't any valid argument 
that it could be problematic. If this was a common SCMI library intended 
to be portable then the patch would seem more reasonable, but in 
Linux-specific driver code it's just pointless churn.

Cheers,
Robin.

[1] https://gcc.gnu.org/onlinedocs/gcc/Pointer-Arith.html

> Fixes: b6f20ff8bd94 ("firmware: arm_scmi: add common infrastructure and support for base protocol")
> Cc: Sudeep Holla <sudeep.holla at arm.com>
> Signed-off-by: Cristian Marussi <cristian.marussi at arm.com>
> ---
>   drivers/firmware/arm_scmi/base.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/firmware/arm_scmi/base.c b/drivers/firmware/arm_scmi/base.c
> index 20fba7370f4e..6d6214d9e68c 100644
> --- a/drivers/firmware/arm_scmi/base.c
> +++ b/drivers/firmware/arm_scmi/base.c
> @@ -187,7 +187,7 @@ scmi_base_implementation_list_get(const struct scmi_protocol_handle *ph,
>   
>   	num_skip = t->tx.buf;
>   	num_ret = t->rx.buf;
> -	list = t->rx.buf + sizeof(*num_ret);
> +	list = ((u8 *)t->rx.buf) + sizeof(*num_ret);
>   
>   	do {
>   		size_t real_list_sz;



More information about the linux-arm-kernel mailing list