Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

+46
+46
drivers/gpu/drm/i915/i915_utils.h
··· 67 67 drm_err(&(i915)->drm, fmt, ##__VA_ARGS__); \ 68 68 }) 69 69 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 + */ 70 82 #define range_overflows(start, size, max) ({ \ 71 83 typeof(start) start__ = (start); \ 72 84 typeof(size) size__ = (size); \ ··· 88 76 start__ >= max__ || size__ > max__ - start__; \ 89 77 }) 90 78 79 + /** 80 + * range_overflows_t() - Check if a range is out of bounds 81 + * @type: Data type to use. 82 + * @start: Start of the range. 83 + * @size: Size of the range. 84 + * @max: Exclusive upper boundary. 85 + * 86 + * Same as range_overflows() but forcing the parameters to @type. 87 + * 88 + * Returns: true if the range is out of bounds. 89 + */ 91 90 #define range_overflows_t(type, start, size, max) \ 92 91 range_overflows((type)(start), (type)(size), (type)(max)) 93 92 93 + /** 94 + * range_end_overflows() - Check if a range's endpoint is out of bounds 95 + * @start: Start of the range. 96 + * @size: Size of the range. 97 + * @max: Exclusive upper boundary. 98 + * 99 + * Checks only if the endpoint of a range (@start + @size) exceeds @max. 100 + * Unlike range_overflows(), a zero-sized range at the boundary (@start == @max) 101 + * is not considered an overflow. Useful for iterator-style checks. 102 + * 103 + * Returns: true if the endpoint exceeds the boundary. 104 + */ 94 105 #define range_end_overflows(start, size, max) ({ \ 95 106 typeof(start) start__ = (start); \ 96 107 typeof(size) size__ = (size); \ ··· 123 88 start__ > max__ || size__ > max__ - start__; \ 124 89 }) 125 90 91 + /** 92 + * range_end_overflows_t() - Check if a range's endpoint 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_end_overflows() but forcing the parameters to @type. 99 + * 100 + * Returns: true if the endpoint exceeds the boundary. 101 + */ 126 102 #define range_end_overflows_t(type, start, size, max) \ 127 103 range_end_overflows((type)(start), (type)(size), (type)(max)) 128 104