[PATCH i-g-t 1/2] lib/igt_kmod: Allow igt_kmod_unbind() on a specific device

Lucas De Marchi lucas.demarchi at intel.com
Fri Mar 14 14:19:30 UTC 2025


On Fri, Mar 14, 2025 at 10:55:04AM +0100, Francois Dugast wrote:
>It can be that multiple devices are bound but we want to unbind only
>one of them. Add an optional parameter so specificy which device.
>
>Cc: Satyanarayana K V P <satyanarayana.k.v.p at intel.com>
>Cc: Lucas De Marchi <lucas.demarchi at intel.com>
>Signed-off-by: Francois Dugast <francois.dugast at intel.com>
>---
> lib/igt_kmod.c | 15 ++++++++++-----
> lib/igt_kmod.h |  2 +-
> 2 files changed, 11 insertions(+), 6 deletions(-)
>
>diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c
>index 524c1a632..f00f7dd15 100644
>--- a/lib/igt_kmod.c
>+++ b/lib/igt_kmod.c
>@@ -633,7 +633,7 @@ int __igt_intel_driver_unload(char **who, const char *driver)
> 	}
>
> 	if (igt_kmod_is_loaded(driver)) {
>-		igt_kmod_unbind(driver);
>+		igt_kmod_unbind(driver, NULL);
>
> 		ret = igt_kmod_unload(driver);
> 		if (ret) {
>@@ -647,10 +647,14 @@ int __igt_intel_driver_unload(char **who, const char *driver)
> 	return 0;
> }
>
>-/*
>+/**
>+ * igt_kmod_unbind:
>+ *
>  * Unbind driver from devices. Currently supports only PCI bus
>+ * @mod_name: name of the module to unbind
>+ * @pci_device: if provided, unbind only this device, otherwise unbind all devices
>  */
>-int igt_kmod_unbind(const char *mod_name)
>+int igt_kmod_unbind(const char *mod_name, const char *pci_device)
> {
> 	char path[PATH_MAX];
> 	struct dirent *de;
>@@ -671,7 +675,8 @@ int igt_kmod_unbind(const char *mod_name)
> 		int devfd;
> 		bool ret;
>
>-		if (de->d_type != DT_LNK || !isdigit(de->d_name[0]))
>+		if (de->d_type != DT_LNK || !isdigit(de->d_name[0]) ||
>+		    (pci_device && strcmp(pci_device, de->d_name) != 0))

nit: I'd prefer to keep this in a separate `if` to make it easier to
read as the reason to continue is very different, i.e.:

		if (de->d_type != DT_LNK || !isdigit(de->d_name[0]))
			continue;

		if (pci_device && strcmp(pci_device, de->d_name) != 0))
			continue;

other than that, lgtm.

	Reviewed-by: Lucas De Marchi <lucas.demarchi at intel.com>

thanks
Lucas De Marchi

> 			continue;
>
> 		devfd = openat(dirfd(dir), de->d_name, O_RDONLY | O_CLOEXEC);
>@@ -718,7 +723,7 @@ igt_intel_driver_unload(const char *driver)
>
> int igt_xe_driver_unload(void)
> {
>-	igt_kmod_unbind("xe");
>+	igt_kmod_unbind("xe", NULL);
>
> 	igt_kmod_unload("xe");
> 	if (igt_kmod_is_loaded("xe"))
>diff --git a/lib/igt_kmod.h b/lib/igt_kmod.h
>index 193b95627..170a8df9d 100644
>--- a/lib/igt_kmod.h
>+++ b/lib/igt_kmod.h
>@@ -36,7 +36,7 @@ bool igt_kmod_has_param(const char *mod_name, const char *param);
> int igt_kmod_load(const char *mod_name, const char *opts);
> int igt_kmod_unload(const char *mod_name);
>
>-int igt_kmod_unbind(const char *mod_name);
>+int igt_kmod_unbind(const char *mod_name, const char *pci_device);
>
> int igt_audio_driver_unload(char **whom);
>
>-- 
>2.43.0
>


More information about the igt-dev mailing list