[PATCH] spi: nxp-xspi: Use reinit_completion() for repeated operations

Felix Gu posted 1 patch 1 month, 1 week ago
drivers/spi/spi-nxp-xspi.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[PATCH] spi: nxp-xspi: Use reinit_completion() for repeated operations
Posted by Felix Gu 1 month, 1 week ago
The driver currently calls init_completion() during every spi_mem_op.
Tchnically it may work, but it's not the recommended pattern.

According to the kernel documentation: Calling init_completion() on
the same completion object twice is most likely a bug as it
re-initializes the queue to an empty queue and enqueued tasks
could get "lost" - use reinit_completion() in that case, but be
aware of other races.

So moves the initial initialization to probe function and uses
reinit_completion() for subsequent perations.

Fixes: 29c8c00d9f9d ("spi: add driver for NXP XSPI controller")
Signed-off-by: Felix Gu <ustc.gu@gmail.com>
---
 drivers/spi/spi-nxp-xspi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi-nxp-xspi.c b/drivers/spi/spi-nxp-xspi.c
index 06fcdf22990b..7b2de5612964 100644
--- a/drivers/spi/spi-nxp-xspi.c
+++ b/drivers/spi/spi-nxp-xspi.c
@@ -958,7 +958,7 @@ static int nxp_xspi_do_op(struct nxp_xspi *xspi, const struct spi_mem_op *op)
 		writel(reg, base + XSPI_RBCT);
 	}
 
-	init_completion(&xspi->c);
+	reinit_completion(&xspi->c);
 
 	/* Config the data address */
 	writel(op->addr.val + xspi->memmap_phy, base + XSPI_SFP_TG_SFAR);
@@ -1273,6 +1273,8 @@ static int nxp_xspi_probe(struct platform_device *pdev)
 
 	nxp_xspi_default_setup(xspi);
 
+	init_completion(&xspi->c);
+
 	ret = devm_request_irq(dev, irq,
 			nxp_xspi_irq_handler, 0, pdev->name, xspi);
 	if (ret)

---
base-commit: d517cb8cea012f43b069617fc8179b45404f8018
change-id: 20260303-spi-nxp-d70b97a8df08

Best regards,
-- 
Felix Gu <ustc.gu@gmail.com>
Re: [PATCH] spi: nxp-xspi: Use reinit_completion() for repeated operations
Posted by Frank Li 1 month ago
From: Frank Li (AI-BOT) <frank.li@nxp.com>

Subject: Re: [PATCH] spi: nxp-xspi: Use reinit_completion() for repeated
operations

> -	init_completion(&xspi->c);
> +	reinit_completion(&xspi->c);

Good catch. This is the correct pattern for repeated operations on the
same completion object.

> +	init_completion(&xspi->c);
> +
> 	ret = devm_request_irq(dev, irq,

Looks good. Initialization happens once at probe time, then
reinit_completion() resets the state for each operation.

One minor note: the blank line after init_completion() is unnecessary
per coding style. Consider removing it to keep the probe function
compact.

> Fixes: 29c8c00d9f9d ("spi: add driver for NXP XSPI controller")

Commit message has a typo: "perations" should be "operations". Please
fix before sending.

Overall the change is sound. Moving initialization to probe and using
reinit_completion() in the hot path is the recommended pattern.

AI bot review and may be useless.