Skip to content

Commit

Permalink
idr: Warn if old iterators see large IDs
Browse files Browse the repository at this point in the history
Now that the IDR can be used to store large IDs, it is possible somebody
might only partially convert their old code and use the iterators which
can only handle IDs up to INT_MAX.  It's probably unwise to show them a
truncated ID, so settle for spewing warnings to dmesg, and terminating
the iteration.

Signed-off-by: Matthew Wilcox <[email protected]>
  • Loading branch information
Matthew Wilcox committed Feb 6, 2018
1 parent 7a45757 commit 72fd6c7
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/idr.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ int idr_for_each(const struct idr *idr,
void __rcu **slot;

radix_tree_for_each_slot(slot, &idr->idr_rt, &iter, 0) {
int ret = fn(iter.index, rcu_dereference_raw(*slot), data);
int ret;

if (WARN_ON_ONCE(iter.index > INT_MAX))
break;
ret = fn(iter.index, rcu_dereference_raw(*slot), data);
if (ret)
return ret;
}
Expand Down Expand Up @@ -187,6 +191,9 @@ void *idr_get_next(struct idr *idr, int *nextid)
if (!slot)
return NULL;

if (WARN_ON_ONCE(iter.index > INT_MAX))
return NULL;

*nextid = iter.index;
return rcu_dereference_raw(*slot);
}
Expand Down

0 comments on commit 72fd6c7

Please sign in to comment.