Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/i915: Move abs_diff() to math.h

abs_diff() belongs to math.h. Move it there. This will allow others to
use it.

[andriy.shevchenko@linux.intel.com: add abs_diff() documentation]
Link: https://lkml.kernel.org/r/20230804050934.83223-1-andriy.shevchenko@linux.intel.com
[akpm@linux-foundation.org: fix comment, per Randy]
Link: https://lkml.kernel.org/r/20230803131918.53727-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Jiri Slaby <jirislaby@kernel.org> # tty/serial
Acked-by: Jani Nikula <jani.nikula@intel.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de> # gpu/ipu-v3
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: David Airlie <airlied@gmail.com>
Cc: Helge Deller <deller@gmx.de>
Cc: Imre Deak <imre.deak@intel.com>
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
Cc: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Andy Shevchenko and committed by
Andrew Morton
46f12960 84c10951

+29 -27
+1
drivers/gpu/drm/i915/display/intel_dpll_mgr.c
··· 21 21 * DEALINGS IN THE SOFTWARE. 22 22 */ 23 23 24 + #include <linux/math.h> 24 25 #include <linux/string_helpers.h> 25 26 26 27 #include "i915_reg.h"
-7
drivers/gpu/drm/i915/display/intel_dpll_mgr.h
··· 29 29 30 30 #include "intel_wakeref.h" 31 31 32 - /*FIXME: Move this to a more appropriate place. */ 33 - #define abs_diff(a, b) ({ \ 34 - typeof(a) __a = (a); \ 35 - typeof(b) __b = (b); \ 36 - (void) (&__a == &__b); \ 37 - __a > __b ? (__a - __b) : (__b - __a); }) 38 - 39 32 enum tc_port; 40 33 struct drm_i915_private; 41 34 struct intel_atomic_state;
+7 -8
drivers/gpu/ipu-v3/ipu-image-convert.c
··· 7 7 8 8 #include <linux/interrupt.h> 9 9 #include <linux/dma-mapping.h> 10 + #include <linux/math.h> 11 + 10 12 #include <video/imx-ipu-image-convert.h> 13 + 11 14 #include "ipu-prv.h" 12 15 13 16 /* ··· 546 543 unsigned int in_pos; 547 544 unsigned int in_pos_aligned; 548 545 unsigned int in_pos_rounded; 549 - unsigned int abs_diff; 546 + unsigned int diff; 550 547 551 548 /* 552 549 * Tiles in the right row / bottom column may not be allowed to ··· 578 575 (in_edge - in_pos_rounded) % in_burst) 579 576 continue; 580 577 581 - if (in_pos < in_pos_aligned) 582 - abs_diff = in_pos_aligned - in_pos; 583 - else 584 - abs_diff = in_pos - in_pos_aligned; 585 - 586 - if (abs_diff < min_diff) { 578 + diff = abs_diff(in_pos, in_pos_aligned); 579 + if (diff < min_diff) { 587 580 in_seam = in_pos_rounded; 588 581 out_seam = out_pos; 589 - min_diff = abs_diff; 582 + min_diff = diff; 590 583 } 591 584 } 592 585
+1 -6
drivers/tty/serial/omap-serial.c
··· 222 222 unsigned int baud, unsigned int mode) 223 223 { 224 224 unsigned int n = port->uartclk / (mode * baud); 225 - int abs_diff; 226 225 227 226 if (n == 0) 228 227 n = 1; 229 228 230 - abs_diff = baud - (port->uartclk / (mode * n)); 231 - if (abs_diff < 0) 232 - abs_diff = -abs_diff; 233 - 234 - return abs_diff; 229 + return abs_diff(baud, port->uartclk / (mode * n)); 235 230 } 236 231 237 232 /*
+1 -6
drivers/video/fbdev/core/svgalib.c
··· 14 14 #include <linux/kernel.h> 15 15 #include <linux/string.h> 16 16 #include <linux/fb.h> 17 + #include <linux/math.h> 17 18 #include <linux/svga.h> 18 19 #include <asm/types.h> 19 20 #include <asm/io.h> ··· 373 372 * F_VCO = (F_BASE * M) / N 374 373 * F_OUT = F_VCO / (2^R) 375 374 */ 376 - 377 - static inline u32 abs_diff(u32 a, u32 b) 378 - { 379 - return (a > b) ? (a - b) : (b - a); 380 - } 381 - 382 375 int svga_compute_pll(const struct svga_pll *pll, u32 f_wanted, u16 *m, u16 *n, u16 *r, int node) 383 376 { 384 377 u16 am, an, ar;
+19
include/linux/math.h
··· 156 156 ({ signed type __x = (x); __x < 0 ? -__x : __x; }), other) 157 157 158 158 /** 159 + * abs_diff - return absolute value of the difference between the arguments 160 + * @a: the first argument 161 + * @b: the second argument 162 + * 163 + * @a and @b have to be of the same type. With this restriction we compare 164 + * signed to signed and unsigned to unsigned. The result is the subtraction 165 + * the smaller of the two from the bigger, hence result is always a positive 166 + * value. 167 + * 168 + * Return: an absolute value of the difference between the @a and @b. 169 + */ 170 + #define abs_diff(a, b) ({ \ 171 + typeof(a) __a = (a); \ 172 + typeof(b) __b = (b); \ 173 + (void)(&__a == &__b); \ 174 + __a > __b ? (__a - __b) : (__b - __a); \ 175 + }) 176 + 177 + /** 159 178 * reciprocal_scale - "scale" a value into range [0, ep_ro) 160 179 * @val: value 161 180 * @ep_ro: right open interval endpoint