[PATCH v2 1/3] net/ncsi: fix restricted cast warning of sparse
Ivan Mikhaylov
i.mikhaylov at yadro.com
Tue Jul 13 19:08:56 AEST 2021
On Mon, 2021-07-12 at 09:09 +0000, Joel Stanley wrote:
> On Thu, 8 Jul 2021 at 12:27, Ivan Mikhaylov <i.mikhaylov at yadro.com> wrote:
> >
> > Sparse reports:
> > net/ncsi/ncsi-rsp.c:406:24: warning: cast to restricted __be32
> > net/ncsi/ncsi-manage.c:732:33: warning: cast to restricted __be32
> > net/ncsi/ncsi-manage.c:756:25: warning: cast to restricted __be32
> > net/ncsi/ncsi-manage.c:779:25: warning: cast to restricted __be32
>
> Strange, I don't get these warnings from sparse on my system.
https://patchwork.hopto.org/static/nipa/510079/12355969/build_32bit/stderr
All those errors from ntohl. David linked this one in first series of patches.
>
> $ sparse --version
> 0.6.3 (Debian: 0.6.3-2)
>
> >
> > Signed-off-by: Ivan Mikhaylov <i.mikhaylov at yadro.com>
> > ---
> > net/ncsi/ncsi-manage.c | 6 +++---
> > net/ncsi/ncsi-rsp.c | 2 +-
> > 2 files changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/net/ncsi/ncsi-manage.c b/net/ncsi/ncsi-manage.c
> > index ca04b6df1341..42b54a3da2e6 100644
> > --- a/net/ncsi/ncsi-manage.c
> > +++ b/net/ncsi/ncsi-manage.c
> > @@ -700,7 +700,7 @@ static int ncsi_oem_gma_handler_bcm(struct ncsi_cmd_arg
> > *nca)
> > nca->payload = NCSI_OEM_BCM_CMD_GMA_LEN;
> >
> > memset(data, 0, NCSI_OEM_BCM_CMD_GMA_LEN);
> > - *(unsigned int *)data = ntohl(NCSI_OEM_MFR_BCM_ID);
> > + *(unsigned int *)data = ntohl((__force __be32)NCSI_OEM_MFR_BCM_ID);
>
> This looks wrong, the value you're passing isn't big endian. It would
> make more sense if the byte swap was ntohl, as it's coming from the
> cpu and going into the NCSI packet.
Is there any other ways to deal with those sparse errors?
Thanks.
More information about the openbmc
mailing list