[igt-dev] [PATCH i-g-t v2 2/2] lib/igt_device_scan: Return true from igt_device_find_first_i915_discrete_card()

Lyude lyude at redhat.com
Fri Oct 9 17:50:57 UTC 2020


From: Lyude Paul <lyude at redhat.com>

So that we can also print a relevant error message when failing to find any devices in
intel_gpu_top.

Signed-off-by: Lyude Paul <lyude at redhat.com>
Cc: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
---
 lib/igt_device_scan.c |  6 ++++--
 lib/igt_device_scan.h |  2 +-
 tools/intel_gpu_top.c | 15 +++++++++------
 3 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/lib/igt_device_scan.c b/lib/igt_device_scan.c
index d77311a4..f4d43c73 100644
--- a/lib/igt_device_scan.c
+++ b/lib/igt_device_scan.c
@@ -449,7 +449,7 @@ __copy_dev_to_card(struct igt_device *dev, struct igt_device_card *card)
  * Iterate over all igt_devices array and find first discrete card.
  * card->pci_slot_name will be updated only if a discrete card is present.
  */
-void igt_device_find_first_i915_discrete_card(struct igt_device_card *card)
+bool igt_device_find_first_i915_discrete_card(struct igt_device_card *card)
 {
 	struct igt_device *dev;
 
@@ -462,9 +462,11 @@ void igt_device_find_first_i915_discrete_card(struct igt_device_card *card)
 
 		if ((strncmp(dev->pci_slot_name, INTEGRATED_I915_GPU_PCI_ID, PCI_SLOT_NAME_SIZE)) != 0) {
 			__copy_dev_to_card(dev, card);
-			break;
+			return true;
 		}
 	}
+
+	return false;
 }
 
 static struct igt_device *igt_device_from_syspath(const char *syspath)
diff --git a/lib/igt_device_scan.h b/lib/igt_device_scan.h
index 9ed73958..bd937d22 100644
--- a/lib/igt_device_scan.h
+++ b/lib/igt_device_scan.h
@@ -68,7 +68,7 @@ const char *igt_device_filter_get(int num);
 
 /* Use filter to match the device and fill card structure */
 bool igt_device_card_match(const char *filter, struct igt_device_card *card);
-void igt_device_find_first_i915_discrete_card(struct igt_device_card *card);
+bool igt_device_find_first_i915_discrete_card(struct igt_device_card *card);
 int igt_open_card(struct igt_device_card *card);
 int igt_open_render(struct igt_device_card *card);
 
diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c
index cae01c25..79a936ff 100644
--- a/tools/intel_gpu_top.c
+++ b/tools/intel_gpu_top.c
@@ -1394,15 +1394,18 @@ int main(int argc, char **argv)
 
 	if (opt_device != NULL) {
 		ret = igt_device_card_match(opt_device, &card);
-		if (!ret) {
+		if (!ret)
 			fprintf(stderr, "Requested device %s not found!\n", opt_device);
-			free(opt_device);
-			ret = EXIT_FAILURE;
-			goto exit;
-		}
 		free(opt_device);
 	} else {
-		igt_device_find_first_i915_discrete_card(&card);
+		ret = igt_device_find_first_i915_discrete_card(&card);
+		if (!ret)
+			fprintf(stderr, "No device filter specified and no discrete i915 devices found\n");
+	}
+
+	if (!ret) {
+		ret = EXIT_FAILURE;
+		goto exit;
 	}
 
 	if (card.pci_slot_name[0] && !is_igpu_pci(card.pci_slot_name))
-- 
2.26.2



More information about the igt-dev mailing list