mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] spi: sprd-adi: Fix probe succeeding without registering the controller
@ 2026-07-26  7:22 Babanpreet Singh
  2026-07-27  6:09 ` Baolin Wang
  0 siblings, 1 reply; 2+ messages in thread
From: Babanpreet Singh @ 2026-07-26  7:22 UTC (permalink / raw)
  To: Mark Brown
  Cc: Orson Zhai, Baolin Wang, Chunyan Zhang, linux-spi, linux-kernel,
	Babanpreet Singh

With CONFIG_HWSPINLOCK=n the of_hwspin_lock_get_id() stub returns 0
unconditionally. In sprd_adi_probe() the guard

	if (ret > 0 || (IS_ENABLED(CONFIG_HWSPINLOCK) && ret == 0))

is false for that 0, so it takes the else branch, where the switch has no
case for 0 and lands in

	default:
		return dev_err_probe(&pdev->dev, ret, "failed to find hwlock id\n");

dev_err_probe() returns its err argument unchanged, so probe logs
"failed to find hwlock id" and then returns 0, reporting success.
sprd_adi_hw_init(), the restart handler and devm_spi_register_controller()
are all skipped: the device binds but no SPI controller is ever
registered. Since the stub is a constant-returning static inline, the
compiler folds the whole remainder of probe away as dead code - an
object built in that configuration contains no reference to
devm_spi_register_controller() at all.

The hardware spinlock is optional for this controller and the -ENOENT arm
already covers "no hardware spinlock supplied". Treat the stub's 0 the
same way and continue without a lock; all four users of sadi->hwlock
already test it for NULL.

This is not reachable on production kernels. Kconfig has

	depends on HWSPINLOCK || (COMPILE_TEST && !HWSPINLOCK)

so the affected configuration exists only under COMPILE_TEST, where no
real hardware is present. Object code for CONFIG_HWSPINLOCK=y builds is
byte-identical before and after this change.

Found by smatch:
drivers/spi/spi-sprd-adi.c:560 sprd_adi_probe() warn: passing zero to 'dev_err_probe'

Fixes: f9adf61e983f ("spi: sprd: adi: Change hwlock to be optional")
Assisted-by: Claude:claude-opus-5
Signed-off-by: Babanpreet Singh <bbnpreetsingh@gmail.com>
---
 drivers/spi/spi-sprd-adi.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/spi/spi-sprd-adi.c b/drivers/spi/spi-sprd-adi.c
index e7d83c16b46c..7c29115c5b8b 100644
--- a/drivers/spi/spi-sprd-adi.c
+++ b/drivers/spi/spi-sprd-adi.c
@@ -553,6 +553,11 @@ static int sprd_adi_probe(struct platform_device *pdev)
 			return -ENXIO;
 	} else {
 		switch (ret) {
+		case 0:
+			/*
+			 * Only reachable with CONFIG_HWSPINLOCK=n, where the
+			 * of_hwspin_lock_get_id() stub returns 0.
+			 */
 		case -ENOENT:
 			dev_info(&pdev->dev, "no hardware spinlock supplied\n");
 			break;
-- 
2.43.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] spi: sprd-adi: Fix probe succeeding without registering the controller
  2026-07-26  7:22 [PATCH] spi: sprd-adi: Fix probe succeeding without registering the controller Babanpreet Singh
@ 2026-07-27  6:09 ` Baolin Wang
  0 siblings, 0 replies; 2+ messages in thread
From: Baolin Wang @ 2026-07-27  6:09 UTC (permalink / raw)
  To: Babanpreet Singh, Mark Brown
  Cc: Orson Zhai, Chunyan Zhang, linux-spi, linux-kernel



On 7/26/26 3:22 PM, Babanpreet Singh wrote:
> With CONFIG_HWSPINLOCK=n the of_hwspin_lock_get_id() stub returns 0
> unconditionally. In sprd_adi_probe() the guard
> 
> 	if (ret > 0 || (IS_ENABLED(CONFIG_HWSPINLOCK) && ret == 0))
> 
> is false for that 0, so it takes the else branch, where the switch has no
> case for 0 and lands in
> 
> 	default:
> 		return dev_err_probe(&pdev->dev, ret, "failed to find hwlock id\n");
> 
> dev_err_probe() returns its err argument unchanged, so probe logs
> "failed to find hwlock id" and then returns 0, reporting success.
> sprd_adi_hw_init(), the restart handler and devm_spi_register_controller()
> are all skipped: the device binds but no SPI controller is ever
> registered. Since the stub is a constant-returning static inline, the
> compiler folds the whole remainder of probe away as dead code - an
> object built in that configuration contains no reference to
> devm_spi_register_controller() at all.
> 
> The hardware spinlock is optional for this controller and the -ENOENT arm
> already covers "no hardware spinlock supplied". Treat the stub's 0 the
> same way and continue without a lock; all four users of sadi->hwlock
> already test it for NULL.
> 
> This is not reachable on production kernels. Kconfig has
> 
> 	depends on HWSPINLOCK || (COMPILE_TEST && !HWSPINLOCK)
> 
> so the affected configuration exists only under COMPILE_TEST, where no
> real hardware is present. Object code for CONFIG_HWSPINLOCK=y builds is
> byte-identical before and after this change.
> 
> Found by smatch:
> drivers/spi/spi-sprd-adi.c:560 sprd_adi_probe() warn: passing zero to 'dev_err_probe'
> 
> Fixes: f9adf61e983f ("spi: sprd: adi: Change hwlock to be optional")
> Assisted-by: Claude:claude-opus-5
> Signed-off-by: Babanpreet Singh <bbnpreetsingh@gmail.com>
> ---
>   drivers/spi/spi-sprd-adi.c | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/spi/spi-sprd-adi.c b/drivers/spi/spi-sprd-adi.c
> index e7d83c16b46c..7c29115c5b8b 100644
> --- a/drivers/spi/spi-sprd-adi.c
> +++ b/drivers/spi/spi-sprd-adi.c
> @@ -553,6 +553,11 @@ static int sprd_adi_probe(struct platform_device *pdev)
>   			return -ENXIO;
>   	} else {
>   		switch (ret) {
> +		case 0:
> +			/*
> +			 * Only reachable with CONFIG_HWSPINLOCK=n, where the
> +			 * of_hwspin_lock_get_id() stub returns 0.
> +			 */

Please add a 'fallthrough' here. With that, you can add:

Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>

>   		case -ENOENT:
>   			dev_info(&pdev->dev, "no hardware spinlock supplied\n");
>   			break;


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-27  6:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-26  7:22 [PATCH] spi: sprd-adi: Fix probe succeeding without registering the controller Babanpreet Singh
2026-07-27  6:09 ` Baolin Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®