staging: trivial: hikey9xx: fix be32<->u32 casting warnings
PATCH 1/1 staging: trivial: hikey9xx: fix be32<->u32 casting warnings
This patch fixes the following warnings reported by sparse by adding missing __force annotations.
drivers/staging/hikey9xx/hisi-spmi-controller.c:164:24: warning: cast to restricted __be32 drivers/staging/hikey9xx/hisi-spmi-controller.c:164:24: warning: cast to restricted __be32 drivers/staging/hikey9xx/hisi-spmi-controller.c:164:24: warning: cast to restricted __be32 drivers/staging/hikey9xx/hisi-spmi-controller.c:164:24: warning: cast to restricted __be32 drivers/staging/hikey9xx/hisi-spmi-controller.c:164:24: warning: cast to restricted __be32 drivers/staging/hikey9xx/hisi-spmi-controller.c:164:24: warning: cast to restricted __be32
drivers/staging/hikey9xx/hisi-spmi-controller.c:239:25: warning: cast from restricted __be32
Rationale for #164:
data is declared as u32, and it read then converted by means of be32_to_cpu(). Said function expects a __be32 but data is u32, therefore there's a type missmatch here.
Rationale for #293:
Is the dualof #164. This time data going to be written so it needs to be converted from cpu to be32, but writel() expects u32 and the output of cpu_to_be32 returns a __be32.
--- drivers/staging/hikey9xx/hisi-spmi-controller.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/hikey9xx/hisi-spmi-controller.c +2 -2
@@ -161,7 +161,7 @@ static int spmi_read_cmd(struct spmi_controller *ctrl,SPMI_SLAVE_OFFSET * slave_id +SPMI_APB_SPMI_RDATA0_BASE_ADDR + i * SPMI_PER_DATAREG_BYTE); - data =be32_to_cpu ((__be32 )data); + data =be32_to_cpu ((__be32 __force )data);if ((bc - i *SPMI_PER_DATAREG_BYTE ) >>2 ) {memcpy (buf, &data,sizeof (data)); buf +=sizeof (data);
@@ -236,7 +236,7 @@ static int spmi_write_cmd(struct spmi_controller *ctrl, buf += (bc %SPMI_PER_DATAREG_BYTE ); } -writel ((u32 )cpu_to_be32 (data), +writel ((u32 __force )cpu_to_be32 (data), spmi_controller->base + chnl_ofst +SPMI_APB_SPMI_WDATA0_BASE_ADDR +SPMI_PER_DATAREG_BYTE * i);
Signature · 1 line
2.28.0
PATCH v2 1/1 staging: trivial: hikey9xx: fix be32<->u32 casting warnings
This patch fixes the following warnings reported by sparse, by adding missing __force annotations.
drivers/staging/hikey9xx/hisi-spmi-controller.c:164:24: warning: cast to restricted __be32 drivers/staging/hikey9xx/hisi-spmi-controller.c:164:24: warning: cast to restricted __be32 drivers/staging/hikey9xx/hisi-spmi-controller.c:164:24: warning: cast to restricted __be32 drivers/staging/hikey9xx/hisi-spmi-controller.c:164:24: warning: cast to restricted __be32 drivers/staging/hikey9xx/hisi-spmi-controller.c:164:24: warning: cast to restricted __be32 drivers/staging/hikey9xx/hisi-spmi-controller.c:164:24: warning: cast to restricted __be32
drivers/staging/hikey9xx/hisi-spmi-controller.c:239:25: warning: cast from restricted __be32
Rationale for #164:
data is declared as u32, and it is read and then converted by means of be32_to_cpu(). Said function expects a __be32 but data is u32, therefore there's a type missmatch here.
Rationale for #239:
Is the dual of #164. This time data going to be written so it needs to be converted from cpu to __be32, but writel() expects u32 and the output of cpu_to_be32 returns a __be32.
---
Changes in V2:
- Fix typo in commit message.
drivers/staging/hikey9xx/hisi-spmi-controller.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/hikey9xx/hisi-spmi-controller.c +2 -2
@@ -161,7 +161,7 @@ static int spmi_read_cmd(struct spmi_controller *ctrl,SPMI_SLAVE_OFFSET * slave_id +SPMI_APB_SPMI_RDATA0_BASE_ADDR + i * SPMI_PER_DATAREG_BYTE); - data =be32_to_cpu ((__be32 )data); + data =be32_to_cpu ((__be32 __force )data);if ((bc - i *SPMI_PER_DATAREG_BYTE ) >>2 ) {memcpy (buf, &data,sizeof (data)); buf +=sizeof (data);
@@ -236,7 +236,7 @@ static int spmi_write_cmd(struct spmi_controller *ctrl, buf += (bc %SPMI_PER_DATAREG_BYTE ); } -writel ((u32 )cpu_to_be32 (data), +writel ((u32 __force )cpu_to_be32 (data), spmi_controller->base + chnl_ofst +SPMI_APB_SPMI_WDATA0_BASE_ADDR +SPMI_PER_DATAREG_BYTE * i);
Signature · 1 line
2.28.0
Quoted 18 lines · Juan Antonio Aldea-Armenteros
This patch fixes the following warnings reported by sparse, by adding missing
__forceannotations.
drivers/staging/hikey9xx/hisi-spmi-controller.c:164:24: warning: cast to restricted__be32drivers/staging/hikey9xx/hisi-spmi-controller.c:164:24: warning: cast to restricted__be32drivers/staging/hikey9xx/hisi-spmi-controller.c:164:24: warning: cast to restricted__be32drivers/staging/hikey9xx/hisi-spmi-controller.c:164:24: warning: cast to restricted__be32drivers/staging/hikey9xx/hisi-spmi-controller.c:164:24: warning: cast to restricted__be32drivers/staging/hikey9xx/hisi-spmi-controller.c:164:24: warning: cast to restricted__be32
drivers/staging/hikey9xx/hisi-spmi-controller.c:239:25: warning: cast from restricted__be32Rationale for #164:
data is declared as u32, and it is read and then converted by means ofbe32_to_cpu(). Said function expects a__be32but data is u32, therefore there's a type missmatch here.
Quoted 4 lines
Rationale for #239:
Is the dual of #164. This time data going to be written so it needs to be converted from cpu to__be32, butwritel()expects u32 and the output ofcpu_to_be32returns a__be32.
Both of the casts look very suspicious, I'd leave these in unless someone can confirm what the actual desired behavior is.
drivers/staging/hikey9xx/hisi-spmi-controller.c static int spmi_read_cmd(struct spmi_controller *ctrl, · line 167
Quoted 8 lines
SPMI_SLAVE_OFFSET*slave_id+SPMI_APB_SPMI_RDATA0_BASE_ADDR+ i *SPMI_PER_DATAREG_BYTE);drivers/staging/hikey9xx/hisi-spmi-controller.c +1
-1- data =be32_to_cpu ((__be32 )data); + data =be32_to_cpu ((__be32 __force )data);if ((bc - i *SPMI_PER_DATAREG_BYTE ) >>2 ) {memcpy (buf, &data,sizeof (data)); buf +=sizeof (data);
The data comes from a readl(), which contains an endian conversion on architectures that need it, such as when running the board in big-endian arm64 mode. Having a second endian-conversion on little-endian architectures means that the data is always swapped when it gets written to the register.
In the original code before Mauro's commit 8788a30c12c7 ("staging:
spmi: hisi-spmi-controller: use le32 macros where needed"), the data was byteswapped, and then written into the fifo register, which produced no warning but would do a double-swap on a big-endian kernel, and change the behavior from what it was before.
My guess is that Mauro inadvertently fixed this driver for big-endian mode, without noticing that it was broken to start with, and that he did not actually try it with CONFIG_CPU_BIG_ENDIAN.
I think the best way would be to go back to to using swab32p() (not the open-coded version) and then use writesl() or iowrite32_rep() with count=1 to write the byteswapped FIFO register without swapping it again.
Arnd