mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] spi: core: do not WARN on OOM spi_controller_id_alloc
@ 2026-10-31  2:39 Gowtham S Bhushan
  0 siblings, 0 replies; only message in thread
From: Gowtham S Bhushan @ 2026-10-31  2:39 UTC (permalink / raw)
  To: Mark Brown
  Cc: linux-spi, linux-kernel, Gowtham S Bhushan, syzbot+41172204e7323356ecdb

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

Signed-off-by: Gowtham S Bhushan <gowtham398gs@gmail.com>
---
 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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-10-31  2:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-31  2:39 [PATCH] spi: core: do not WARN on OOM spi_controller_id_alloc Gowtham S Bhushan

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®