All of lore.kernel.org
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy@arm.com>
To: Cristian Marussi <cristian.marussi@arm.com>,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Cc: Sudeep Holla <sudeep.holla@arm.com>
Subject: Re: [PATCH 2/2] firmware: arm_scmi: Fix pointers arithmetic in Base protocol
Date: Tue, 31 May 2022 12:02:53 +0100	[thread overview]
Message-ID: <1cdf5131-a67b-7297-ad75-49b53f2da293@arm.com> (raw)
In-Reply-To: <20220530115237.277077-2-cristian.marussi@arm.com>

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@arm.com>
> Signed-off-by: Cristian Marussi <cristian.marussi@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;

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

WARNING: multiple messages have this Message-ID (diff)
From: Robin Murphy <robin.murphy@arm.com>
To: Cristian Marussi <cristian.marussi@arm.com>,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Cc: Sudeep Holla <sudeep.holla@arm.com>
Subject: Re: [PATCH 2/2] firmware: arm_scmi: Fix pointers arithmetic in Base protocol
Date: Tue, 31 May 2022 12:02:53 +0100	[thread overview]
Message-ID: <1cdf5131-a67b-7297-ad75-49b53f2da293@arm.com> (raw)
In-Reply-To: <20220530115237.277077-2-cristian.marussi@arm.com>

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@arm.com>
> Signed-off-by: Cristian Marussi <cristian.marussi@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;

  reply	other threads:[~2022-05-31 11:04 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-30 11:52 [PATCH 1/2] firmware: arm_scmi: Remove unused local variables Cristian Marussi
2022-05-30 11:52 ` Cristian Marussi
2022-05-30 11:52 ` [PATCH 2/2] firmware: arm_scmi: Fix pointers arithmetic in Base protocol Cristian Marussi
2022-05-30 11:52   ` Cristian Marussi
2022-05-31 11:02   ` Robin Murphy [this message]
2022-05-31 11:02     ` Robin Murphy
2022-05-31 11:36     ` Cristian Marussi
2022-05-31 11:36       ` Cristian Marussi
2022-06-06 14:51 ` [PATCH 1/2] firmware: arm_scmi: Remove unused local variables Sudeep Holla
2022-06-06 14:51   ` Sudeep Holla

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=1cdf5131-a67b-7297-ad75-49b53f2da293@arm.com \
    --to=robin.murphy@arm.com \
    --cc=cristian.marussi@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sudeep.holla@arm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.