Spotted by Suparna: if the first range check fails, we leak a ref on the io
context.
struct kioctx *ioctx = lookup_ioctx(ctx_id);
long ret = -EINVAL;
- if (unlikely(min_nr > nr || min_nr < 0 || nr < 0))
- return ret;
-
- if (likely(NULL != ioctx)) {
- ret = read_events(ioctx, min_nr, nr, events, timeout);
+ if (likely(ioctx)) {
+ if (likely(min_nr <= nr && min_nr >= 0 && nr >= 0))
+ ret = read_events(ioctx, min_nr, nr, events, timeout);
put_ioctx(ioctx);
}