diff mbox series

[3/4] spi: spi-imx: Fix casting warnings

Message ID 20240927132944.19285-3-hardevsinh.palaniya@siliconsignals.io (mailing list archive)
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-imx.c:410:19: warning: cast to restricted __be32
drivers/spi/spi-imx.c:410:19: warning: cast to restricted __be32
drivers/spi/spi-imx.c:410:19: warning: cast to restricted __be32
drivers/spi/spi-imx.c:410:19: warning: cast to restricted __be32
drivers/spi/spi-imx.c:410:19: warning: cast to restricted __be32
drivers/spi/spi-imx.c:410:19: warning: cast to restricted __be32
drivers/spi/spi-imx.c:439:21: warning: incorrect type in assignment (different base types)
drivers/spi/spi-imx.c:439:21:    expected unsigned int [addressable] [usertype] val
drivers/spi/spi-imx.c:439:21:    got restricted __be32 [usertype]

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

Comments

Frank Li Sept. 27, 2024, 4:53 p.m. UTC | #1
On Fri, Sep 27, 2024 at 06:58:34PM +0530, Hardevsinh Palaniya wrote:
> Sparse warnings:
>
> drivers/spi/spi-imx.c:410:19: warning: cast to restricted __be32
> drivers/spi/spi-imx.c:410:19: warning: cast to restricted __be32
> drivers/spi/spi-imx.c:410:19: warning: cast to restricted __be32
> drivers/spi/spi-imx.c:410:19: warning: cast to restricted __be32
> drivers/spi/spi-imx.c:410:19: warning: cast to restricted __be32
> drivers/spi/spi-imx.c:410:19: warning: cast to restricted __be32
> drivers/spi/spi-imx.c:439:21: warning: incorrect type in assignment (different base types)
> drivers/spi/spi-imx.c:439:21:    expected unsigned int [addressable] [usertype] val
> drivers/spi/spi-imx.c:439:21:    got restricted __be32 [usertype]
>
> Signed-off-by: Hardevsinh Palaniya <hardevsinh.palaniya@siliconsignals.io>
> ---
>  drivers/spi/spi-imx.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
> index 85bd1a82a34e..8d09d9c1c556 100644
> --- a/drivers/spi/spi-imx.c
> +++ b/drivers/spi/spi-imx.c
> @@ -407,7 +407,7 @@ static void spi_imx_buf_tx_swap(struct spi_imx_data *spi_imx)
>
>  static void mx53_ecspi_rx_target(struct spi_imx_data *spi_imx)
>  {
> -	u32 val = be32_to_cpu(readl(spi_imx->base + MXC_CSPIRXDATA));
> +	u32 val = readl(spi_imx->base + MXC_CSPIRXDATA);

be32_to_cpu() is necessary in little endian system. You can't simple remove
it. you can use ioread32be here.

>
>  	if (spi_imx->rx_buf) {
>  		int n_bytes = spi_imx->target_burst % sizeof(val);
> @@ -436,7 +436,7 @@ static void mx53_ecspi_tx_target(struct spi_imx_data *spi_imx)
>  	if (spi_imx->tx_buf) {
>  		memcpy(((u8 *)&val) + sizeof(val) - n_bytes,
>  		       spi_imx->tx_buf, n_bytes);
> -		val = cpu_to_be32(val);
> +		val = (__force u32)cpu_to_be32(val);
>  		spi_imx->tx_buf += n_bytes;
>  	}

Original code logic is strange, you'd better to remove cpu_to_be32 here.

below writel change to iowrite32be().

Frank

>
> --
> 2.43.0
>
Hardevsinh Palaniya Sept. 28, 2024, 6:16 a.m. UTC | #2
Hi Frank,

Thanks for suggestions

>>  static void mx53_ecspi_rx_target(struct spi_imx_data *spi_imx)
>>  {
>> -     u32 val = be32_to_cpu(readl(spi_imx->base + MXC_CSPIRXDATA));
>> +     u32 val = readl(spi_imx->base + MXC_CSPIRXDATA);
>
>be32_to_cpu() is necessary in little endian system. You can't simple remove
>it. you can use ioread32be here.

I agree , i will update with ioread32be

>>
>>       if (spi_imx->rx_buf) {
>>               int n_bytes = spi_imx->target_burst % sizeof(val);
>> @@ -436,7 +436,7 @@ static void mx53_ecspi_tx_target(struct spi_imx_data *spi_imx)
>>       if (spi_imx->tx_buf) {
>>               memcpy(((u8 *)&val) + sizeof(val) - n_bytes,
>>                      spi_imx->tx_buf, n_bytes);
>> -             val = cpu_to_be32(val);
>> +             val = (__force u32)cpu_to_be32(val);
>>               spi_imx->tx_buf += n_bytes;
>>       }
>
>Original code logic is strange, you'd better to remove cpu_to_be32 here.

I will remove 

>
>below writel change to iowrite32be().

Sure 

>
>Frank

Best Regards,
Hardev
diff mbox series

Patch

diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index 85bd1a82a34e..8d09d9c1c556 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -407,7 +407,7 @@  static void spi_imx_buf_tx_swap(struct spi_imx_data *spi_imx)
 
 static void mx53_ecspi_rx_target(struct spi_imx_data *spi_imx)
 {
-	u32 val = be32_to_cpu(readl(spi_imx->base + MXC_CSPIRXDATA));
+	u32 val = readl(spi_imx->base + MXC_CSPIRXDATA);
 
 	if (spi_imx->rx_buf) {
 		int n_bytes = spi_imx->target_burst % sizeof(val);
@@ -436,7 +436,7 @@  static void mx53_ecspi_tx_target(struct spi_imx_data *spi_imx)
 	if (spi_imx->tx_buf) {
 		memcpy(((u8 *)&val) + sizeof(val) - n_bytes,
 		       spi_imx->tx_buf, n_bytes);
-		val = cpu_to_be32(val);
+		val = (__force u32)cpu_to_be32(val);
 		spi_imx->tx_buf += n_bytes;
 	}