diff mbox series

[v6,1/2] tst_kernel: Add function check if the kernel module is built-in

Message ID 20230323121026.28710-2-wegao@suse.com
State Accepted
Headers show
Series madvise11: Check if module is loadable before rmmod | expand

Commit Message

Wei Gao March 23, 2023, 12:10 p.m. UTC
Signed-off-by: Wei Gao <wegao@suse.com>
---
 include/tst_kernel.h | 14 ++++++++++++--
 lib/tst_kernel.c     | 36 ++++++++++++++++++++++--------------
 2 files changed, 34 insertions(+), 16 deletions(-)

Comments

Petr Vorel March 24, 2023, 5:51 a.m. UTC | #1
Hi Wei,

> Signed-off-by: Wei Gao <wegao@suse.com>
> ---
>  include/tst_kernel.h | 14 ++++++++++++--
>  lib/tst_kernel.c     | 36 ++++++++++++++++++++++--------------
>  2 files changed, 34 insertions(+), 16 deletions(-)

> diff --git a/include/tst_kernel.h b/include/tst_kernel.h
> index 9e17bb71e..884a1c7f9 100644
> --- a/include/tst_kernel.h
> +++ b/include/tst_kernel.h
> @@ -10,8 +10,18 @@
>   */
>  int tst_kernel_bits(void);

> -/**
> - * Checks support for the kernel driver.
> +/*
> + * Check if the kernel module is built-in .
Patchset merged with removed extra space before dot in the end.

Thank you!

Kind regards,
Petr
diff mbox series

Patch

diff --git a/include/tst_kernel.h b/include/tst_kernel.h
index 9e17bb71e..884a1c7f9 100644
--- a/include/tst_kernel.h
+++ b/include/tst_kernel.h
@@ -10,8 +10,18 @@ 
  */
 int tst_kernel_bits(void);
 
-/**
- * Checks support for the kernel driver.
+/*
+ * Check if the kernel module is built-in .
+ *
+ * @param driver The name of the driver.
+ * @return Returns 0 if builtin driver
+ * -1 when driver is missing or config file not available.
+ * On Android *always* 0 (always expect the driver is available).
+ */
+int tst_check_builtin_driver(const char *driver);
+
+/*
+ * Checks support for the kernel module (both built-in and loadable).
  *
  * @param driver The name of the driver.
  * @return Returns 0 if the kernel has the driver,
diff --git a/lib/tst_kernel.c b/lib/tst_kernel.c
index ecf4b917e..be3ec92da 100644
--- a/lib/tst_kernel.c
+++ b/lib/tst_kernel.c
@@ -90,7 +90,7 @@  int tst_kernel_bits(void)
 	return kernel_bits;
 }
 
-static int tst_search_driver(const char *driver, const char *file)
+static int tst_search_driver_(const char *driver, const char *file)
 {
 	struct stat st;
 	char buf[PATH_MAX];
@@ -144,28 +144,19 @@  static int tst_search_driver(const char *driver, const char *file)
 	return ret;
 }
 
-static int tst_check_driver_(const char *driver)
-{
-	if (!tst_search_driver(driver, "modules.dep") ||
-		!tst_search_driver(driver, "modules.builtin"))
-		return 0;
-
-	return -1;
-}
-
-int tst_check_driver(const char *driver)
+static int tst_search_driver(const char *driver, const char *file)
 {
 #ifdef __ANDROID__
 	/*
 	 * Android may not have properly installed modules.* files. We could
-	 * search modules in /system/lib/modules, but to to determine built-in
+	 * search modules in /system/lib/modules, but to determine built-in
 	 * drivers we need modules.builtin. Therefore assume all drivers are
 	 * available.
 	 */
 	return 0;
 #endif
 
-	if (!tst_check_driver_(driver))
+	if (!tst_search_driver_(driver, file))
 		return 0;
 
 	int ret = -1;
@@ -183,9 +174,26 @@  int tst_check_driver(const char *driver)
 		while ((ix = strchr(ix, find)))
 			*ix++ = replace;
 
-		ret = tst_check_driver_(driver2);
+		ret = tst_search_driver_(driver2, file);
 		free(driver2);
 	}
 
 	return ret;
 }
+
+int tst_check_builtin_driver(const char *driver)
+{
+	if (!tst_search_driver(driver, "modules.builtin"))
+		return 0;
+
+	return -1;
+}
+
+int tst_check_driver(const char *driver)
+{
+	if (!tst_search_driver(driver, "modules.dep") ||
+		!tst_search_driver(driver, "modules.builtin"))
+		return 0;
+
+	return -1;
+}