nsp: fix dentry usage 27/191027/2
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Tue, 25 Sep 2018 13:29:51 +0000 (16:29 +0300)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Thu, 11 Oct 2018 18:49:23 +0000 (21:49 +0300)
Change-Id: I752d857e7a24b07b92c007768c289fd46c60b989
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
modules/nsp/nsp.c

index a5be6a0a30b9de887fcadaf588e0fb73ac0555bf..53eb7ee411d2a0da4c4f09eb92a113c15a4de0eb 100644 (file)
@@ -25,6 +25,7 @@
 #include <writer/swap_msg.h>
 #include <kprobe/swap_ktd.h>
 #include <uprobe/swap_uaccess.h>
+#include <us_manager/swap_dcache.h>
 #include <us_manager/pf/pf_group.h>
 #include <us_manager/sspt/sspt_proc.h>
 #include <us_manager/probes/probe_info_new.h>
@@ -97,26 +98,19 @@ static struct probe_new p_do_app = {
  * =                the variables are initialized by the user                 =
  * ============================================================================
  */
-static const char *lpad_path;
 static struct dentry *lpad_dentry;
-
-static const char *libappcore_path;
 static struct dentry *libappcore_dentry;
-static const char *libcapi_path;
 static struct dentry *libcapi_dentry;
 
 static void uninit_variables(void)
 {
-       kfree(lpad_path);
-       lpad_path = NULL;
+       swap_dput(lpad_dentry);
        lpad_dentry = NULL;
 
-       kfree(libappcore_path);
-       libappcore_path = NULL;
+       swap_dput(libappcore_dentry);
        libappcore_dentry = NULL;
 
-       kfree(libcapi_path);
-       libcapi_path = NULL;
+       swap_dput(libcapi_dentry);
        libcapi_dentry = NULL;
 }
 
@@ -129,24 +123,17 @@ static int do_set_lpad_info(const char *path, unsigned long dlopen,
                            unsigned long dlsym)
 {
        struct dentry *dentry;
-       const char *new_path;
 
-       dentry = dentry_by_path(path);
+       dentry = swap_dget_by_path(path);
        if (dentry == NULL) {
                pr_err("dentry not found (path='%s')\n", path);
                return -EINVAL;
        }
 
-       new_path = kstrdup(path, GFP_KERNEL);
-       if (new_path == NULL) {
-               pr_err("out of memory\n");
-               return -ENOMEM;
-       }
-
-       kfree(lpad_path);
-
-       lpad_path = new_path;
+       /* update lpad_dentry */
+       swap_dput(lpad_dentry);
        lpad_dentry = dentry;
+
        p_dlopen.offset = dlopen;
        p_dlsym.offset = dlsym;
 
@@ -155,39 +142,28 @@ static int do_set_lpad_info(const char *path, unsigned long dlopen,
 
 static int do_set_appcore_info(struct nsp_info_data *info)
 {
-       struct dentry *dentry;
-       const char *new_path;
-       int ret = 0;
-
-       new_path = kstrdup(info->appcore_path, GFP_KERNEL);
-       if (!new_path)
-               return -ENOMEM;
-       kfree(libappcore_path);
-       libappcore_path = new_path;
+       struct dentry *appcore_dentry, *capi_dentry;
 
-       new_path = kstrdup(info->capi_path, GFP_KERNEL);
-       if (!new_path) {
-               ret = -ENOMEM;
-               goto fail_alloc;
-       }
-       kfree(libcapi_path);
-       libcapi_path = new_path;
-
-       dentry = dentry_by_path(info->appcore_path);
-       if (!dentry) {
+       appcore_dentry = swap_dget_by_path(info->appcore_path);
+       if (!appcore_dentry) {
                pr_err("dentry not found (path='%s')\n", info->appcore_path);
-               ret = -EINVAL;
-               goto fail;
+               return -EINVAL;
        }
-       libappcore_dentry = dentry;
 
-       dentry = dentry_by_path(info->capi_path);
-       if (!dentry) {
+       capi_dentry = swap_dget_by_path(info->capi_path);
+       if (!capi_dentry) {
                pr_err("dentry not found (path='%s')\n", info->capi_path);
-               ret = -EINVAL;
-               goto fail;
+               swap_dput(appcore_dentry);
+               return -EINVAL;
        }
-       libcapi_dentry = dentry;
+
+       /* update libappcore_dentry */
+       swap_dput(libappcore_dentry);
+       libappcore_dentry = appcore_dentry;
+
+       /* update libcapi_dentry */
+       swap_dput(libcapi_dentry);
+       libcapi_dentry = capi_dentry;
 
        p_ac_efl_main.offset = info->ac_efl_init;
        p_do_app.offset = info->do_app;
@@ -195,15 +171,6 @@ static int do_set_appcore_info(struct nsp_info_data *info)
        p_elm_run.offset = info->elm_run;
 
        return 0;
-
-fail:
-       kfree(libcapi_path);
-       libcapi_path = NULL;
-fail_alloc:
-       kfree(libappcore_path);
-       libappcore_path = NULL;
-
-       return ret;
 }
 
 
@@ -232,7 +199,7 @@ static struct nsp_data *nsp_data_create(const char *app_path,
        struct dentry *dentry;
        struct nsp_data *data;
 
-       dentry = dentry_by_path(app_path);
+       dentry = swap_dget_by_path(app_path);
        if (dentry == NULL)
                return ERR_PTR(-ENOENT);
 
@@ -256,6 +223,7 @@ static struct nsp_data *nsp_data_create(const char *app_path,
 
 static void nsp_data_destroy(struct nsp_data *data)
 {
+       swap_dput(data->app_dentry);
        kfree(data->app_path);
        kfree(data);
 }
@@ -386,21 +354,26 @@ static int __nsp_add(const char *app_path, unsigned long main_addr)
 
 static int __nsp_rm(const char *path)
 {
+       int ret = 0;
        struct dentry *dentry;
        struct nsp_data *data;
 
-       dentry = dentry_by_path(path);
+       dentry = swap_dget_by_path(path);
        if (dentry == NULL)
                return -ENOENT;
 
        data = nsp_data_find(dentry);
-       if (data == NULL)
-               return -ESRCH;
+       if (data == NULL) {
+               ret = -ESRCH;
+               goto put_dentry;
+       }
 
        nsp_data_rm(data);
        nsp_data_destroy(data);
 
-       return 0;
+put_dentry:
+       swap_dput(dentry);
+       return ret;
 }
 
 static int __nsp_rm_all(void)