From: Jani Nikula <jani.nikula@intel.com>
To: Kees Cook <kees@kernel.org>, Jani Nikula <jani.nikula@intel.com>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>,
linux-hardening@vger.kernel.org, intel-gfx@lists.freedesktop.org
Subject: [RFC] drm/i915/utils: document range_overflows*() macros
Date: Wed, 4 Jun 2025 11:59:00 +0300 [thread overview]
Message-ID: <20250604085900.819259-1-jani.nikula@intel.com> (raw)
In-Reply-To: <202506021119.8FD6339F@keescook>
In preparation for moving the range check macros to
include/linux/overflow.h, document them properly.
Cc: Kees Cook <kees@kernel.org>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
I can squash this into actually moving the macros, I just want to
solicit feedback for the documentation first.
---
drivers/gpu/drm/i915/i915_utils.h | 45 +++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/drivers/gpu/drm/i915/i915_utils.h b/drivers/gpu/drm/i915/i915_utils.h
index f7fb40cfdb70..79127f01f887 100644
--- a/drivers/gpu/drm/i915/i915_utils.h
+++ b/drivers/gpu/drm/i915/i915_utils.h
@@ -67,6 +67,19 @@ bool i915_error_injected(void);
drm_err(&(i915)->drm, fmt, ##__VA_ARGS__); \
})
+
+/**
+ * range_overflows() - Check if @start + @size > @max
+ * @start: start offset
+ * @size: length of the range
+ * @max: valid upper limit
+ *
+ * Helper for the common @start + @size > @max range or buffer overflow
+ * check. Return true if the addition exceeds max or overflows. Also return true
+ * if @start == @max, even if @size == 0.
+ *
+ * Returns: %true if the range overflows.
+ */
#define range_overflows(start, size, max) ({ \
typeof(start) start__ = (start); \
typeof(size) size__ = (size); \
@@ -76,9 +89,30 @@ bool i915_error_injected(void);
start__ >= max__ || size__ > max__ - start__; \
})
+/**
+ * range_overflows_t() - Check if @start + @size > @max
+ * @type: data type to use
+ * @start: start offset
+ * @size: length of the range
+ * @max: valid upper limit
+ *
+ * Same as range_overflows(), but using the specified @type.
+ *
+ * Returns: %true if the range overflows.
+ */
#define range_overflows_t(type, start, size, max) \
range_overflows((type)(start), (type)(size), (type)(max))
+/**
+ * range_overflows_end() - Check if @start + @size > @max
+ * @start: start offset
+ * @size: length of the range
+ * @max: valid upper limit
+ *
+ * Same as range_overflows(), but allow @start == @max when @size == 0.
+ *
+ * Returns: %true if the range overflows.
+ */
#define range_overflows_end(start, size, max) ({ \
typeof(start) start__ = (start); \
typeof(size) size__ = (size); \
@@ -88,6 +122,17 @@ bool i915_error_injected(void);
start__ > max__ || size__ > max__ - start__; \
})
+/**
+ * range_overflows_end_t() - Check if @start + @size > @max
+ * @type: data type to use
+ * @start: start offset
+ * @size: length of the range
+ * @max: valid upper limit
+ *
+ * Same as range_overflows_end(), but using the specified @type.
+ *
+ * Returns: %true if the range overflows.
+ */
#define range_overflows_end_t(type, start, size, max) \
range_overflows_end((type)(start), (type)(size), (type)(max))
--
2.39.5
next prev parent reply other threads:[~2025-06-04 8:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-30 7:44 i915 utils: range_overflows*() Jani Nikula
2025-05-30 17:28 ` Kees Cook
2025-06-02 13:10 ` Jani Nikula
2025-06-02 18:20 ` Kees Cook
2025-06-04 8:59 ` Jani Nikula [this message]
2025-06-04 9:25 ` ✗ Fi.CI.CHECKPATCH: warning for drm/i915/utils: document range_overflows*() macros Patchwork
2025-06-04 9:25 ` ✗ Fi.CI.SPARSE: " Patchwork
2025-06-04 9:49 ` ✓ i915.CI.BAT: success " Patchwork
2025-06-04 11:23 ` ✗ i915.CI.Full: failure " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250604085900.819259-1-jani.nikula@intel.com \
--to=jani.nikula@intel.com \
--cc=gustavoars@kernel.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox