On Wed, Mar 7, 2018 at 2:08 AM, Laurent Vivier <laur...@vivier.eu> wrote: >> +static inline int guest_range_valid(unsigned long start, unsigned long len) >> +{ >> + if (len) >> + return guest_addr_valid(len - 1) && start <= GUEST_ADDR_MAX - len + >> 1; >> + else >> + return guest_addr_valid(start); >> +} > > I think we can consider len == 0 is invalid and use only: > > return start + (len - 1) <= GUEST_ADDR_MAX;
start + len - 1 may wrap around, that's why I first validate len and then have len at the right side of the comparison. I.e. if we drop check for len == 0 I'd still write it as guest_addr_valid(len - 1) && start <= GUEST_ADDR_MAX - len + 1; -- Thanks. -- Max