[igt-dev] [PATCH i-g-t] lib/igt_device_scan: init card in igt_device_find_first_i915_discrete_card()

Lyude lyude at redhat.com
Wed Sep 30 19:47:56 UTC 2020


From: Lyude Paul <lyude at redhat.com>

Because we never initialize the card pointer passed to
igt_device_find_first_i915_discrete_card() if we don't match any cards, we make
the mistake of checking the contents of card in main() in intel_gpu_top.c before
they've actually been initialized, which can lead to a segfault in some
scenarios:

   # intel_gpu_top
   intel_gpu_top: ../tools/intel_gpu_top.c:1297: tr_pmu_name: Assertion `ret == (bufsize-1)' failed.
   abort--core dumped

So, fix it by making sure to initialize card in
igt_device_find_first_i915_discrete_card() like we do in
igt_device_card_match().

Signed-off-by: Lyude Paul <lyude at redhat.com>
Reported-by: Chris Siebenmann <cks-rhbugzilla at cs.toronto.edu>
Fedora bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1884016
---
 lib/igt_device_scan.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/igt_device_scan.c b/lib/igt_device_scan.c
index 345bae76..d77311a4 100644
--- a/lib/igt_device_scan.c
+++ b/lib/igt_device_scan.c
@@ -453,6 +453,8 @@ void igt_device_find_first_i915_discrete_card(struct igt_device_card *card)
 {
 	struct igt_device *dev;
 
+	memset(card, 0, sizeof(*card));
+
 	igt_list_for_each_entry(dev, &igt_devs.all, link) {
 
 		if (!is_pci_subsystem(dev))
-- 
2.26.2



More information about the igt-dev mailing list