Skip to contentSkip to conversation

drm/i915: avoid "may be used uninitialised" warnings

PATCH In review Dave Gordon 3 participants 3 messages Jul 25, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/i915: avoid "may be used uninitialised" warnings

gcc is getting false positives in its detection of uninitialised values. Specifically it thinks 'gtt_entry' can be used in a WARN_ON() macro without previously being assigned (the assigment is inside a conditional loop), bu actually the WARN_ON() can only be reached if the assignment has also been executed at least once.

To avoid the annoying warning, though, this patch reorganises the code a little and adds an explicit initialisation of the suspect variable.

---
 drivers/gpu/drm/i915/i915_gem_gtt.c | 19 ++++++++++++-------
 drivers/gpu/drm/i915/i915_gem_gtt.h |  1 +
 2 files changed, 13 insertions(+), 7 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +12 -7
index 30da543..90e1cf3 100644
@@ -2368,7 +2368,7 @@ static void gen8_ggtt_insert_entries(struct i915_address_space *vm,
 	struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm);
 	struct sgt_iter sgt_iter;
 	gen8_pte_t __iomem *gtt_entries;
-	gen8_pte_t gtt_entry;
+	gen8_pte_t gtt_entry = I915_NULL_PTE;
 	dma_addr_t addr;
 	int rpm_atomic_seq;
 	int i = 0;
@@ -2389,8 +2389,10 @@ static void gen8_ggtt_insert_entries(struct i915_address_space *vm,
 	 * of NUMA access patterns. Therefore, even with the way we assume
 	 * hardware should work, we must keep this posting read for paranoia.
 	 */
-	if (i != 0)
-		WARN_ON(readq(&gtt_entries[i-1]) != gtt_entry);
+	if (i != 0) {
+		gen8_pte_t last_gtt_entry = readq(&gtt_entries[i-1]);
+		WARN_ON(last_gtt_entry != gtt_entry);
+	}
 
 	/* This next bit makes the above posting read even more important. We
 	 * want to flush the TLBs only after we're certain all the PTE updates
@@ -2465,7 +2467,7 @@ static void gen6_ggtt_insert_entries(struct i915_address_space *vm,
 	struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm);
 	struct sgt_iter sgt_iter;
 	gen6_pte_t __iomem *gtt_entries;
-	gen6_pte_t gtt_entry;
+	gen6_pte_t gtt_entry = I915_NULL_PTE;
 	dma_addr_t addr;
 	int rpm_atomic_seq;
 	int i = 0;
@@ -2479,14 +2481,17 @@ static void gen6_ggtt_insert_entries(struct i915_address_space *vm,
 		iowrite32(gtt_entry, &gtt_entries[i++]);
 	}
 
-	/* XXX: This serves as a posting read to make sure that the PTE has
+	/*
+	 * XXX: This serves as a posting read to make sure that the PTE has
 	 * actually been updated. There is some concern that even though
 	 * registers and PTEs are within the same BAR that they are potentially
 	 * of NUMA access patterns. Therefore, even with the way we assume
 	 * hardware should work, we must keep this posting read for paranoia.
 	 */
-	if (i != 0)
-		WARN_ON(readl(&gtt_entries[i-1]) != gtt_entry);
+	if (i != 0) {
+		gen8_pte_t last_gtt_entry = readl(&gtt_entries[i-1]);
+		WARN_ON(last_gtt_entry != gtt_entry);
+	}
 
 	/* This next bit makes the above posting read even more important. We
 	 * want to flush the TLBs only after we're certain all the PTE updates
drivers/gpu/drm/i915/i915_gem_gtt.h +1 -0
index c4a6579..e088210 100644
@@ -54,6 +54,7 @@ typedef uint64_t gen8_ppgtt_pml4e_t;
 #define GEN6_PTE_UNCACHED		(1 << 1)
 #define GEN6_PTE_VALID			(1 << 0)
 
+#define	I915_NULL_PTE			0
 #define I915_PTES(pte_len)		(PAGE_SIZE / (pte_len))
 #define I915_PTE_MASK(pte_len)		(I915_PTES(pte_len) - 1)
 #define I915_PDES			512
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw
Quoted 5 lines · Dave Gordon

gcc is getting false positives in its detection of uninitialised values. Specifically it thinks 'gtt_entry' can be used in a WARN_ON() macro without previously being assigned (the assigment is inside a conditional loop), bu actually the WARN_ON() can only be reached if the assignment has also been executed at least once.

gcc 4.7 through 6.1 doesn't generate the warning for me, and the kbuilder can happily ignore it.

At any rate the markup is uninitialised_var().
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw

✗ Ro.CI.BAT: warning for drm/i915: avoid "may be used uninitialised" warnings

In reply to Dave Gordon
== Series Details ==

== Series Details ==

Series: drm/i915: avoid "may be used uninitialised" warnings
URL : https://patchwork.freedesktop.org/series/10243/
State : warning

== Summary ==

Series 10243v1 drm/i915: avoid "may be used uninitialised" warnings
http://patchwork.freedesktop.org/api/1.0/series/10243/revisions/1/mbox

Test gem_exec_suspend:

        Subgroup basic-s3:
                dmesg-warn -> PASS       (fi-skl-i5-6260u)
Test gem_sync:
        Subgroup basic-store-each:
                pass       -> SKIP       (ro-bdw-i7-5600u)
                pass       -> SKIP       (ro-bdw-i5-5250u)
fi-hsw-i7-4770k  total:235  pass:215  dwarn:0   dfail:0   fail:0   skip:20 
fi-kbl-qkkr      total:235  pass:179  dwarn:28  dfail:1   fail:0   skip:27 
fi-skl-i5-6260u  total:235  pass:223  dwarn:0   dfail:0   fail:0   skip:12 
fi-skl-i7-6700k  total:235  pass:209  dwarn:0   dfail:0   fail:0   skip:26 
fi-snb-i7-2600   total:235  pass:195  dwarn:0   dfail:0   fail:0   skip:40 
ro-bdw-i5-5250u  total:235  pass:217  dwarn:4   dfail:0   fail:0   skip:14 
ro-bdw-i7-5557U  total:235  pass:218  dwarn:3   dfail:0   fail:0   skip:14 
ro-bdw-i7-5600u  total:235  pass:203  dwarn:0   dfail:0   fail:0   skip:32 
ro-bsw-n3050     total:235  pass:193  dwarn:0   dfail:0   fail:0   skip:42 
ro-byt-n2820     total:235  pass:196  dwarn:0   dfail:0   fail:1   skip:38 
ro-hsw-i3-4010u  total:235  pass:211  dwarn:0   dfail:0   fail:0   skip:24 
ro-hsw-i7-4770r  total:235  pass:211  dwarn:0   dfail:0   fail:0   skip:24 
ro-ilk-i7-620lm  total:235  pass:171  dwarn:0   dfail:0   fail:1   skip:63 
ro-ilk1-i5-650   total:230  pass:171  dwarn:0   dfail:0   fail:1   skip:58 
ro-ivb-i7-3770   total:235  pass:202  dwarn:0   dfail:0   fail:0   skip:33 
ro-skl3-i5-6260u total:235  pass:223  dwarn:0   dfail:0   fail:0   skip:12 
ro-snb-i7-2620M  total:235  pass:193  dwarn:0   dfail:0   fail:1   skip:41 

Results at /archive/results/CI_IGT_test/RO_Patchwork_1599/

5c9e3d9 drm-intel-nightly: 2016y-07m-25d-06h-32m-37s UTC integration manifest 9b271c1 drm/i915: avoid "may be used uninitialised" warnings

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx