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

Configure Feed

Select the types of activity you want to include in your feed.

iopoll: Avoid evaluating 'cond' twice in poll_timeout_us()

Currently poll_timeout_us() evaluates 'cond' twice at the end
of the success case. This not desirable in case 'cond' itself
is expensive.

Avoid the double evaluation by tracking the return value in
a variable. Need to use a triple undescore '___ret' name to
avoid a conflict with an existing double undescore '__ret'
variable in the regmap code.

Cc: Lucas De Marchi <lucas.demarchi@intel.com>
Cc: Dibin Moolakadan Subrahmanian <dibin.moolakadan.subrahmanian@intel.com>
Cc: Imre Deak <imre.deak@intel.com>
Cc: David Laight <david.laight.linux@gmail.com>
Cc: Geert Uytterhoeven <geert+renesas@glider.be>
Cc: Matt Wagantall <mattw@codeaurora.org>
Cc: Dejin Zheng <zhengdejin5@gmail.com>
Cc: intel-gfx@lists.freedesktop.org
Cc: intel-xe@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Reviewed-by: Jani Nikula <jani.nikula@intel.com>
Acked-by: Simona Vetter <simona.vetter@ffwll.ch>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Link: https://lore.kernel.org/r/20250826121859.15497-2-ville.syrjala@linux.intel.com
Signed-off-by: Jani Nikula <jani.nikula@intel.com>

authored by

Ville Syrjälä and committed by
Jani Nikula
563e5eca 9df8043a

+18 -4
+18 -4
include/linux/iopoll.h
··· 36 36 u64 __timeout_us = (timeout_us); \ 37 37 unsigned long __sleep_us = (sleep_us); \ 38 38 ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \ 39 + int ___ret; \ 39 40 might_sleep_if((__sleep_us) != 0); \ 40 41 if ((sleep_before_op) && __sleep_us) \ 41 42 usleep_range((__sleep_us >> 2) + 1, __sleep_us); \ 42 43 for (;;) { \ 43 44 op; \ 44 - if (cond) \ 45 + if (cond) { \ 46 + ___ret = 0; \ 45 47 break; \ 48 + } \ 46 49 if (__timeout_us && \ 47 50 ktime_compare(ktime_get(), __timeout) > 0) { \ 48 51 op; \ 52 + if (cond) \ 53 + ___ret = 0; \ 54 + else \ 55 + ___ret = -ETIMEDOUT; \ 49 56 break; \ 50 57 } \ 51 58 if (__sleep_us) \ 52 59 usleep_range((__sleep_us >> 2) + 1, __sleep_us); \ 53 60 cpu_relax(); \ 54 61 } \ 55 - (cond) ? 0 : -ETIMEDOUT; \ 62 + ___ret; \ 56 63 }) 57 64 58 65 /** ··· 90 83 s64 __left_ns = __timeout_us * NSEC_PER_USEC; \ 91 84 unsigned long __delay_us = (delay_us); \ 92 85 u64 __delay_ns = __delay_us * NSEC_PER_USEC; \ 86 + int ___ret; \ 93 87 if ((delay_before_op) && __delay_us) { \ 94 88 udelay(__delay_us); \ 95 89 if (__timeout_us) \ ··· 98 90 } \ 99 91 for (;;) { \ 100 92 op; \ 101 - if (cond) \ 93 + if (cond) { \ 94 + ___ret = 0; \ 102 95 break; \ 96 + } \ 103 97 if (__timeout_us && __left_ns < 0) { \ 104 98 op; \ 99 + if (cond) \ 100 + ___ret = 0; \ 101 + else \ 102 + ___ret = -ETIMEDOUT; \ 105 103 break; \ 106 104 } \ 107 105 if (__delay_us) { \ ··· 119 105 if (__timeout_us) \ 120 106 __left_ns--; \ 121 107 } \ 122 - (cond) ? 0 : -ETIMEDOUT; \ 108 + ___ret; \ 123 109 }) 124 110 125 111 /**