diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2025-02-18 13:07:18 +1100 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2025-02-18 08:43:12 +0100 |
commit | 354bc0bab1cb6095592288674d375511443427fd (patch) | |
tree | 71e8f82fd0847458a95e4e7b81a9f690de0ae4e7 /vu_common.c | |
parent | 0a51060f7ac3e1e1a9d87ffdb037b9c367a2a4d9 (diff) | |
download | passt-354bc0bab1cb6095592288674d375511443427fd.tar passt-354bc0bab1cb6095592288674d375511443427fd.tar.gz passt-354bc0bab1cb6095592288674d375511443427fd.tar.bz2 passt-354bc0bab1cb6095592288674d375511443427fd.tar.lz passt-354bc0bab1cb6095592288674d375511443427fd.tar.xz passt-354bc0bab1cb6095592288674d375511443427fd.tar.zst passt-354bc0bab1cb6095592288674d375511443427fd.zip |
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 <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'vu_common.c')
-rw-r--r-- | vu_common.c | 11 |
1 files changed, 4 insertions, 7 deletions
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; } |