[igt-dev] [PATCH i-g-t] lib/igt_device_scan: init card in igt_device_find_first_i915_discrete_card()
Zbigniew Kempczyński
zbigniew.kempczynski at intel.com
Thu Oct 1 05:43:20 UTC 2020
On Wed, Sep 30, 2020 at 03:47:56PM -0400, Lyude wrote:
> 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))
> --
Maybe this function should return boolean does card was found or not?
This will require change in intel_gpu_top and check return value
but is more intuitive and appropriate message can be show that card
is not found.
--
Zbigniew
> 2.26.2
>
> _______________________________________________
> igt-dev mailing list
> igt-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/igt-dev
More information about the igt-dev
mailing list