[PATCH 03/13] spi: cadence-qspi: Fix style and improve readability

Miquel Raynal (Schneider Electric) posted 13 patches 1 month, 3 weeks ago
There is a newer version of this series
[PATCH 03/13] spi: cadence-qspi: Fix style and improve readability
Posted by Miquel Raynal (Schneider Electric) 1 month, 3 weeks ago
It took me several seconds to correctly understand this block. I
understand the goal: showing that we are in the if, or in one of the two
other cases. Improve the organization of the code to both improve
readability and fix the style.

Signed-off-by: Miquel Raynal (Schneider Electric) <miquel.raynal@bootlin.com>
---
 drivers/spi/spi-cadence-quadspi.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c
index e16a591e1f20..90387757fb6b 100644
--- a/drivers/spi/spi-cadence-quadspi.c
+++ b/drivers/spi/spi-cadence-quadspi.c
@@ -376,13 +376,13 @@ static irqreturn_t cqspi_irq_handler(int this_irq, void *dev)
 			complete(&cqspi->transfer_complete);
 			return IRQ_HANDLED;
 		}
+	} else {
+		if (!cqspi->slow_sram)
+			irq_status &= CQSPI_IRQ_MASK_RD | CQSPI_IRQ_MASK_WR;
+		else
+			irq_status &= CQSPI_REG_IRQ_WATERMARK | CQSPI_IRQ_MASK_WR;
 	}
 
-	else if (!cqspi->slow_sram)
-		irq_status &= CQSPI_IRQ_MASK_RD | CQSPI_IRQ_MASK_WR;
-	else
-		irq_status &= CQSPI_REG_IRQ_WATERMARK | CQSPI_IRQ_MASK_WR;
-
 	if (irq_status)
 		complete(&cqspi->transfer_complete);
 

-- 
2.51.1
Re: [PATCH 03/13] spi: cadence-qspi: Fix style and improve readability
Posted by Pratyush Yadav 1 month, 2 weeks ago
On Fri, Dec 19 2025, Miquel Raynal (Schneider Electric) wrote:

> It took me several seconds to correctly understand this block. I
> understand the goal: showing that we are in the if, or in one of the two
> other cases. Improve the organization of the code to both improve
> readability and fix the style.
>
> Signed-off-by: Miquel Raynal (Schneider Electric) <miquel.raynal@bootlin.com>
> ---
>  drivers/spi/spi-cadence-quadspi.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c
> index e16a591e1f20..90387757fb6b 100644
> --- a/drivers/spi/spi-cadence-quadspi.c
> +++ b/drivers/spi/spi-cadence-quadspi.c
> @@ -376,13 +376,13 @@ static irqreturn_t cqspi_irq_handler(int this_irq, void *dev)
>  			complete(&cqspi->transfer_complete);
>  			return IRQ_HANDLED;
>  		}
> +	} else {
> +		if (!cqspi->slow_sram)
> +			irq_status &= CQSPI_IRQ_MASK_RD | CQSPI_IRQ_MASK_WR;
> +		else
> +			irq_status &= CQSPI_REG_IRQ_WATERMARK | CQSPI_IRQ_MASK_WR;
>  	}
>  
> -	else if (!cqspi->slow_sram)
> -		irq_status &= CQSPI_IRQ_MASK_RD | CQSPI_IRQ_MASK_WR;
> -	else
> -		irq_status &= CQSPI_REG_IRQ_WATERMARK | CQSPI_IRQ_MASK_WR;
> -

I suppose you can further simplify the if-else chain to:


	if (cqspi->use_dma_read && ddata && ddata->get_dma_status) {
		irq_status = ddata->get_dma_status(cqspi);
	else if (cqspi->slow_sram)
		irq_status &= CQSPI_REG_IRQ_WATERMARK | CQSPI_IRQ_MASK_WR;
	else
		irq_status &= CQSPI_IRQ_MASK_RD | CQSPI_IRQ_MASK_WR;

	if (irq_status)
		complete(&cqspi->transfer_complete);

	return IRQ_HANDLED;

Note that I swapped the latter two if statements to get rid of the
unnecessary negation of slow_sram. I suppose the overloading of
irq_status isn't the nicest thing, but I still find this easier to read.

>  	if (irq_status)
>  		complete(&cqspi->transfer_complete);

-- 
Regards,
Pratyush Yadav
Re: [PATCH 03/13] spi: cadence-qspi: Fix style and improve readability
Posted by Miquel Raynal 3 weeks, 6 days ago
Hi Pratyush,

>> +	} else {
>> +		if (!cqspi->slow_sram)
>> +			irq_status &= CQSPI_IRQ_MASK_RD | CQSPI_IRQ_MASK_WR;
>> +		else
>> +			irq_status &= CQSPI_REG_IRQ_WATERMARK | CQSPI_IRQ_MASK_WR;
>>  	}
>>  
>> -	else if (!cqspi->slow_sram)
>> -		irq_status &= CQSPI_IRQ_MASK_RD | CQSPI_IRQ_MASK_WR;
>> -	else
>> -		irq_status &= CQSPI_REG_IRQ_WATERMARK | CQSPI_IRQ_MASK_WR;
>> -
>
> I suppose you can further simplify the if-else chain to:
>
>
> 	if (cqspi->use_dma_read && ddata && ddata->get_dma_status) {
> 		irq_status = ddata->get_dma_status(cqspi);
> 	else if (cqspi->slow_sram)
> 		irq_status &= CQSPI_REG_IRQ_WATERMARK | CQSPI_IRQ_MASK_WR;
> 	else
> 		irq_status &= CQSPI_IRQ_MASK_RD | CQSPI_IRQ_MASK_WR;
>
> 	if (irq_status)
> 		complete(&cqspi->transfer_complete);
>
> 	return IRQ_HANDLED;
>
> Note that I swapped the latter two if statements to get rid of the
> unnecessary negation of slow_sram. I suppose the overloading of
> irq_status isn't the nicest thing, but I still find this easier to
> read.

I'm fine with this approach too, I'll take it!

Thanks for the proposal.

Miquèl