|
| 1 | +# Warning Analysis Report |
| 2 | + |
| 3 | +### General |
| 4 | + |
| 5 | +**Warning Type:** -Wsometimes-uninitialized |
| 6 | + |
| 7 | +**Warning Explanation:** |
| 8 | +``` |
| 9 | +drivers/gpu/drm/i915/intel_crt.c:815:11: warning: variable 'status' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized] |
| 10 | + else if (ret < 0) |
| 11 | + ^~~~~~~ |
| 12 | +drivers/gpu/drm/i915/intel_crt.c:820:9: note: uninitialized use occurs here |
| 13 | + return status; |
| 14 | + ^~~~~~ |
| 15 | +drivers/gpu/drm/i915/intel_crt.c:815:7: note: remove the 'if' if its condition is always true |
| 16 | + else if (ret < 0) |
| 17 | + ^~~~~~~~~~~~ |
| 18 | +drivers/gpu/drm/i915/intel_crt.c:755:12: note: initialize the variable 'status' to silence this warning |
| 19 | + int status, ret; |
| 20 | + ^ |
| 21 | + = 0 |
| 22 | +``` |
| 23 | +### History |
| 24 | + |
| 25 | +**Introduced in version:** v4.12-rc1<br/> |
| 26 | +**Date:** 2017-04-06<br/> |
| 27 | +**Author:** Maarten Lankhorst<br/> |
| 28 | +**Patch:** https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=6c5ed5ae353cdf156f9ac4db17e15db56b4de880 |
| 29 | + |
| 30 | +### Warning Assessment |
| 31 | + |
| 32 | +**File Location:** drivers/gpu/drm/i915/intel_pm.c |
| 33 | + |
| 34 | +In the function static int intel_crt_detect,<br/> |
| 35 | +The variable is declared as<br/> |
| 36 | +``` |
| 37 | +int status, ret; |
| 38 | +``` |
| 39 | +Here the variable status is used within if blocks only. Variable status<br/> |
| 40 | +is always initialized to some value. The else if bock for condition<br/> |
| 41 | +ret < 0 needs to be changed to else block.<br/> |
| 42 | +``` |
| 43 | + ret = intel_get_load_detect_pipe(connector, NULL, &tmp, ctx); |
| 44 | + if (ret > 0) { |
| 45 | + if (intel_crt_detect_ddc(connector)) |
| 46 | + status = connector_status_connected; |
| 47 | + else if (INTEL_GEN(dev_priv) < 4) |
| 48 | + status = intel_crt_load_detect(crt, |
| 49 | + to_intel_crtc(connector->state->crtc)->pipe); |
| 50 | + else if (i915_modparams.load_detect_test) |
| 51 | + status = connector_status_disconnected; |
| 52 | + else |
| 53 | + status = connector_status_unknown; |
| 54 | + intel_release_load_detect_pipe(connector, &tmp, ctx); |
| 55 | + } else if (ret == 0) |
| 56 | + status = connector_status_unknown; |
| 57 | + else if (ret < 0) |
| 58 | + status = ret; |
| 59 | +``` |
| 60 | +### Conclusion |
| 61 | + |
| 62 | +The Clang warning is true in this case too. It suggests two solutions<br/> |
| 63 | +1) remove the 'if' if its condition is always true<br/> |
| 64 | +2) initialize the variable 'status' to silence this warning<br/> |
| 65 | + |
| 66 | +I would prefer solution 1 here, as status is always initialized to some integer value. |
| 67 | + |
| 68 | +### Fixed By |
| 69 | + |
| 70 | +**Author:** Chris Wilson<br/> |
| 71 | +**Date:** 2018-02-08<br/> |
| 72 | +**Patch:** https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/gpu/drm/i915/intel_crt.c?id=2927e4211f76893249cfa8e7ac5fe1c73ae791c1 |
0 commit comments