Skip to contentSkip to conversation

spi: nxp: Use reinit_completion() for repeated operations

PATCH In review Felix Gu 6 participants 11 messages Mar 4 – Mar 9

Subsystems (5)
lore
Share & tools
lore

Felix Gu

author
#0 lore raw

v2 cover spi: nxp: Use reinit_completion() for repeated operations

---
Changes in v2:
- Fix Frank's comments.
- Fix for spi-nxp-fspi.c and spi-fsl-qspi.c suggested by Bough.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Felix Gu (3):
spi: nxp-xspi: Use reinit_completion() for repeated operations
spi: nxp-fspi: Use reinit_completion() for repeated operations
spi: fsl-qspi: Use reinit_completion() for repeated operations

 drivers/spi/spi-fsl-qspi.c | 3 ++-
 drivers/spi/spi-nxp-fspi.c | 3 ++-
 drivers/spi/spi-nxp-xspi.c | 3 ++-
 3 files changed, 6 insertions(+), 3 deletions(-)

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

Best regards,

Signature · 1 line
Felix Gu <[email protected]>
author
#1 lore raw

PATCH v2 1/3 spi: nxp-xspi: Use reinit_completion() for repeated operations

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 operations.

Fixes 29c8c00d9f9d ("spi: add driver for NXP XSPI controller")
---
 drivers/spi/spi-nxp-xspi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/spi/spi-nxp-xspi.c +2 -1
index 06fcdf22990b..385302a6e62f 100644
@@ -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,7 @@ 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)
Signature · 1 line
2.43.0
author
#4 lore raw

PATCH v2 2/3 spi: nxp-fspi: Use reinit_completion() for repeated operations

In reply to Felix Gu

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 operations.

Fixes a5356aef6a90 ("spi: spi-mem: Add driver for NXP FlexSPI controller")
---
 drivers/spi/spi-nxp-fspi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/spi/spi-nxp-fspi.c +2 -1
index 320b3d93df57..1e36ae084dd8 100644
@@ -996,7 +996,7 @@ static int nxp_fspi_do_op(struct nxp_fspi *f, const struct spi_mem_op *op)
 	reg = reg | FSPI_IPRXFCR_CLR;
 	fspi_writel(f, reg, base + FSPI_IPRXFCR);
 
-	init_completion(&f->c);
+	reinit_completion(&f->c);
 
 	fspi_writel(f, op->addr.val, base + FSPI_IPCR0);
 	/*
@@ -1365,6 +1365,7 @@ static int nxp_fspi_probe(struct platform_device *pdev)
 	if (ret < 0)
 		return dev_err_probe(dev, ret, "Failed to disable clock");
 
+	init_completion(&f->c);
 	ret = devm_request_irq(dev, irq,
 			nxp_fspi_irq_handler, 0, pdev->name, f);
 	if (ret)
Signature · 1 line
2.43.0
author
#7 lore raw

PATCH v2 3/3 spi: fsl-qspi: Use reinit_completion() for repeated operations

In reply to Felix Gu

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 operations.

Fixes 84d043185dbe ("spi: Add a driver for the Freescale/NXP QuadSPI controller")
---
 drivers/spi/spi-fsl-qspi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/spi/spi-fsl-qspi.c +2 -1
index a223b4bc6e63..57358851029b 100644
@@ -633,7 +633,7 @@ static int fsl_qspi_do_op(struct fsl_qspi *q, const struct spi_mem_op *op)
 	void __iomem *base = q->iobase;
 	int err = 0;
 
-	init_completion(&q->c);
+	reinit_completion(&q->c);
 
 	/*
 	 * Always start the sequence at the same index since we update
@@ -965,6 +965,7 @@ static int fsl_qspi_probe(struct platform_device *pdev)
 	if (ret < 0)
 		return ret;
 
+	init_completion(&q->c);
 	ret = devm_request_irq(dev, ret,
 			fsl_qspi_irq_handler, 0, pdev->name, q);
 	if (ret) {
Signature · 1 line
2.43.0
maintainer
#2 lore raw

Re: [PATCH v2 1/3] spi: nxp-xspi: Use reinit_completion() for repeated operations

In reply to Felix Gu

From: Frank Li (AI-BOT) <[email protected]>

Typo in commit message:

Quoted 1 line

Tchnically it may work, but it's not the recommended pattern.

Should be "Technically" (missing 'e').

---

Quoted 1 line

So moves the initial initialization to probe function and uses

Should be "So move the initial initialization..." or "This moves the initial initialization..." (subject-verb agreement).

---

AI bot review and may be useless.

maintainer
#8 lore raw

Re: [PATCH v2 3/3] spi: fsl-qspi: Use reinit_completion() for repeated operations

In reply to Felix Gu

From: Frank Li (AI-BOT) <[email protected]>

Commit message has a typo:

Quoted 1 line

Tchnically it may work, but it's not the recommended pattern.

Should be "Technically".

Also, the placement of init_completion() in the probe function should come before devm_request_irq(), since the IRQ handler may reference the completion object. The current placement is correct, but consider adding a comment explaining why the initialization must happen before IRQ registration.

Otherwise the patch looks good.

AI bot review and may be useless.

maintainer
#3 lore raw

Re: [PATCH v2 1/3] spi: nxp-xspi: Use reinit_completion() for repeated operations

In reply to Felix Gu
Quoted 3 lines · Felix Gu

The driver currently calls init_completion() during every spi_mem_op. Tchnically it may work, but it's not the recommended pattern.

Typo, Technically.

Quoted 42 lines

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 operations.

Fixes 29c8c00d9f9d ("spi: add driver for NXP XSPI controller")
---
 drivers/spi/spi-nxp-xspi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/spi/spi-nxp-xspi.c +2 -2
index 06fcdf22990b..385302a6e62f 100644
@@ -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,7 @@ 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)
 
--

2.43.0

#5 lore raw

Re: [PATCH v2 2/3] spi: nxp-fspi: Use reinit_completion() for repeated operations

In reply to Felix Gu
Quoted 43 lines · On Wed, 04 Mar 2026 20:47:20 +0800 Felix Gu wrote:

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 operations.

Fixes a5356aef6a90 ("spi: spi-mem: Add driver for NXP FlexSPI controller")
---
 drivers/spi/spi-nxp-fspi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/spi/spi-nxp-fspi.c +2 -1
index 320b3d93df57..1e36ae084dd8 100644
@@ -996,7 +996,7 @@ static int nxp_fspi_do_op(struct nxp_fspi *f, const struct spi_mem_op *op)
 	reg = reg | FSPI_IPRXFCR_CLR;
 	fspi_writel(f, reg, base + FSPI_IPRXFCR);
 
-	init_completion(&f->c);
+	reinit_completion(&f->c);
 
 	fspi_writel(f, op->addr.val, base + FSPI_IPCR0);
 	/*
@@ -1365,6 +1365,7 @@ static int nxp_fspi_probe(struct platform_device *pdev)
 	if (ret < 0)
 		return dev_err_probe(dev, ret, "Failed to disable clock");
 
+	init_completion(&f->c);
 	ret = devm_request_irq(dev, irq,
 			nxp_fspi_irq_handler, 0, pdev->name, f);
 	if (ret)
Signature · 2 lines
-- 
2.43.0

After this work relevant code in nxp_fspi_exec_op() looks like

	guard(mutex)(&f->lock);
	nxp_fspi_do_op()
	  reinit_completion(&f->c);
	  /* Wait for the interrupt. */
	  if (!wait_for_completion_timeout(&f->c, msecs_to_jiffies(1000)))
		err = -ETIMEDOUT;

and if __no__ interrupt could fire after the 1000ms timeout, no reinit is needed at all. Otherwise reinit alone fails to work.

Important is -- show the evidence that no chance is left for the timeout.

BTW the same applies to other patches in this series?

maintainer Reviewed-by on v2 2/3
#6 lore raw

RE: [PATCH v2 2/3] spi: nxp-fspi: Use reinit_completion() for repeated operations

In reply to Felix Gu
Quoted 16 lines

-----Original Message-----
From: Felix Gu <[email protected]>
Sent: 2026年3月4日 20:47
To: Han Xu <[email protected]>; Bough Chen <[email protected]>; Mark Brown <[email protected]>; Frank Li <[email protected]>; Yogesh Gaur <[email protected]>; Yogesh Narayan Gaur <[email protected]>; Boris Brezillon <[email protected]>; Frieder Schrempf <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Felix Gu <[email protected]>
Subject: [PATCH v2 2/3] spi: nxp-fspi: Use reinit_completion() for repeated operations

The driver currently calls init_completion() during every spi_mem_op. Tchnically it may work, but it's not the recommended pattern.

Quoted 7 lines

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 operations.

Regards
Haibo Chen

Quoted 33 lines
Fixes a5356aef6a90 ("spi: spi-mem: Add driver for NXP FlexSPI controller")
---
 drivers/spi/spi-nxp-fspi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/spi/spi-nxp-fspi.c index renamed from drivers/spi/spi-nxp-fspi.c +0 -0

320b3d93df57..1e36ae084dd8 100644

drivers/spi/spi-nxp-fspi.c +1 -1
@@ -996,7 +996,7 @@ static int nxp_fspi_do_op(struct nxp_fspi *f, const struct
 spi_mem_op *op)
 	reg = reg | FSPI_IPRXFCR_CLR;
 	fspi_writel(f, reg, base + FSPI_IPRXFCR);
 
-	init_completion(&f->c);
+	reinit_completion(&f->c);
 
 	fspi_writel(f, op->addr.val, base + FSPI_IPCR0);
drivers/spi/spi-nxp-fspi.c +1 -0
 	/*
@@ -1365,6 +1365,7 @@ static int nxp_fspi_probe(struct platform_device
 *pdev)
 	if (ret < 0)
 		return dev_err_probe(dev, ret, "Failed to disable clock");
 
+	init_completion(&f->c);
 	ret = devm_request_irq(dev, irq,
 			nxp_fspi_irq_handler, 0, pdev->name, f);

if (ret)

--
2.43.0

maintainer Reviewed-by on v2 3/3
#9 lore raw

RE: [PATCH v2 3/3] spi: fsl-qspi: Use reinit_completion() for repeated operations

In reply to Felix Gu
Quoted 16 lines

-----Original Message-----
From: Felix Gu <[email protected]>
Sent: 2026年3月4日 20:47
To: Han Xu <[email protected]>; Bough Chen <[email protected]>; Mark Brown <[email protected]>; Frank Li <[email protected]>; Yogesh Gaur <[email protected]>; Yogesh Narayan Gaur <[email protected]>; Boris Brezillon <[email protected]>; Frieder Schrempf <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Felix Gu <[email protected]>
Subject: [PATCH v2 3/3] spi: fsl-qspi: Use reinit_completion() for repeated operations

The driver currently calls init_completion() during every spi_mem_op. Tchnically it may work, but it's not the recommended pattern.

Quoted 7 lines

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 operations.

Regards
Haibo Chen

Quoted 34 lines
Fixes 84d043185dbe ("spi: Add a driver for the Freescale/NXP QuadSPI

controller")

---
 drivers/spi/spi-fsl-qspi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/spi/spi-fsl-qspi.c index renamed from drivers/spi/spi-fsl-qspi.c +0 -0

a223b4bc6e63..57358851029b 100644

drivers/spi/spi-fsl-qspi.c +1 -1
@@ -633,7 +633,7 @@ static int fsl_qspi_do_op(struct fsl_qspi *q, const struct
 spi_mem_op *op)
 	void __iomem *base = q->iobase;
 	int err = 0;
 
-	init_completion(&q->c);
+	reinit_completion(&q->c);
 
 	/*
drivers/spi/spi-fsl-qspi.c +1 -2
 	 * Always start the sequence at the same index since we update @@
-965,6 +965,7 @@ static int fsl_qspi_probe(struct platform_device *pdev)
 	if (ret < 0)
 		return ret;
 
+	init_completion(&q->c);
 	ret = devm_request_irq(dev, ret,
 			fsl_qspi_irq_handler, 0, pdev->name, q);
 	if (ret) {
 
--

2.43.0

maintainer
#10 lore raw
In reply to Felix Gu
Quoted 1 line · Felix Gu

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[1/3] spi: nxp-xspi: Use reinit_completion() for repeated operations

      commit: 40f9bc646db5aa89fb85f2cda1e55a2bf9d6a30c
[2/3] spi: nxp-fspi: Use reinit_completion() for repeated operations
      commit: 68c8c93fdb0de7e528dc3dfb1d17eb0f652259b8
[3/3] spi: fsl-qspi: Use reinit_completion() for repeated operations
      commit: 981b080a79724738882b0af1c5bb7ade30d94f24

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark