From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ED7FACD342C for ; Wed, 6 May 2026 16:10:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 92E0B10E1B1; Wed, 6 May 2026 16:10:19 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="W/IvqCRp"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5FF8510E1DE for ; Wed, 6 May 2026 16:10:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778083803; x=1809619803; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=0dB+hZ8u7SSyvtQlFzTYcnpgaGhH+WOUrlGZKLir44A=; b=W/IvqCRpGctjFvDaOt5jQkZuo9pOhxi6uBVKViMjdOJZZiDFeYfob2vM c2mfdkN6bW+HnKjUBzj+Nt58jTeVh7CAD1ESEnj5fGG6d3PkdVs4y/JEC sxWEX+3Ufeaoj+izqClDcZv5T34ptTyl2nMoTTkAC88tCFDX02WI1UKCP Z++9NLRbyTalMkFRgsqp4f/Vz2ABxtlcQI4B4WN7UgCxSjs2vRSX026mc pEMGb/fHc2m5wCowaYQnIshVSgIp7PXcks8XxvND/oY64Fit7rxy4kTaM dveosntDSMxakOjbsc3WghF7k69QCIibbmDe8aeJvCJeMprGJwPyEmPJv g==; X-CSE-ConnectionGUID: q+5CmeosQe2FObvOqiApHg== X-CSE-MsgGUID: W296M1fET+qi+8TQZgtpnQ== X-IronPort-AV: E=McAfee;i="6800,10657,11778"; a="82892084" X-IronPort-AV: E=Sophos;i="6.23,219,1770624000"; d="scan'208";a="82892084" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2026 09:10:03 -0700 X-CSE-ConnectionGUID: aXC2wq8bQW+wb8iLEPDeaw== X-CSE-MsgGUID: E6rI6awqTT+v70SClK3ZwQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,219,1770624000"; d="scan'208";a="233084522" Received: from ettammin-mobl2.ger.corp.intel.com (HELO localhost) ([10.245.244.208]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2026 09:10:01 -0700 From: Kamil Konieczny To: igt-dev@lists.freedesktop.org Cc: Kamil Konieczny , Ashutosh Dixit , Karthik B S , =?UTF-8?q?Zbigniew=20Kempczy=C5=84ski?= , Jani Nikula Subject: [PATCH i-g-t v5] lib/drmtest: Create proper error report when open driver fails Date: Wed, 6 May 2026 18:09:52 +0200 Message-ID: <20260506160952.202178-1-kamil.konieczny@linux.intel.com> X-Mailer: git-send-email 2.54.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: igt-dev@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development mailing list for IGT GPU Tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" When first try for opening driver fails then opening function is searching for next available device. When that also fails reporting is printing last errno which could mislead developer: $ build/tests/kms_dp_aux_dev IGT-Version: 2.3-NO-GIT (x86_64) (Linux: 6.17.0-19-generic x86_64) Test requirement not met in function drm_open_driver, file ../lib/drmtest.c:754: Test requirement: !(fd<0) No known gpu found for chipset flags 0x4294965755 (any) Last errno: 2, No such file or directory SKIP (0.006s) ls /dev/dri by-path card1 renderD128 The real problem here is lack of permissions as there was a card but program could not open it. Break looking for a card as soon as an error is different from ENOENT. It will create a proper error report which will print: Last errno: 13, Permission denied v3: break only when errno actually happens in open() (Kamil) v4: removed 'else', removed errno printing (Zbigniew) v5: use explicit strerror() (Kamil) Cc: Ashutosh Dixit Cc: Karthik B S Cc: "Zbigniew KempczyƄski" Cc: Jani Nikula Signed-off-by: Kamil Konieczny --- lib/drmtest.c | 26 +++++++++++++++++++++----- lib/drmtest.h | 2 +- lib/igt_sriov_device.c | 2 +- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/drmtest.c b/lib/drmtest.c index 4a788ea7a..084737edf 100644 --- a/lib/drmtest.c +++ b/lib/drmtest.c @@ -323,6 +323,7 @@ static void log_opened_device_path(const char *device_path) * __drm_open_device: * @name: DRM node name * @chipset: OR'd flags for chipset to be opened + * @error: pointer for saving errno when open() fails * * Open a drm legacy device node with given @name and compatible with given * @chipset flag. @@ -334,8 +335,10 @@ static void log_opened_device_path(const char *device_path) * name, even when driver was excluded by ANY or is not listed in known drivers. * * Returns: DRM file descriptor or -1 on error + * + * When open() succeeds, sets @error to zero otherwise to errno */ -int __drm_open_device(const char *name, unsigned int chipset) +int __drm_open_device(const char *name, unsigned int chipset, int *error) { const char *forced; char dev_name[16] = ""; @@ -343,8 +346,15 @@ int __drm_open_device(const char *name, unsigned int chipset) int fd; fd = open(name, O_RDWR); - if (fd == -1) + if (fd == -1) { + if (error) + *error = errno; + return -1; + } + + if (error) + *error = 0; if (__get_drm_device_name(fd, dev_name, sizeof(dev_name) - 1) == -1) goto err; @@ -426,6 +436,7 @@ static bool _is_already_opened(const char *path, int as_idx) static int __search_and_open(const char *base, int offset, unsigned int chipset, int as_idx) { const char *forced; + int err; forced = forced_driver(); if (forced) @@ -440,9 +451,14 @@ static int __search_and_open(const char *base, int offset, unsigned int chipset, if (_is_already_opened(name, as_idx)) continue; - fd = __drm_open_device(name, chipset); + fd = __drm_open_device(name, chipset, &err); if (fd != -1) return fd; + + if (err) { + igt_debug("Error at open %s %s\n", name, strerror(err)); + break; + } } return -1; @@ -500,13 +516,13 @@ static int __open_driver_exact(const char *name, unsigned int chipset) { int fd; - fd = __drm_open_device(name, chipset); + fd = __drm_open_device(name, chipset, NULL); if (fd != -1) return fd; drm_load_module(chipset); - return __drm_open_device(name, chipset); + return __drm_open_device(name, chipset, NULL); } /* diff --git a/lib/drmtest.h b/lib/drmtest.h index 37874d729..126feffda 100644 --- a/lib/drmtest.h +++ b/lib/drmtest.h @@ -117,7 +117,7 @@ unsigned int drm_get_chipset(int fd); */ #define IS_ALIGNED(v, a) (((v) & ((typeof(v))(a) - 1)) == 0) -int __drm_open_device(const char *name, unsigned int chipset); +int __drm_open_device(const char *name, unsigned int chipset, int *error); void drm_load_module(unsigned int chipset); int drm_open_driver_another(int idx, int chipset); int drm_open_driver(int chipset); diff --git a/lib/igt_sriov_device.c b/lib/igt_sriov_device.c index 1f4c3ac04..21d23298b 100644 --- a/lib/igt_sriov_device.c +++ b/lib/igt_sriov_device.c @@ -284,7 +284,7 @@ int igt_sriov_open_vf_drm_device(int pf, unsigned int vf_num) if (!found) return -1; - fd = __drm_open_device(dev_name, DRIVER_ANY); + fd = __drm_open_device(dev_name, DRIVER_ANY, NULL); if (fd >= 0 && is_xe_device(fd)) xe_device_get(fd); -- 2.54.0