From: Lucas De Marchi <lucas.demarchi@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Francois Dugast <francois.dugast@intel.com>,
Peter Senna Tschudin <peter.senna@linux.intel.com>,
Lucas De Marchi <lucas.demarchi@intel.com>
Subject: [PATCH i-g-t 1/4] lib/drmtest: Fix drm_close_driver()
Date: Tue, 17 Dec 2024 21:13:21 -0800 [thread overview]
Message-ID: <20241218051324.2696557-2-lucas.demarchi@intel.com> (raw)
In-Reply-To: <20241218051324.2696557-1-lucas.demarchi@intel.com>
When the driver is closed, make sure to invalidate the opened_devices,
otherwise it may later try use that info and wrongly detect the device
as "already opened". Also make sure that if the device can't even be stat'ed,
it should be considered as "already opened" since that fd refers to something
that already went away.
While at it fix some minor typos and coding style nearby.
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
---
lib/drmtest.c | 26 ++++++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)
diff --git a/lib/drmtest.c b/lib/drmtest.c
index 2dd4540b8..c541be132 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -377,7 +377,7 @@ err:
static struct {
int fd;
struct stat stat;
-}_opened_fds[64];
+} _opened_fds[64];
static int _opened_fds_count;
@@ -393,6 +393,20 @@ static void _set_opened_fd(int idx, int fd)
_opened_fds_count = idx+1;
}
+static void _set_closed_fd(int fd)
+{
+ unsigned int idx;
+
+ for (idx = 0; idx < ARRAY_SIZE(_opened_fds); idx++) {
+ if (_opened_fds[idx].fd == fd) {
+ memset(&_opened_fds[idx].stat, 0,
+ sizeof(_opened_fds[idx].stat));
+ _opened_fds[idx].fd = -1;
+ break;
+ }
+ }
+}
+
static bool _is_already_opened(const char *path, int as_idx)
{
struct stat new;
@@ -401,11 +415,10 @@ static bool _is_already_opened(const char *path, int as_idx)
assert(as_idx <= _opened_fds_count);
/*
- * we cannot even stat the device, so it's of no use - let's claim it's
- * already opened
+ * we cannot even stat the device, so it's of no use
*/
if (igt_debug_on(stat(path, &new) != 0))
- return true;
+ return false;
for (int i = 0; i < as_idx; ++i) {
/* did we cross filesystem boundary? */
@@ -605,10 +618,9 @@ int __drm_open_driver_another(int idx, int chipset)
igt_warn("No card matches the filter! [%s]\n",
igt_device_filter_get(idx));
else if (_is_already_opened(card.card, idx))
- igt_warn("card maching filter %d is already opened\n", idx);
+ igt_warn("card matching filter %d is already opened\n", idx);
else
fd = __open_driver_exact(card.card, chipset);
-
} else {
/* no filter for device idx, let's open whatever is available */
fd = __open_driver("/dev/dri/card", 0, chipset, idx);
@@ -806,6 +818,8 @@ int __drm_close_driver(int fd)
if (is_xe_device(fd))
xe_device_put(fd);
+ _set_closed_fd(fd);
+
return close(fd);
}
--
2.47.0
next prev parent reply other threads:[~2024-12-18 5:14 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-18 5:13 [PATCH i-g-t 0/4] Device scan fixes Lucas De Marchi
2024-12-18 5:13 ` Lucas De Marchi [this message]
2024-12-18 5:13 ` [PATCH i-g-t 2/4] lib/igt_sysfs: Fix close when rebinding Lucas De Marchi
2024-12-18 5:13 ` [PATCH i-g-t 3/4] lib/igt_sysfs: Move close to be common to all actions Lucas De Marchi
2024-12-18 5:13 ` [PATCH i-g-t 4/4] lib/igt_device_scan: Fix scan vs bind/unbind/reload Lucas De Marchi
2024-12-18 6:07 ` Peter Senna Tschudin
2024-12-18 6:17 ` Zbigniew Kempczyński
2024-12-20 19:10 ` Lucas De Marchi
2024-12-18 6:34 ` Zbigniew Kempczyński
2024-12-19 16:35 ` Lucas De Marchi
2024-12-20 6:59 ` Zbigniew Kempczyński
2024-12-20 18:52 ` Lucas De Marchi
2024-12-18 8:20 ` Kamil Konieczny
2024-12-18 8:16 ` [PATCH i-g-t 0/4] Device scan fixes Peter Senna Tschudin
2024-12-18 22:04 ` Lucas De Marchi
2024-12-19 8:44 ` Peter Senna Tschudin
2024-12-18 20:55 ` ✓ i915.CI.BAT: success for " Patchwork
2024-12-18 23:00 ` ✓ Xe.CI.BAT: " Patchwork
2024-12-19 10:18 ` ✗ i915.CI.Full: failure " Patchwork
2024-12-19 14:13 ` ✗ Xe.CI.Full: " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241218051324.2696557-2-lucas.demarchi@intel.com \
--to=lucas.demarchi@intel.com \
--cc=francois.dugast@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=peter.senna@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox