diff mbox series

[v2,1/3] net/ncsi: fix restricted cast warning of sparse

Message ID 20210708122754.555846-2-i.mikhaylov@yadro.com (mailing list archive)
State Accepted
Commit 27fa107d3b8d13a57cdd7c7a40bd6548d4b9cef8
Delegated to: Netdev Maintainers
Headers show
Series net/ncsi: Add NCSI Intel OEM command to keep PHY link up | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Guessed tree name to be net-next
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cc_maintainers success CCed 4 of 4 maintainers
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 5 this patch: 1
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 32 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 5 this patch: 1
netdev/header_inline success Link

Commit Message

Ivan Mikhaylov July 8, 2021, 12:27 p.m. UTC
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

Signed-off-by: Ivan Mikhaylov <i.mikhaylov@yadro.com>
---
 net/ncsi/ncsi-manage.c | 6 +++---
 net/ncsi/ncsi-rsp.c    | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

Comments

Joel Stanley July 12, 2021, 9:09 a.m. UTC | #1
On Thu, 8 Jul 2021 at 12:27, Ivan Mikhaylov <i.mikhaylov@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.

$ sparse --version
0.6.3 (Debian: 0.6.3-2)

>
> Signed-off-by: Ivan Mikhaylov <i.mikhaylov@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.

>         data[5] = NCSI_OEM_BCM_CMD_GMA;
>
>         nca->data = data;
> @@ -724,7 +724,7 @@ static int ncsi_oem_gma_handler_mlx(struct ncsi_cmd_arg *nca)
>         nca->payload = NCSI_OEM_MLX_CMD_GMA_LEN;
>
>         memset(&u, 0, sizeof(u));
> -       u.data_u32[0] = ntohl(NCSI_OEM_MFR_MLX_ID);
> +       u.data_u32[0] = ntohl((__force __be32)NCSI_OEM_MFR_MLX_ID);
>         u.data_u8[5] = NCSI_OEM_MLX_CMD_GMA;
>         u.data_u8[6] = NCSI_OEM_MLX_CMD_GMA_PARAM;
>
> @@ -747,7 +747,7 @@ static int ncsi_oem_smaf_mlx(struct ncsi_cmd_arg *nca)
>         int ret = 0;
>
>         memset(&u, 0, sizeof(u));
> -       u.data_u32[0] = ntohl(NCSI_OEM_MFR_MLX_ID);
> +       u.data_u32[0] = ntohl((__force __be32)NCSI_OEM_MFR_MLX_ID);
>         u.data_u8[5] = NCSI_OEM_MLX_CMD_SMAF;
>         u.data_u8[6] = NCSI_OEM_MLX_CMD_SMAF_PARAM;
>         memcpy(&u.data_u8[MLX_SMAF_MAC_ADDR_OFFSET],
> diff --git a/net/ncsi/ncsi-rsp.c b/net/ncsi/ncsi-rsp.c
> index 888ccc2d4e34..04bc50be5c01 100644
> --- a/net/ncsi/ncsi-rsp.c
> +++ b/net/ncsi/ncsi-rsp.c
> @@ -403,7 +403,7 @@ static int ncsi_rsp_handler_ev(struct ncsi_request *nr)
>         /* Update to VLAN mode */
>         cmd = (struct ncsi_cmd_ev_pkt *)skb_network_header(nr->cmd);
>         ncm->enable = 1;
> -       ncm->data[0] = ntohl(cmd->mode);
> +       ncm->data[0] = ntohl((__force __be32)cmd->mode);
>
>         return 0;
>  }
> --
> 2.31.1
>
Ivan Mikhaylov July 13, 2021, 9:08 a.m. UTC | #2
On Mon, 2021-07-12 at 09:09 +0000, Joel Stanley wrote:
> On Thu, 8 Jul 2021 at 12:27, Ivan Mikhaylov <i.mikhaylov@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@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.
diff mbox series

Patch

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);
 	data[5] = NCSI_OEM_BCM_CMD_GMA;
 
 	nca->data = data;
@@ -724,7 +724,7 @@  static int ncsi_oem_gma_handler_mlx(struct ncsi_cmd_arg *nca)
 	nca->payload = NCSI_OEM_MLX_CMD_GMA_LEN;
 
 	memset(&u, 0, sizeof(u));
-	u.data_u32[0] = ntohl(NCSI_OEM_MFR_MLX_ID);
+	u.data_u32[0] = ntohl((__force __be32)NCSI_OEM_MFR_MLX_ID);
 	u.data_u8[5] = NCSI_OEM_MLX_CMD_GMA;
 	u.data_u8[6] = NCSI_OEM_MLX_CMD_GMA_PARAM;
 
@@ -747,7 +747,7 @@  static int ncsi_oem_smaf_mlx(struct ncsi_cmd_arg *nca)
 	int ret = 0;
 
 	memset(&u, 0, sizeof(u));
-	u.data_u32[0] = ntohl(NCSI_OEM_MFR_MLX_ID);
+	u.data_u32[0] = ntohl((__force __be32)NCSI_OEM_MFR_MLX_ID);
 	u.data_u8[5] = NCSI_OEM_MLX_CMD_SMAF;
 	u.data_u8[6] = NCSI_OEM_MLX_CMD_SMAF_PARAM;
 	memcpy(&u.data_u8[MLX_SMAF_MAC_ADDR_OFFSET],
diff --git a/net/ncsi/ncsi-rsp.c b/net/ncsi/ncsi-rsp.c
index 888ccc2d4e34..04bc50be5c01 100644
--- a/net/ncsi/ncsi-rsp.c
+++ b/net/ncsi/ncsi-rsp.c
@@ -403,7 +403,7 @@  static int ncsi_rsp_handler_ev(struct ncsi_request *nr)
 	/* Update to VLAN mode */
 	cmd = (struct ncsi_cmd_ev_pkt *)skb_network_header(nr->cmd);
 	ncm->enable = 1;
-	ncm->data[0] = ntohl(cmd->mode);
+	ncm->data[0] = ntohl((__force __be32)cmd->mode);
 
 	return 0;
 }