Skip to contentSkip to conversation

math.h: Amend kernel-doc and add a note about signed type limits

PATCH Applied Andy Shevchenko 2 participants 3 messages Nov 6, 2025 – Nov 10, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 math.h: Amend kernel-doc and add a note about signed type limits

First of all, amend the existing kernel-doc so the description of the function is decoupled with the parameter descriptions. Second, add a note to explain behaviour for the signed types when supplied value is the minimum (e.g., INT_MIN for int type).

---
 include/linux/math.h | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
include/linux/math.h +9 -4
index 7fcb980677a0..c02cc5b9e6ae 100644
@@ -180,11 +180,16 @@ __STRUCT_FRACT(u32)
 
 /**
  * abs - return absolute value of an argument
- * @x: the value.  If it is unsigned type, it is converted to signed type first.
- *     char is treated as if it was signed (regardless of whether it really is)
- *     but the macro's return type is preserved as char.
+ * @x: the value.
  *
- * Return: an absolute value of x.
+ * If it is unsigned type, @x is converted to signed type first.
+ * char is treated as if it was signed (regardless of whether it really is)
+ * but the macro's return type is preserved as char.
+ *
+ * NOTE, for signed type if @x is the minimum, the returned result is undefined
+ * as there is not enough bits to represent it as a positive number.
+ *
+ * Return: an absolute value of @x.
  */
 #define abs(x)	__abs_choose_expr(x, long long,				\
 		__abs_choose_expr(x, long,				\
Signature · 1 line
2.50.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 20 lines · Andy Shevchenko

First of all, amend the existing kernel-doc so the description of the function is decoupled with the parameter descriptions. Second, add a note to explain behaviour for the signed types when supplied value is the minimum (e.g., INT_MIN for int type).

---
 include/linux/math.h | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
include/linux/math.h +0 -2
index 7fcb980677a0..c02cc5b9e6ae 100644
@@ -180,11 +180,16 @@ __STRUCT_FRACT(u32)
 
 /**
  * abs - return absolute value of an argument
- * @x: the value.  If it is unsigned type, it is converted to signed type first.
- *     char is treated as if it was signed (regardless of whether it really is)

include/linux/math.h __STRUCT_FRACT(u32) · line 190

Quoted 10 lines
include/linux/math.h +7 -2
- *     but the macro's return type is preserved as char.
+ * @x: the value.
  *
- * Return: an absolute value of x.
+ * If it is unsigned type, @x is converted to signed type first.
+ * char is treated as if it was signed (regardless of whether it really is)
+ * but the macro's return type is preserved as char.
+ *
+ * NOTE, for signed type if @x is the minimum, the returned result is undefined
+ * as there is not enough bits to represent it as a positive number.

Nit: s/is/are

Otherwise, the patch is:

Regards,
Kuan-Wei

Quoted 9 lines
include/linux/math.h +2 -0
+ *
+ * Return: an absolute value of @x.
  */
 #define abs(x)	__abs_choose_expr(x, long long,				\
 		__abs_choose_expr(x, long,				\
Signature · 1 line
2.50.1
#2 lore raw
Quoted 1 line · Kuan-Wei Chiu

On Thu, Nov 06, 2025 at 04:20:51PM +0100, Andy Shevchenko wrote:

...

Quoted 4 lines
Quoted 2 lines

+ * NOTE, for signed type if @x is the minimum, the returned result is undefined
+ * as there is not enough bits to represent it as a positive number.

Nit: s/is/are

I hope Andrew can combine this with the original patch.

Quoted 2 lines

Otherwise, the patch is:

Thank you!

Signature · 2 lines
With Best Regards,
Andy Shevchenko