Message ID | 1564451504-27906-1-git-send-email-yi.zhang@huawei.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [v2] aio: add timeout validity check for io_[p]getevents | expand |
On Tue, Jul 30, 2019 at 3:46 AM zhangyi (F) <yi.zhang@huawei.com> wrote: > { > - ktime_t until = ts ? timespec64_to_ktime(*ts) : KTIME_MAX; > - struct kioctx *ioctx = lookup_ioctx(ctx_id); > + ktime_t until = KTIME_MAX; > + struct kioctx *ioctx = NULL; > long ret = -EINVAL; > > + if (ts) { > + if (!timespec64_valid(ts)) > + return ret; > + until = timespec64_to_ktime(*ts); > + } The man page should probably get updated as well to reflect that this will now return -EINVAL for a negative timeout or malformed nanoseconds. Arnd
On 2019/7/30 15:11, Arnd Bergmann Wrote: > On Tue, Jul 30, 2019 at 3:46 AM zhangyi (F) <yi.zhang@huawei.com> wrote: > >> { >> - ktime_t until = ts ? timespec64_to_ktime(*ts) : KTIME_MAX; >> - struct kioctx *ioctx = lookup_ioctx(ctx_id); >> + ktime_t until = KTIME_MAX; >> + struct kioctx *ioctx = NULL; >> long ret = -EINVAL; >> >> + if (ts) { >> + if (!timespec64_valid(ts)) >> + return ret; >> + until = timespec64_to_ktime(*ts); >> + } > > The man page should probably get updated as well to reflect that this > will now return -EINVAL for a negative timeout or malformed > nanoseconds. > Thanks for your suggestion, I will add a patch to update the man page. Thanks, Yi.
diff --git a/fs/aio.c b/fs/aio.c index 01e0fb9..dd967a0 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -2031,10 +2031,17 @@ static long do_io_getevents(aio_context_t ctx_id, struct io_event __user *events, struct timespec64 *ts) { - ktime_t until = ts ? timespec64_to_ktime(*ts) : KTIME_MAX; - struct kioctx *ioctx = lookup_ioctx(ctx_id); + ktime_t until = KTIME_MAX; + struct kioctx *ioctx = NULL; long ret = -EINVAL; + if (ts) { + if (!timespec64_valid(ts)) + return ret; + until = timespec64_to_ktime(*ts); + } + + ioctx = lookup_ioctx(ctx_id); if (likely(ioctx)) { if (likely(min_nr <= nr && min_nr >= 0)) ret = read_events(ioctx, min_nr, nr, events, until);