Skip to content

Commit f89a0f1

Browse files
groeckgregkh
authored andcommitted
drm/i915/backlight: Return immediately when scale() finds invalid parameters
commit 6f71507 upstream. The scale() functions detects invalid parameters, but continues its calculations anyway. This causes bad results if negative values are used for unsigned operations. Worst case, a division by 0 error will be seen if source_min == source_max. On top of that, after v6.13, the sequence of WARN_ON() followed by clamp() may result in a build error with gcc 13.x. drivers/gpu/drm/i915/display/intel_backlight.c: In function 'scale': include/linux/compiler_types.h:542:45: error: call to '__compiletime_assert_415' declared with attribute error: clamp() low limit source_min greater than high limit source_max This happens if the compiler decides to rearrange the code as follows. if (source_min > source_max) { WARN(..); /* Do the clamp() knowing that source_min > source_max */ source_val = clamp(source_val, source_min, source_max); } else { /* Do the clamp knowing that source_min <= source_max */ source_val = clamp(source_val, source_min, source_max); } Fix the problem by evaluating the return values from WARN_ON and returning immediately after a warning. While at it, fix divide by zero error seen if source_min == source_max. Analyzed-by: Linus Torvalds <[email protected]> Suggested-by: Linus Torvalds <[email protected]> Suggested-by: David Laight <[email protected]> Cc: David Laight <[email protected]> Cc: Jani Nikula <[email protected]> Cc: Andy Shevchenko <[email protected]> Signed-off-by: Guenter Roeck <[email protected]> Reviewed-by: Rodrigo Vivi <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Signed-off-by: Rodrigo Vivi <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent cbfd3c7 commit f89a0f1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/gpu/drm/i915/display/intel_backlight.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ static u32 scale(u32 source_val,
4040
{
4141
u64 target_val;
4242

43-
WARN_ON(source_min > source_max);
44-
WARN_ON(target_min > target_max);
43+
if (WARN_ON(source_min >= source_max) ||
44+
WARN_ON(target_min > target_max))
45+
return target_min;
4546

4647
/* defensive */
4748
source_val = clamp(source_val, source_min, source_max);

0 commit comments

Comments
 (0)