diff mbox series

[1/4] spi: spi-fsl-dspi: Fix casting warnings

Message ID 20240927132944.19285-1-hardevsinh.palaniya@siliconsignals.io
State Superseded
Headers show
Series [1/4] spi: spi-fsl-dspi: Fix casting warnings | expand

Commit Message

Hardevsinh Palaniya Sept. 27, 2024, 1:28 p.m. UTC
Sparse warnings:

drivers/spi/spi-fsl-dspi.c:283:17: warning: incorrect type in assignment (different base types)
drivers/spi/spi-fsl-dspi.c:283:17:    expected unsigned int [usertype]
drivers/spi/spi-fsl-dspi.c:283:17:    got restricted __be32 [usertype]
drivers/spi/spi-fsl-dspi.c:289:28: warning: cast to restricted __be32
drivers/spi/spi-fsl-dspi.c:289:28: warning: cast to restricted __be32
drivers/spi/spi-fsl-dspi.c:289:28: warning: cast to restricted __be32
drivers/spi/spi-fsl-dspi.c:289:28: warning: cast to restricted __be32
drivers/spi/spi-fsl-dspi.c:289:28: warning: cast to restricted __be32
drivers/spi/spi-fsl-dspi.c:289:28: warning: cast to restricted __be32
drivers/spi/spi-fsl-dspi.c:295:17: warning: incorrect type in assignment (different base types)
drivers/spi/spi-fsl-dspi.c:295:17:    expected unsigned int [usertype]
drivers/spi/spi-fsl-dspi.c:295:17:    got restricted __be16 [usertype]
drivers/spi/spi-fsl-dspi.c:301:28: warning: cast to restricted __be16
drivers/spi/spi-fsl-dspi.c:301:28: warning: cast to restricted __be16
drivers/spi/spi-fsl-dspi.c:301:28: warning: cast to restricted __be16
drivers/spi/spi-fsl-dspi.c:301:28: warning: cast to restricted __be16

Signed-off-by: Hardevsinh Palaniya <hardevsinh.palaniya@siliconsignals.io>
---
 drivers/spi/spi-fsl-dspi.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Frank Li Sept. 27, 2024, 3:40 p.m. UTC | #1
On Fri, Sep 27, 2024 at 06:58:33PM +0530, Hardevsinh Palaniya wrote:
> Sparse warnings:
>
> drivers/spi/spi-fsl-qspi.c:635:25: warning: cast from restricted __be32
>
> Signed-off-by: Hardevsinh Palaniya <hardevsinh.palaniya@siliconsignals.io>
> ---
>  drivers/spi/spi-fsl-qspi.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/spi/spi-fsl-qspi.c b/drivers/spi/spi-fsl-qspi.c
> index 79bac30e79af..e4a2a6049e33 100644
> --- a/drivers/spi/spi-fsl-qspi.c
> +++ b/drivers/spi/spi-fsl-qspi.c
> @@ -632,7 +632,7 @@ static int fsl_qspi_readl_poll_tout(struct fsl_qspi *q, void __iomem *base,
>  	u32 reg;
>
>  	if (!q->devtype_data->little_endian)
> -		mask = (u32)cpu_to_be32(mask);
> +		mask =(__force u32)cpu_to_be32(mask);

Most this kind warning report the real problem. I don't suggest fix as it

the 'if branch' should be removed.

and simple

return read_poll_timeout(qspi_readl, reg, !(reg & mask), delay_us, timeout_us,
		  	 q, base);

qspi_readl() already handle endian problem.

Frank

>
>  	return readl_poll_timeout(base, reg, !(reg & mask), delay_us,
>  				  timeout_us);
> --
> 2.43.0
>
Frank Li Sept. 27, 2024, 3:47 p.m. UTC | #2
On Fri, Sep 27, 2024 at 06:58:35PM +0530, Hardevsinh Palaniya wrote:
> Sparse warnings:
>
> drivers/spi/spi-nxp-fspi.c:512:25: warning: cast from restricted __be32
>
> Signed-off-by: Hardevsinh Palaniya <hardevsinh.palaniya@siliconsignals.io>
> ---
>  drivers/spi/spi-nxp-fspi.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/spi/spi-nxp-fspi.c b/drivers/spi/spi-nxp-fspi.c
> index 6585b19a4866..f602bfd11426 100644
> --- a/drivers/spi/spi-nxp-fspi.c
> +++ b/drivers/spi/spi-nxp-fspi.c
> @@ -509,7 +509,7 @@ static int fspi_readl_poll_tout(struct nxp_fspi *f, void __iomem *base,
>  	u32 reg;
>
>  	if (!f->devtype_data->little_endian)
> -		mask = (u32)cpu_to_be32(mask);
> +		mask = (__force u32)cpu_to_be32(mask);

See patch 2's comments.

Frank

>
>  	if (c)
>  		return readl_poll_timeout(base, reg, (reg & mask),
> --
> 2.43.0
>
Hardevsinh Palaniya Sept. 28, 2024, 6:11 a.m. UTC | #3
Hi Frank,

Thanks for the suggestions

>>       if (!q->devtype_data->little_endian)
>> -             mask = (u32)cpu_to_be32(mask);
>> +             mask =(__force u32)cpu_to_be32(mask);
>
>Most this kind warning report the real problem. I don't suggest fix as it

I’m curious about the types of real problems that might arise

>the 'if branch' should be removed.
>
>and simple
>
>return read_poll_timeout(qspi_readl, reg, !(reg & mask), delay_us, timeout_us,
>                         q, base);
>
>qspi_readl() already handle endian problem.

I agree , it is a good approach since qspi_readl() already handles the endian issue 

I will change it to your approach.

>
>Frank

Best Regards,
Hardev
Hardevsinh Palaniya Sept. 30, 2024, 5:21 a.m. UTC | #4
Hi Frank,

>>       if (!q->devtype_data->little_endian)
>> -             mask = (u32)cpu_to_be32(mask);
>> +             mask =(__force u32)cpu_to_be32(mask);
>
>Most this kind warning report the real problem. I don't suggest fix as it

Should I drop patches 2 and 4 as per your suggestion.

>the 'if branch' should be removed.
>
>and simple
>
>return read_poll_timeout(qspi_readl, reg, !(reg & mask), delay_us, timeout_us,
                         q, base);
>
>qspi_readl() already handle endian problem.

 would you prefer I resend them with the changes you've recommended?

Best Regards,
Hardev
diff mbox series

Patch

diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c
index 191de1917f83..e34588679514 100644
--- a/drivers/spi/spi-fsl-dspi.c
+++ b/drivers/spi/spi-fsl-dspi.c
@@ -280,25 +280,25 @@  static void dspi_native_dev_to_host(struct fsl_dspi *dspi, u32 rxdata)
 
 static void dspi_8on32_host_to_dev(struct fsl_dspi *dspi, u32 *txdata)
 {
-	*txdata = cpu_to_be32(*(u32 *)dspi->tx);
+	*txdata = (__force u32)cpu_to_be32(*(u32 *)dspi->tx);
 	dspi->tx += sizeof(u32);
 }
 
 static void dspi_8on32_dev_to_host(struct fsl_dspi *dspi, u32 rxdata)
 {
-	*(u32 *)dspi->rx = be32_to_cpu(rxdata);
+	*(u32 *)dspi->rx = be32_to_cpu((__force __be32)rxdata);
 	dspi->rx += sizeof(u32);
 }
 
 static void dspi_8on16_host_to_dev(struct fsl_dspi *dspi, u32 *txdata)
 {
-	*txdata = cpu_to_be16(*(u16 *)dspi->tx);
+	*txdata = (__force u32)cpu_to_be16(*(u16 *)dspi->tx);
 	dspi->tx += sizeof(u16);
 }
 
 static void dspi_8on16_dev_to_host(struct fsl_dspi *dspi, u32 rxdata)
 {
-	*(u16 *)dspi->rx = be16_to_cpu(rxdata);
+	*(u16 *)dspi->rx = be16_to_cpu((__force __be16)rxdata);
 	dspi->rx += sizeof(u16);
 }