Skip to content
This repository has been archived by the owner on Nov 21, 2022. It is now read-only.

Commit

Permalink
minmax-sanity-check-constant-bounds-when-clamping-checkpatch-fixes
Browse files Browse the repository at this point in the history
ERROR: code indent should use tabs where possible
microsoft#36: FILE: include/linux/minmax.h:50:
+        (BUILD_BUG_ON_ZERO(__builtin_choose_expr(^I^I^I^I\$

WARNING: please, no spaces at the start of a line
microsoft#36: FILE: include/linux/minmax.h:50:
+        (BUILD_BUG_ON_ZERO(__builtin_choose_expr(^I^I^I^I\$

ERROR: code indent should use tabs where possible
#37: FILE: include/linux/minmax.h:51:
+                __is_constexpr((lo) > (hi)), (lo) > (hi), false)))$

WARNING: please, no spaces at the start of a line
#37: FILE: include/linux/minmax.h:51:
+                __is_constexpr((lo) > (hi)), (lo) > (hi), false)))$

WARNING: please, no space before tabs
microsoft#40: FILE: include/linux/minmax.h:54:
+^I__clamp_input_check(lo, hi) + ^I^I^I^I^I^I\$

WARNING: please, no space before tabs
#42: FILE: include/linux/minmax.h:56:
+^I^I^I      __typecheck(hi, lo) && __is_constexpr(val) && ^I\$

total: 2 errors, 4 warnings, 44 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

NOTE: Whitespace errors detected.
      You may wish to use scripts/cleanpatch or scripts/cleanfile

./patches/minmax-sanity-check-constant-bounds-when-clamping.patch has style problems, please review.

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.

Please run checkpatch prior to sending patches

Cc: Andy Shevchenko <[email protected]>
Cc: "Jason A. Donenfeld" <[email protected]>
Cc: Kees Cook <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
akpm00 committed Nov 15, 2022
1 parent abb4014 commit 9d8b6d2
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions include/linux/minmax.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,26 @@
__cmp(x, y, op), \
__cmp_once(x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y), op))

#define __clamp(val, lo, hi) \
#define __clamp(val, lo, hi) \
__cmp(__cmp(val, lo, >), hi, <)

#define __clamp_once(val, lo, hi, unique_val, unique_lo, unique_hi) ({ \
typeof(val) unique_val = (val); \
typeof(lo) unique_lo = (lo); \
typeof(hi) unique_hi = (hi); \
#define __clamp_once(val, lo, hi, unique_val, unique_lo, unique_hi) ({ \
typeof(val) unique_val = (val); \
typeof(lo) unique_lo = (lo); \
typeof(hi) unique_hi = (hi); \
__clamp(unique_val, unique_lo, unique_hi); })

#define __clamp_input_check(lo, hi) \
(BUILD_BUG_ON_ZERO(__builtin_choose_expr( \
#define __clamp_input_check(lo, hi) \
(BUILD_BUG_ON_ZERO(__builtin_choose_expr( \
__is_constexpr((lo) > (hi)), (lo) > (hi), false)))

#define __careful_clamp(val, lo, hi) ({ \
__clamp_input_check(lo, hi) + \
__builtin_choose_expr(__typecheck(val, lo) && __typecheck(val, hi) && \
__typecheck(hi, lo) && __is_constexpr(val) && \
__is_constexpr(lo) && __is_constexpr(hi), \
__clamp(val, lo, hi), \
__clamp_once(val, lo, hi, __UNIQUE_ID(__val), \
#define __careful_clamp(val, lo, hi) ({ \
__clamp_input_check(lo, hi) + \
__builtin_choose_expr(__typecheck(val, lo) && __typecheck(val, hi) &&\
__typecheck(hi, lo) && __is_constexpr(val) &&\
__is_constexpr(lo) && __is_constexpr(hi), \
__clamp(val, lo, hi), \
__clamp_once(val, lo, hi, __UNIQUE_ID(__val), \
__UNIQUE_ID(__lo), __UNIQUE_ID(__hi))); })

/**
Expand Down

0 comments on commit 9d8b6d2

Please sign in to comment.