Skip to contentSkip to conversation

spi: sprd-adi: Fix probe succeeding without registering the controller

PATCH In review Babanpreet Singh 2 participants 2 messages Jul 29 – Aug 11

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 spi: sprd-adi: Fix probe succeeding without registering the controller

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.

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.

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

---
Changes in v2:
- Add the fallthrough; Baolin Wang asked for [1], and carry his Reviewed-by. The v1 case carried only a comment, so gcc's -Wimplicit-fallthrough never fired and W=1 was clean either way; this makes the intent explicit rather than fixing a warning.
- Trim two sentences of build-verification detail out of the changelog.

v1: https://lore.kernel.org/all/[email protected]/
[1] https://lore.kernel.org/all/[email protected]/

 drivers/spi/spi-sprd-adi.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/spi/spi-sprd-adi.c +6 -0
index e7d83c16b46c..a6baaf02b3c8 100644
@@ -553,6 +553,12 @@ 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.
+			 */
+			fallthrough;
 		case -ENOENT:
 			dev_info(&pdev->dev, "no hardware spinlock supplied\n");
 			break;
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 1 line · Babanpreet Singh

spi: sprd-adi: Fix probe succeeding without registering the controller

Applied to

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

Thanks!

[1/1] spi: sprd-adi: Fix probe succeeding without registering the controller

      https://git.kernel.org/broonie/spi/c/f092e1c93501

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