[PATCH 4/5] test_kmod: fix the lock in register_test_dev_kmod()

From: Luis R. Rodriguez
Date: Wed Aug 02 2017 - 17:15:41 EST

From: Dan Carpenter <dan.carpenter@xxxxxxxxxx>

We accidentally just drop the lock twice instead of taking it and then
releasing it. This isn't a big issue unless you are adding more than
one device to test on, and the kmod.sh doesn't do that yet, however
this obviously is the correct thing to do.

Fixes: 39258f448d71 ("kmod: add test driver to stress test the module loader")
Signed-off-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
[mcgrof: massaged subject, explain what happens]
Signed-off-by: Luis R. Rodriguez <mcgrof@xxxxxxxxxx>
lib/test_kmod.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/test_kmod.c b/lib/test_kmod.c
index 8fc0a7a19c83..1bc06bbfc97a 100644
--- a/lib/test_kmod.c
+++ b/lib/test_kmod.c
@@ -1146,7 +1146,7 @@ static struct kmod_test_device *register_test_dev_kmod(void)
struct kmod_test_device *test_dev = NULL;
int ret;

- mutex_unlock(&reg_dev_mutex);
+ mutex_lock(&reg_dev_mutex);

/* int should suffice for number of devices, test for wrap */
if (unlikely(num_test_devs + 1) < 0) {