Skip to content

Commit 59bf37a

Browse files
committed
drm/i915: document range_overflows() and range_end_overflows() macros
Document the macros in preparation for making them more generally available. Cc: Kees Cook <kees@kernel.org> Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org> Cc: linux-hardening@vger.kernel.org Reviewed-by: Jouni Högander <jouni.hogander@intel.com> Link: https://lore.kernel.org/r/20250829174601.2163064-2-jani.nikula@intel.com Signed-off-by: Jani Nikula <jani.nikula@intel.com>
1 parent 1e4c851 commit 59bf37a

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

drivers/gpu/drm/i915/i915_utils.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ bool i915_error_injected(void);
6767
drm_err(&(i915)->drm, fmt, ##__VA_ARGS__); \
6868
})
6969

70+
/**
71+
* range_overflows() - Check if a range is out of bounds
72+
* @start: Start of the range.
73+
* @size: Size of the range.
74+
* @max: Exclusive upper boundary.
75+
*
76+
* A strict check to determine if the range [@start, @start + @size) is
77+
* invalid with respect to the allowable range [0, @max). Any range
78+
* starting at or beyond @max is considered an overflow, even if @size is 0.
79+
*
80+
* Returns: true if the range is out of bounds.
81+
*/
7082
#define range_overflows(start, size, max) ({ \
7183
typeof(start) start__ = (start); \
7284
typeof(size) size__ = (size); \
@@ -76,9 +88,32 @@ bool i915_error_injected(void);
7688
start__ >= max__ || size__ > max__ - start__; \
7789
})
7890

91+
/**
92+
* range_overflows_t() - Check if a range is out of bounds
93+
* @type: Data type to use.
94+
* @start: Start of the range.
95+
* @size: Size of the range.
96+
* @max: Exclusive upper boundary.
97+
*
98+
* Same as range_overflows() but forcing the parameters to @type.
99+
*
100+
* Returns: true if the range is out of bounds.
101+
*/
79102
#define range_overflows_t(type, start, size, max) \
80103
range_overflows((type)(start), (type)(size), (type)(max))
81104

105+
/**
106+
* range_end_overflows() - Check if a range's endpoint is out of bounds
107+
* @start: Start of the range.
108+
* @size: Size of the range.
109+
* @max: Exclusive upper boundary.
110+
*
111+
* Checks only if the endpoint of a range (@start + @size) exceeds @max.
112+
* Unlike range_overflows(), a zero-sized range at the boundary (@start == @max)
113+
* is not considered an overflow. Useful for iterator-style checks.
114+
*
115+
* Returns: true if the endpoint exceeds the boundary.
116+
*/
82117
#define range_end_overflows(start, size, max) ({ \
83118
typeof(start) start__ = (start); \
84119
typeof(size) size__ = (size); \
@@ -88,6 +123,17 @@ bool i915_error_injected(void);
88123
start__ > max__ || size__ > max__ - start__; \
89124
})
90125

126+
/**
127+
* range_end_overflows_t() - Check if a range's endpoint is out of bounds
128+
* @type: Data type to use.
129+
* @start: Start of the range.
130+
* @size: Size of the range.
131+
* @max: Exclusive upper boundary.
132+
*
133+
* Same as range_end_overflows() but forcing the parameters to @type.
134+
*
135+
* Returns: true if the endpoint exceeds the boundary.
136+
*/
91137
#define range_end_overflows_t(type, start, size, max) \
92138
range_end_overflows((type)(start), (type)(size), (type)(max))
93139

0 commit comments

Comments
 (0)