diff --git a/lib/idr.c b/lib/idr.c
index c4afd94bdf69abd2a09ff4e75222592d976a796c..36ff732fd2a6dca0847373d7b3a45048c2f0d0f7 100644
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -1048,7 +1048,7 @@ void ida_remove(struct ida *ida, int id)
 	__clear_bit(n, p->bitmap);
 
 	bitmap = (void *)p->ary[n];
-	if (!test_bit(offset, bitmap->bitmap))
+	if (!bitmap || !test_bit(offset, bitmap->bitmap))
 		goto err;
 
 	/* update bitmap and remove it if empty */