return -EINVAL;
        }
 
+       mutex_lock(&damon_dbgfs_lock);
        if (!strncmp(kbuf, "on", count)) {
                int i;
 
                for (i = 0; i < dbgfs_nr_ctxs; i++) {
                        if (damon_targets_empty(dbgfs_ctxs[i])) {
                                kfree(kbuf);
+                               mutex_unlock(&damon_dbgfs_lock);
                                return -EINVAL;
                        }
                }
        } else {
                ret = -EINVAL;
        }
+       mutex_unlock(&damon_dbgfs_lock);
 
        if (!ret)
                ret = count;
 
 static int __init damon_dbgfs_init(void)
 {
-       int rc;
+       int rc = -ENOMEM;
 
+       mutex_lock(&damon_dbgfs_lock);
        dbgfs_ctxs = kmalloc(sizeof(*dbgfs_ctxs), GFP_KERNEL);
        if (!dbgfs_ctxs)
-               return -ENOMEM;
+               goto out;
        dbgfs_ctxs[0] = dbgfs_new_ctx();
        if (!dbgfs_ctxs[0]) {
                kfree(dbgfs_ctxs);
-               return -ENOMEM;
+               goto out;
        }
        dbgfs_nr_ctxs = 1;
 
                pr_err("%s: dbgfs init failed\n", __func__);
        }
 
+out:
+       mutex_unlock(&damon_dbgfs_lock);
        return rc;
 }