[PATCH] spi: core: do not WARN on OOM spi_controller_id_alloc

From: Gowtham S Bhushan

Date: Fri Oct 30 2026 - 22:39:57 EST


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: syzbot+41172204e7323356ecdb@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=41172204e7323356ecdb
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Tested-by: syzbot+41172204e7323356ecdb@xxxxxxxxxxxxxxxxxxxxxxxxx

Signed-off-by: Gowtham S Bhushan <gowtham398gs@xxxxxxxxx>
---
drivers/spi/spi.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 40cda0037ea5..a1276d194465 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -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;
}
--
2.56.0