From 354bc0bab1cb6095592288674d375511443427fd Mon Sep 17 00:00:00 2001 From: David Gibson Date: Tue, 18 Feb 2025 13:07:18 +1100 Subject: packet: Don't pass start and offset separately to packet_check_range() Fundamentally what packet_check_range() does is to check whether a given memory range is within the allowed / expected memory set aside for packets from a particular pool. That range could represent a whole packet (from packet_add_do()) or part of a packet (from packet_get_do()), but it doesn't really matter which. However, we pass the start of the range as two parameters: @start which is the start of the packet, and @offset which is the offset within the packet of the range we're interested in. We never use these separately, only as (start + offset). Simplify the interface of packet_check_range() and vu_packet_check_range() to directly take the start of the relevant range. This will allow some additional future improvements. Signed-off-by: David Gibson Signed-off-by: Stefano Brivio --- vu_common.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'vu_common.c') diff --git a/vu_common.c b/vu_common.c index 48826b1..686a09b 100644 --- a/vu_common.c +++ b/vu_common.c @@ -26,14 +26,12 @@ * vu_packet_check_range() - Check if a given memory zone is contained in * a mapped guest memory region * @buf: Array of the available memory regions - * @offset: Offset of data range in packet descriptor + * @ptr: Start of desired data range * @size: Length of desired data range - * @start: Start of the packet descriptor * * Return: 0 if the zone is in a mapped memory region, -1 otherwise */ -int vu_packet_check_range(void *buf, size_t offset, size_t len, - const char *start) +int vu_packet_check_range(void *buf, const char *ptr, size_t len) { struct vu_dev_region *dev_region; @@ -41,9 +39,8 @@ int vu_packet_check_range(void *buf, size_t offset, size_t len, /* NOLINTNEXTLINE(performance-no-int-to-ptr) */ char *m = (char *)(uintptr_t)dev_region->mmap_addr; - if (m <= start && - start + offset + len <= m + dev_region->mmap_offset + - dev_region->size) + if (m <= ptr && + ptr + len <= m + dev_region->mmap_offset + dev_region->size) return 0; } -- cgit v1.2.3