[PATCH v3 01/17] lib: idr: avoid dangling else in idr_for_each_entry()

Jonas Rebmann jre at pengutronix.de
Thu Nov 6 07:17:58 PST 2025


The idr_for_each_entry() macro uses an if statement to update _entry and
_in in the loop body. This can lead to dangling else issues, or at least
a compiler warning of the potential thereof.

We build with -Werror=dangling-else in CI and that is triggered very
easily by this construct.

Move the loop body into an else to avoid this issue.

Reviewed-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
Signed-off-by: Jonas Rebmann <jre at pengutronix.de>
---
 include/linux/idr.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/idr.h b/include/linux/idr.h
index e726d17b59..206c006c62 100644
--- a/include/linux/idr.h
+++ b/include/linux/idr.h
@@ -41,7 +41,7 @@ struct idr {
 	     *tmp = iter ? list_next_entry(iter, list) : NULL;		\
 	     (iter && iter != (_idr)) || (_entry = NULL);		\
 	     iter = tmp, tmp = tmp ?  list_next_entry(tmp, list) : NULL)\
-	if ((_entry = iter->ptr, _id = iter->id, true))
+	if ((_entry = iter->ptr, _id = iter->id, false)) {} else
 
 struct idr *__idr_find(struct idr *head, int lookup_id);
 

-- 
2.51.2.535.g419c72cb8a




More information about the barebox mailing list