which is simply rounding len up to the next largest page size. So whenbase is not page aligned, increase len by the left-over space at thebeginning, and then do the same calculation as above. (ie, pretendbase is page aligned, and instead count the excess at the beginning aspart of len.)

npages = ( (base & PAGE_MASK) + len + PAGE_SIZE - 1) / PAGE_SIZE;

As long as len < PAGE_MASK - PAGE_SIZE, we're safe from overflows.

(The above gives a different answer when len=0, but you guard for that.)