Skip to contentSkip to conversation

spi: core: do not WARN on OOM spi_controller_id_alloc

PATCH In review Gowtham S Bhushan 2 participants 2 messages Oct 31 – Nov 2 SPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spi: core: do not WARN on OOM spi_controller_id_alloc

In spi_controller_id_alloc() (drivers/spi/spi.c), idr_alloc() can return -ENOMEM when radix tree memory allocation fails under memory pressure or fault injection. The function inappropriately invokes WARN(id < 0, "couldn't get idr") on any failure rather than handling expected runtime allocation errors silently.

Modify the error handling path to only trigger a WARN when the failure is due to reasons other than an out-of-memory condition (such as -ENOSPC).

Reported-by [email protected]
Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 drivers/spi/spi.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/spi/spi.c +10 -1
index 40cda0037ea5..a1276d194465 100644
@@ -3631,8 +3631,17 @@ static int spi_controller_id_alloc(struct spi_controller *ctlr, int start, int e
 	mutex_lock(&board_lock);
 	id = idr_alloc(&spi_controller_idr, ctlr, start, end, GFP_KERNEL);
 	mutex_unlock(&board_lock);
-	if (WARN(id < 0, "couldn't get idr"))
+
+	/*
+	 * Modify the error handling path to only trigger a WARN when the failure
+	 * is not due to an out-of-memory condition
+	 */
+
+	if (id < 0) {
+		WARN(id != -ENOMEM, "couldn't get idr");
 		return id == -ENOSPC ? -EBUSY : id;
+	}
+
 	ctlr->bus_num = id;
 	return 0;
 }
Signature · 1 line
2.56.0
maintainer
#1 lore raw
Quoted 1 line · Gowtham S Bhushan

spi: core: do not WARN on OOM spi_controller_id_alloc

Applied to

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

Thanks!

[1/1] spi: core: do not WARN on OOM spi_controller_id_alloc

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

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