# Re: \[PATCH\] drm/panfrost: Update io-pgtable API

- From: Robin Murphy \<robin.murphy@arm.com\>
- Date: 2022-08-23 10:43:50 
- List: linux-arm-kernel
- Page: https://ratatoskr.run/linux-arm-kernel/2022/08/8825943
- Thread: https://ratatoskr.run/dri-devel/2022/08/8825921/t.md

```text
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.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
```
