summaryrefslogtreecommitdiff
path: root/tools/include/linux/overflow.h
diff options
context:
space:
mode:
authorMaxime Ripard <mripard@kernel.org>2026-03-30 11:05:36 +0300
committerMaxime Ripard <mripard@kernel.org>2026-03-30 11:05:36 +0300
commit6fdfd24017756bbe27ccc786051e97f3bf0c3d62 (patch)
tree2f826d4f094a9edce9872d284172b6c5d3f7c063 /tools/include/linux/overflow.h
parent3bce3fdd1ff2ba242f76ab66659fff27207299f1 (diff)
parent7aaa8047eafd0bd628065b15757d9b48c5f9c07d (diff)
downloadlinux-6fdfd24017756bbe27ccc786051e97f3bf0c3d62.tar.xz
Merge drm/drm-fixes into drm-misc-next-fixes
Boris needs 7.0-rc6 for a shmem helper fix. Signed-off-by: Maxime Ripard <mripard@kernel.org>
Diffstat (limited to 'tools/include/linux/overflow.h')
-rw-r--r--tools/include/linux/overflow.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/tools/include/linux/overflow.h b/tools/include/linux/overflow.h
index dcb0c1bf6866..3427d7880326 100644
--- a/tools/include/linux/overflow.h
+++ b/tools/include/linux/overflow.h
@@ -69,6 +69,25 @@
})
/**
+ * size_mul() - Calculate size_t multiplication with saturation at SIZE_MAX
+ * @factor1: first factor
+ * @factor2: second factor
+ *
+ * Returns: calculate @factor1 * @factor2, both promoted to size_t,
+ * with any overflow causing the return value to be SIZE_MAX. The
+ * lvalue must be size_t to avoid implicit type conversion.
+ */
+static inline size_t __must_check size_mul(size_t factor1, size_t factor2)
+{
+ size_t bytes;
+
+ if (check_mul_overflow(factor1, factor2, &bytes))
+ return SIZE_MAX;
+
+ return bytes;
+}
+
+/**
* array_size() - Calculate size of 2-dimensional array.
*
* @a: dimension one