All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jinjie Ruan <ruanjinjie@huawei.com>
To: <linux-kselftest@vger.kernel.org>, <kunit-dev@googlegroups.com>,
	<brendan.higgins@linux.dev>, <davidgow@google.com>,
	<skhan@linuxfoundation.org>, <rmoar@google.com>,
	<marpagan@redhat.com>
Cc: <ruanjinjie@huawei.com>
Subject: [PATCH RESEND 2/3] kunit: Return error from kunit_module_init()
Date: Thu, 28 Sep 2023 17:14:45 +0800	[thread overview]
Message-ID: <20230928091446.1209703-3-ruanjinjie@huawei.com> (raw)
In-Reply-To: <20230928091446.1209703-1-ruanjinjie@huawei.com>

When the module' state is MODULE_STATE_COMING, the return err code from
kunit_module_init() can be used to return. So when kunit_module_init()
fails, it will not be notified to go to kunit_module_exit() and the empty
checking can be removed. Because if kunit_filter_suites() succeeds, it
will notify the module state to MODULE_STATE_GOING otherwise it will not
and the test suites will be freed in kunit_filter_suites(). The best
practice is return the err code from MODULE_STATE_COMING func.

And if kunit_filter_suites() fails, both suite_set.start and suite_set.end
will be NULL, and the code behind it is dead code. so return err if
it fails.

Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
 lib/kunit/test.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/lib/kunit/test.c b/lib/kunit/test.c
index 29a5f5ea8112..145f70219f46 100644
--- a/lib/kunit/test.c
+++ b/lib/kunit/test.c
@@ -734,7 +734,7 @@ void __kunit_test_suites_exit(struct kunit_suite **suites, int num_suites)
 EXPORT_SYMBOL_GPL(__kunit_test_suites_exit);
 
 #ifdef CONFIG_MODULES
-static void kunit_module_init(struct module *mod)
+static int kunit_module_init(struct module *mod)
 {
 	struct kunit_suite_set suite_set = {
 		mod->kunit_suites, mod->kunit_suites + mod->num_kunit_suites,
@@ -760,6 +760,8 @@ static void kunit_module_init(struct module *mod)
 		kunit_exec_list_tests(&suite_set, true);
 	else
 		pr_err("kunit: unknown action '%s'\n", action);
+
+	return err;
 }
 
 static void kunit_module_exit(struct module *mod)
@@ -773,18 +775,18 @@ static void kunit_module_exit(struct module *mod)
 		__kunit_test_suites_exit(mod->kunit_suites,
 					 mod->num_kunit_suites);
 
-	if (suite_set.start)
-		kunit_free_suite_set(suite_set);
+	kunit_free_suite_set(suite_set);
 }
 
 static int kunit_module_notify(struct notifier_block *nb, unsigned long val,
 			       void *data)
 {
 	struct module *mod = data;
+	int ret = 0;
 
 	switch (val) {
 	case MODULE_STATE_COMING:
-		kunit_module_init(mod);
+		ret = kunit_module_init(mod);
 		break;
 	case MODULE_STATE_LIVE:
 		break;
@@ -795,7 +797,7 @@ static int kunit_module_notify(struct notifier_block *nb, unsigned long val,
 		break;
 	}
 
-	return 0;
+	return notifier_from_errno(ret);
 }
 
 static struct notifier_block kunit_mod_nb = {
-- 
2.34.1


  parent reply	other threads:[~2023-09-28  9:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-28  9:14 [PATCH RESEND 0/3] kunit: Init and run test suites in the right state Jinjie Ruan
2023-09-28  9:14 ` [PATCH RESEND 1/3] kunit: Make the cases sequence more reasonable for kunit_module_notify() Jinjie Ruan
2023-09-28  9:14 ` Jinjie Ruan [this message]
2023-09-28  9:14 ` [PATCH RESEND 3/3] kunit: Init and run test suites in the right state Jinjie Ruan
2023-09-28 16:42   ` Marco Pagani
2023-10-07  6:48     ` Ruan Jinjie

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=20230928091446.1209703-3-ruanjinjie@huawei.com \
    --to=ruanjinjie@huawei.com \
    --cc=brendan.higgins@linux.dev \
    --cc=davidgow@google.com \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=marpagan@redhat.com \
    --cc=rmoar@google.com \
    --cc=skhan@linuxfoundation.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.