From: Cristian Marussi <cristian.marussi@arm.com>
To: Robin Murphy <robin.murphy@arm.com>
Cc: linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
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:36:07 +0100 [thread overview]
Message-ID: <YpX9K3x2zoToVy+3@e120937-lin> (raw)
In-Reply-To: <1cdf5131-a67b-7297-ad75-49b53f2da293@arm.com>
On Tue, May 31, 2022 at 12:02:53PM +0100, Robin Murphy wrote:
> 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.
>
Hi Robin,
thanks for the correction, I'll drop this.
Thanks,
Cristian
> 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;
next prev parent reply other threads:[~2022-05-31 11:36 UTC|newest]
Thread overview: 5+ 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 ` [PATCH 2/2] firmware: arm_scmi: Fix pointers arithmetic in Base protocol Cristian Marussi
2022-05-31 11:02 ` Robin Murphy
2022-05-31 11:36 ` Cristian Marussi [this message]
2022-06-06 14:51 ` [PATCH 1/2] firmware: arm_scmi: Remove unused local variables 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=YpX9K3x2zoToVy+3@e120937-lin \
--to=cristian.marussi@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robin.murphy@arm.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox