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

kernel.h: implement DIV_ROUND_CLOSEST_ULL

We have grown a number of different implementations of
DIV_ROUND_CLOSEST_ULL throughout the kernel. Move the i915 one to
kernel.h so that it can be reused.

Signed-off-by: Javi Merino <javi.merino@arm.com>
Reviewed-by: Jeff Epler <jepler@unpythonic.net>
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: David Airlie <airlied@linux.ie>
Cc: Guenter Roeck <linux@roeck-us.net>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Cc: Alex Elder <elder@linaro.org>
Cc: Antti Palosaari <crope@iki.fi>
Cc: Javi Merino <javi.merino@arm.com>
Cc: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Mike Turquette <mturquette@linaro.org>
Cc: Stephen Boyd <sboyd@codeaurora.org>
Cc: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Javi Merino and committed by
Linus Torvalds
f766093e 675cf53c

+13 -3
-3
drivers/gpu/drm/i915/intel_drv.h
··· 36 36 #include <drm/drm_dp_mst_helper.h> 37 37 #include <drm/drm_rect.h> 38 38 39 - #define DIV_ROUND_CLOSEST_ULL(ll, d) \ 40 - ({ unsigned long long _tmp = (ll)+(d)/2; do_div(_tmp, d); _tmp; }) 41 - 42 39 /** 43 40 * _wait_for - magic (register) wait macro 44 41 *
+1
drivers/gpu/drm/i915/intel_panel.c
··· 30 30 31 31 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 32 32 33 + #include <linux/kernel.h> 33 34 #include <linux/moduleparam.h> 34 35 #include "intel_drv.h" 35 36
+12
include/linux/kernel.h
··· 103 103 (((__x) - ((__d) / 2)) / (__d)); \ 104 104 } \ 105 105 ) 106 + /* 107 + * Same as above but for u64 dividends. divisor must be a 32-bit 108 + * number. 109 + */ 110 + #define DIV_ROUND_CLOSEST_ULL(x, divisor)( \ 111 + { \ 112 + typeof(divisor) __d = divisor; \ 113 + unsigned long long _tmp = (x) + (__d) / 2; \ 114 + do_div(_tmp, __d); \ 115 + _tmp; \ 116 + } \ 117 + ) 106 118 107 119 /* 108 120 * Multiplies an integer by a fraction, while avoiding unnecessary