On 2022-08-23 03:51, Alyssa Rosenzweig wrote:
-static size_t get_pgsize(u64 addr, size_t size)
+static size_t get_pgsize(u64 addr, size_t size, size_t *count)
  {
-       if (addr & (SZ_2M - 1) || size < SZ_2M)
-               return SZ_4K;
+       size_t blk_offset = -addr % SZ_2M;

addr is unsigned. if this is correct, it's magic.

Eh, it's just well-defined unsigned integer overflow. Take "SZ_2M - (addr % SZ_2M)", realise the first term can be anything that's zero modulo SZ_2M, including zero, then also that the operations can be done in either order to give the same result, and there you go.

Cheers,
Robin.

Reply via email to