treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / gpu / drm / i915 / i915_utils.c
blobc47261ae86eab09b1341059a3ec9cb36db6767a8
1 // SPDX-License-Identifier: MIT
2 /*
3 * Copyright © 2019 Intel Corporation
4 */
6 #include <drm/drm_drv.h>
8 #include "i915_drv.h"
9 #include "i915_utils.h"
11 #define FDO_BUG_URL "https://bugs.freedesktop.org/enter_bug.cgi?product=DRI"
12 #define FDO_BUG_MSG "Please file a bug at " FDO_BUG_URL " against DRM/Intel " \
13 "providing the dmesg log by booting with drm.debug=0xf"
15 void
16 __i915_printk(struct drm_i915_private *dev_priv, const char *level,
17 const char *fmt, ...)
19 static bool shown_bug_once;
20 struct device *kdev = dev_priv->drm.dev;
21 bool is_error = level[1] <= KERN_ERR[1];
22 bool is_debug = level[1] == KERN_DEBUG[1];
23 struct va_format vaf;
24 va_list args;
26 if (is_debug && !drm_debug_enabled(DRM_UT_DRIVER))
27 return;
29 va_start(args, fmt);
31 vaf.fmt = fmt;
32 vaf.va = &args;
34 if (is_error)
35 dev_printk(level, kdev, "%pV", &vaf);
36 else
37 dev_printk(level, kdev, "[" DRM_NAME ":%ps] %pV",
38 __builtin_return_address(0), &vaf);
40 va_end(args);
42 if (is_error && !shown_bug_once) {
44 * Ask the user to file a bug report for the error, except
45 * if they may have caused the bug by fiddling with unsafe
46 * module parameters.
48 if (!test_taint(TAINT_USER))
49 dev_notice(kdev, "%s", FDO_BUG_MSG);
50 shown_bug_once = true;
54 #if IS_ENABLED(CONFIG_DRM_I915_DEBUG)
55 static unsigned int i915_probe_fail_count;
57 int __i915_inject_probe_error(struct drm_i915_private *i915, int err,
58 const char *func, int line)
60 if (i915_probe_fail_count >= i915_modparams.inject_probe_failure)
61 return 0;
63 if (++i915_probe_fail_count < i915_modparams.inject_probe_failure)
64 return 0;
66 __i915_printk(i915, KERN_INFO,
67 "Injecting failure %d at checkpoint %u [%s:%d]\n",
68 err, i915_modparams.inject_probe_failure, func, line);
69 i915_modparams.inject_probe_failure = 0;
70 return err;
73 bool i915_error_injected(void)
75 return i915_probe_fail_count && !i915_modparams.inject_probe_failure;
78 #endif
80 void cancel_timer(struct timer_list *t)
82 if (!READ_ONCE(t->expires))
83 return;
85 del_timer(t);
86 WRITE_ONCE(t->expires, 0);
89 void set_timer_ms(struct timer_list *t, unsigned long timeout)
91 if (!timeout) {
92 cancel_timer(t);
93 return;
96 timeout = msecs_to_jiffies_timeout(timeout);
99 * Paranoia to make sure the compiler computes the timeout before
100 * loading 'jiffies' as jiffies is volatile and may be updated in
101 * the background by a timer tick. All to reduce the complexity
102 * of the addition and reduce the risk of losing a jiffie.
104 barrier();
106 mod_timer(t, jiffies + timeout);