Commit 3e19086f authored by Kees Cook's avatar Kees Cook

overflow: Adjust check_*_overflow() kern-doc to reflect results

The check_*_overflow() helpers will return results with potentially
wrapped-around values. These values have always been checked by the
selftests, so avoid the confusing language in the kern-doc. The idea of
"safe for use" was relative to the expectation of whether or not the
caller wants a wrapped value -- the calculation itself will always follow
arithmetic wrapping rules.
Reviewed-by: default avatarGustavo A. R. Silva <gustavoars@kernel.org>
Acked-by: default avatarMark Rutland <mark.rutland@arm.com>
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
parent adeb0436
...@@ -57,11 +57,10 @@ static inline bool __must_check __must_check_overflow(bool overflow) ...@@ -57,11 +57,10 @@ static inline bool __must_check __must_check_overflow(bool overflow)
* @b: second addend * @b: second addend
* @d: pointer to store sum * @d: pointer to store sum
* *
* Returns 0 on success. * Returns true on wrap-around, false otherwise.
* *
* *@d holds the results of the attempted addition, but is not considered * *@d holds the results of the attempted addition, regardless of whether
* "safe for use" on a non-zero return value, which indicates that the * wrap-around occurred.
* sum has overflowed or been truncated.
*/ */
#define check_add_overflow(a, b, d) \ #define check_add_overflow(a, b, d) \
__must_check_overflow(__builtin_add_overflow(a, b, d)) __must_check_overflow(__builtin_add_overflow(a, b, d))
...@@ -72,11 +71,10 @@ static inline bool __must_check __must_check_overflow(bool overflow) ...@@ -72,11 +71,10 @@ static inline bool __must_check __must_check_overflow(bool overflow)
* @b: subtrahend; value to subtract from @a * @b: subtrahend; value to subtract from @a
* @d: pointer to store difference * @d: pointer to store difference
* *
* Returns 0 on success. * Returns true on wrap-around, false otherwise.
* *
* *@d holds the results of the attempted subtraction, but is not considered * *@d holds the results of the attempted subtraction, regardless of whether
* "safe for use" on a non-zero return value, which indicates that the * wrap-around occurred.
* difference has underflowed or been truncated.
*/ */
#define check_sub_overflow(a, b, d) \ #define check_sub_overflow(a, b, d) \
__must_check_overflow(__builtin_sub_overflow(a, b, d)) __must_check_overflow(__builtin_sub_overflow(a, b, d))
...@@ -87,11 +85,10 @@ static inline bool __must_check __must_check_overflow(bool overflow) ...@@ -87,11 +85,10 @@ static inline bool __must_check __must_check_overflow(bool overflow)
* @b: second factor * @b: second factor
* @d: pointer to store product * @d: pointer to store product
* *
* Returns 0 on success. * Returns true on wrap-around, false otherwise.
* *
* *@d holds the results of the attempted multiplication, but is not * *@d holds the results of the attempted multiplication, regardless of whether
* considered "safe for use" on a non-zero return value, which indicates * wrap-around occurred.
* that the product has overflowed or been truncated.
*/ */
#define check_mul_overflow(a, b, d) \ #define check_mul_overflow(a, b, d) \
__must_check_overflow(__builtin_mul_overflow(a, b, d)) __must_check_overflow(__builtin_mul_overflow(a, b, d))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment