Skip to content

Commit e8ae8ad

Browse files
neilbrowndavem330
authored andcommitted
Fix termination state for idr_for_each_entry_ul()
The comment for idr_for_each_entry_ul() states after normal termination @entry is left with the value NULL This is not correct in the case where UINT_MAX has an entry in the idr. In that case @entry will be non-NULL after termination. No current code depends on the documentation being correct, but to save future code we should fix it. Also fix idr_for_each_entry_continue_ul(). While this is not documented as leaving @entry as NULL, the mellanox driver appears to depend on it doing so. So make that explicit in the documentation as well as in the code. Fixes: e33d2b7 ("idr: fix overflow case for idr_for_each_entry_ul()") Cc: Matthew Wilcox <willy@infradead.org> Cc: Chris Mi <chrism@mellanox.com> Cc: Cong Wang <xiyou.wangcong@gmail.com> Signed-off-by: NeilBrown <neilb@suse.de> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent efa5f13 commit e8ae8ad

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

include/linux/idr.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ static inline void idr_preload_end(void)
200200
*/
201201
#define idr_for_each_entry_ul(idr, entry, tmp, id) \
202202
for (tmp = 0, id = 0; \
203-
tmp <= id && ((entry) = idr_get_next_ul(idr, &(id))) != NULL; \
203+
((entry) = tmp <= id ? idr_get_next_ul(idr, &(id)) : NULL) != NULL; \
204204
tmp = id, ++id)
205205

206206
/**
@@ -224,10 +224,12 @@ static inline void idr_preload_end(void)
224224
* @id: Entry ID.
225225
*
226226
* Continue to iterate over entries, continuing after the current position.
227+
* After normal termination @entry is left with the value NULL. This
228+
* is convenient for a "not found" value.
227229
*/
228230
#define idr_for_each_entry_continue_ul(idr, entry, tmp, id) \
229231
for (tmp = id; \
230-
tmp <= id && ((entry) = idr_get_next_ul(idr, &(id))) != NULL; \
232+
((entry) = tmp <= id ? idr_get_next_ul(idr, &(id)) : NULL) != NULL; \
231233
tmp = id, ++id)
232234

233235
/*

0 commit comments

Comments
 (0)