Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTPS id 860E911B163 for ; Thu, 28 Jul 2022 06:59:34 +0000 (UTC) From: =?UTF-8?q?Zbigniew=20Kempczy=C5=84ski?= To: igt-dev@lists.freedesktop.org Date: Thu, 28 Jul 2022 08:59:08 +0200 Message-Id: <20220728065909.21022-1-zbigniew.kempczynski@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [igt-dev] [PATCH i-g-t] lib/igt_device_scan: Assert if there's no empty PCI_SLOT_NAME List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Petri Latvala Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" List-ID: On one of our testing machines executed i915_pm_rpm@module-reload subtest catches SIGSEGV with following callstack: Received signal SIGSEGV. Stack trace: There's single suspicious code line in devtype_intel() which might trigger this behavior - it is strncmp(). But that means pci_slot variable would be null or point to some garbage. This variable is initialized before from uevent property so lets verify and assert if there's no PCI_SLOT_NAME passed from the kernel for pci device. Additionally dump all properties and attributes to get bigger picture what comes from the kernel to device scanning library. Signed-off-by: Zbigniew KempczyƄski Cc: Petri Latvala --- lib/igt_device_scan.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/igt_device_scan.c b/lib/igt_device_scan.c index aad7966764..d6fae0650c 100644 --- a/lib/igt_device_scan.c +++ b/lib/igt_device_scan.c @@ -558,6 +558,16 @@ static void get_attrs(struct udev_device *dev, struct igt_device *idev) #define is_drm_subsystem(dev) (strequal(get_prop_subsystem(dev), "drm")) #define is_pci_subsystem(dev) (strequal(get_prop_subsystem(dev), "pci")) +static void print_ht(GHashTable *ht); +static void dump_props_and_attrs(const struct igt_device *dev) +{ + printf("\n[properties]\n"); + print_ht(dev->props_ht); + printf("\n[attributes]\n"); + print_ht(dev->attrs_ht); + printf("\n"); +} + /* * Get PCI_SLOT_NAME property, it should be in format of * xxxx:yy:zz.z @@ -565,9 +575,20 @@ static void get_attrs(struct udev_device *dev, struct igt_device *idev) static void set_pci_slot_name(struct igt_device *dev) { const char *pci_slot_name = get_prop(dev, "PCI_SLOT_NAME"); + int len; + + if (!pci_slot_name) { + dump_props_and_attrs(dev); + igt_assert_f(pci_slot_name, "PCI_SLOT_NAME property == NULL\n"); + } + + len = strlen(pci_slot_name); + if (len != PCI_SLOT_NAME_SIZE) { + dump_props_and_attrs(dev); + igt_assert_f(len != PCI_SLOT_NAME_SIZE, + "PCI_SLOT_NAME length != %d [%s]\n", len, pci_slot_name); + } - if (!pci_slot_name || (strlen(pci_slot_name) != PCI_SLOT_NAME_SIZE)) - return; dev->pci_slot_name = strdup(pci_slot_name); } @@ -1249,11 +1270,7 @@ igt_devs_print_detail(struct igt_list_head *view, _print_key_value("codename", dev->codename); } - printf("\n[properties]\n"); - print_ht(dev->props_ht); - printf("\n[attributes]\n"); - print_ht(dev->attrs_ht); - printf("\n"); + dump_props_and_attrs(dev); } } -- 2.34.1