On Thu, Apr 20, 2023, Jinrong Liang wrote:
From: Jinrong Liang cloudliang@tencent.com
From: Jinrong Liang cloudliang@tencent.com
Defined as type __u32, the nevents field in kvm_pmu_event_filter can only accept positive values within a specific range. Therefore, replacing int with uint32_t for nevents ensures consistency and readability in the code.
Not really. It fixes one type of inconsistency that is fairly common (userspace passing an integer count to the kernel), and replaces it with a different type of inconsistency (signed iterator comparing against an unsigned count). There's already one of those in remove_event(), but I'd rather not create more.
Passing an unsigned int to track what *should* be a small-ish, postive integer can also make it more difficult to detect bugs, e.g. assertions like this won't work:
TEST_ASSERT(nevents >= 0);
If this code were being written from scratch then I wouldn't object to using uint32_t everywhere, but I don't see the point of trying to retroactively change the code.