Skip to content

Commit 352eff2

Browse files
committed
Report for unitialized variable warning
1 parent e46f7e3 commit 352eff2

File tree

2 files changed

+134
-0
lines changed

2 files changed

+134
-0
lines changed

Report_0003.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Warning Analysis Report
2+
3+
### General
4+
5+
**Warning Type:** -Wsometimes-uninitialized
6+
7+
**Warning Explanation:**
8+
```
9+
drivers/gpu/drm/i915/intel_pm.c:4670:6: warning: variable 'trans_min' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
10+
if (INTEL_GEN(dev_priv) >= 10)
11+
^~~~~~~~~~~~~~~~~~~~~~~~~
12+
drivers/gpu/drm/i915/i915_drv.h:2535:29: note: expanded from macro 'INTEL_GEN'
13+
#define INTEL_GEN(dev_priv) ((dev_priv)->info.gen)
14+
^
15+
drivers/gpu/drm/i915/intel_pm.c:4673:19: note: uninitialized use occurs here
16+
trans_offset_b = trans_min + trans_amount;
17+
^~~~~~~~~
18+
drivers/gpu/drm/i915/intel_pm.c:4670:2: note: remove the 'if' if its condition is always true
19+
if (INTEL_GEN(dev_priv) >= 10)
20+
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21+
drivers/gpu/drm/i915/intel_pm.c:4655:20: note: initialize the variable 'trans_min' to silence this warning
22+
uint16_t trans_min, trans_y_tile_min;
23+
^
24+
= 0
25+
```
26+
### History
27+
28+
**Introduced in version:** v4.15-rc1<br/>
29+
**Date:** 2017-08-17<br/>
30+
**Author:** Kumar, Mahesh<br/>
31+
**Patch:** https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ca47667f523e588318f89c735e127c256de6cb16
32+
33+
### Warning Assessment
34+
35+
**File Location:** drivers/gpu/drm/i915/intel_pm.c
36+
37+
The variable trans_min is declared in the function<br/>
38+
skl_compute_transition_wm
39+
```
40+
uint16_t trans_min, trans_y_tile_min;
41+
```
42+
This variable is initialized only if the following condition is true.
43+
```
44+
if (INTEL_GEN(dev_priv) >= 10)
45+
trans_min = 4;
46+
```
47+
The variable is used in two places, one within the if condition and <br/>
48+
other is outside the condition. The trans_offset_b can have garbage <br/>
49+
value if the trans_min is not initialized during declaration. <br/>
50+
```
51+
trans_offset_b = trans_min + trans_amount;
52+
```
53+
### Conclusion
54+
55+
Clang warning is true in this case.<br/>
56+
The variable needs to be initialised to zero.<br/>
57+
58+
### Fixed By
59+
60+
**Author:** Chris Wilson<br/>
61+
**Date:** 2017-11-15<br/>
62+
**Patch:** https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/gpu/drm/i915/intel_pm.c?id=be3fa66857051e2943960a06f8046e8445cdfe6e

Report_0004.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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

Comments
 (0)