summaryrefslogtreecommitdiff
path: root/src/commonlib/include
diff options
context:
space:
mode:
authorNico Huber <nico.h@gmx.de>2024-01-14 14:26:37 +0100
committerJulius Werner <jwerner@chromium.org>2024-08-23 01:08:16 +0000
commit41feb32559d574e7e08f42742dc4ef8abc3ddd46 (patch)
tree3ebbce83ef7805f80c94240d9cde356cf944694a /src/commonlib/include
parent7bb8de184338453cde924c816e027af5eae40d32 (diff)
region: Turn region_end() into an inclusive region_last()
The current region_end() implementation is susceptible to overflow if the region is at the end of the addressable space. A common case with the memory-mapped flash of x86 directly below the 32-bit limit. Note: This patch also changes console output to inclusive limits. IMO, to the better. Change-Id: Ic4bd6eced638745b7e845504da74542e4220554a Signed-off-by: Nico Huber <nico.h@gmx.de> Reviewed-on: https://review.coreboot.org/c/coreboot/+/79946 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Julius Werner <jwerner@chromium.org>
Diffstat (limited to 'src/commonlib/include')
-rw-r--r--src/commonlib/include/commonlib/region.h12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/commonlib/include/commonlib/region.h b/src/commonlib/include/commonlib/region.h
index 84717979e7..e066ea0eb6 100644
--- a/src/commonlib/include/commonlib/region.h
+++ b/src/commonlib/include/commonlib/region.h
@@ -124,15 +124,15 @@ static inline size_t region_sz(const struct region *r)
return r->size;
}
-static inline size_t region_end(const struct region *r)
+static inline size_t region_last(const struct region *r)
{
- return region_offset(r) + region_sz(r);
+ return region_offset(r) + (region_sz(r) - 1);
}
static inline bool region_overlap(const struct region *r1, const struct region *r2)
{
- return (region_end(r1) > region_offset(r2)) &&
- (region_offset(r1) < region_end(r2));
+ return (region_last(r1) >= region_offset(r2)) &&
+ (region_offset(r1) <= region_last(r2));
}
/* Helper to dynamically initialize region device. */
@@ -156,9 +156,9 @@ static inline size_t region_device_offset(const struct region_device *rdev)
return region_offset(region_device_region(rdev));
}
-static inline size_t region_device_end(const struct region_device *rdev)
+static inline size_t region_device_last(const struct region_device *rdev)
{
- return region_end(region_device_region(rdev));
+ return region_last(region_device_region(rdev));
}
/* Memory map entire region device. Same semantics as rdev_mmap() above. */