misc: tegra-profiler: add start/stop locks
Igor Nabirushkin [Sun, 26 Jan 2014 16:37:31 +0000 (20:37 +0400)]
Locks for ability to use loadable module
to override the built-in driver on rooted devices

Bug 1447640

Change-Id: If20605597d77a0cf76206fbe2f474c8853696a9b
Signed-off-by: Igor Nabirushkin <inabirushkin@nvidia.com>
Reviewed-on: http://git-master/r/360134
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Bharat Nihalani <bnihalani@nvidia.com>
Tested-by: Bharat Nihalani <bnihalani@nvidia.com>

drivers/misc/tegra-profiler/main.c
drivers/misc/tegra-profiler/quadd.h
drivers/misc/tegra-profiler/version.h
include/linux/tegra_profiler.h

index 3829d8c..493cc7f 100644 (file)
@@ -54,16 +54,33 @@ static int get_default_properties(void)
        return 0;
 }
 
+int tegra_profiler_try_lock(void)
+{
+       return atomic_cmpxchg(&ctx.tegra_profiler_lock, 0, 1);
+}
+EXPORT_SYMBOL_GPL(tegra_profiler_try_lock);
+
+void tegra_profiler_unlock(void)
+{
+       atomic_set(&ctx.tegra_profiler_lock, 0);
+}
+EXPORT_SYMBOL_GPL(tegra_profiler_unlock);
+
 static int start(void)
 {
        int err;
 
+       if (tegra_profiler_try_lock()) {
+               pr_err("Error: tegra_profiler lock\n");
+               return -EBUSY;
+       }
+
        if (!atomic_cmpxchg(&ctx.started, 0, 1)) {
                if (ctx.pmu) {
                        err = ctx.pmu->enable();
                        if (err) {
                                pr_err("error: pmu enable\n");
-                               return err;
+                               goto errout;
                        }
                }
 
@@ -71,7 +88,7 @@ static int start(void)
                        err = ctx.pl310->enable();
                        if (err) {
                                pr_err("error: pl310 enable\n");
-                               return err;
+                               goto errout;
                        }
                }
 
@@ -81,17 +98,22 @@ static int start(void)
                err = quadd_power_clk_start();
                if (err < 0) {
                        pr_err("error: power_clk start\n");
-                       return err;
+                       goto errout;
                }
 
                err = quadd_hrt_start();
                if (err) {
                        pr_err("error: hrt start\n");
-                       return err;
+                       goto errout;
                }
        }
 
        return 0;
+
+errout:
+       atomic_set(&ctx.started, 0);
+       tegra_profiler_unlock();
+       return err;
 }
 
 static void stop(void)
@@ -109,6 +131,8 @@ static void stop(void)
 
                if (ctx.pl310)
                        ctx.pl310->disable();
+
+               tegra_profiler_unlock();
        }
 }
 
@@ -407,7 +431,9 @@ static int __init quadd_module_init(void)
 #ifdef QM_DEBUG_SAMPLES_ENABLE
        pr_info("############## DEBUG VERSION! ##############\n");
 #endif
+
        atomic_set(&ctx.started, 0);
+       atomic_set(&ctx.tegra_profiler_lock, 0);
 
        get_default_properties();
 
index 3815f61..8e4d591 100644 (file)
@@ -60,6 +60,7 @@ struct quadd_ctx {
        struct quadd_mmap_ctx *mmap;
 
        atomic_t started;
+       atomic_t tegra_profiler_lock;
 
        int collect_kernel_ips;
 };
index b6b9a9c..090ff1b 100644 (file)
@@ -18,7 +18,7 @@
 #ifndef __QUADD_VERSION_H
 #define __QUADD_VERSION_H
 
-#define QUADD_MODULE_VERSION           "1.41"
+#define QUADD_MODULE_VERSION           "1.42"
 #define QUADD_MODULE_BRANCH            "Dev"
 
 #endif /* __QUADD_VERSION_H */
index e3f90a2..277fc93 100644 (file)
@@ -37,6 +37,9 @@
 #define QUADD_DEVICE_NAME      "quadd"
 #define QUADD_AUTH_DEVICE_NAME "quadd_auth"
 
+#define QUADD_MOD_DEVICE_NAME          "quadd_mod"
+#define QUADD_MOD_AUTH_DEVICE_NAME     "quadd_mod_auth"
+
 #define QUADD_IOCTL    100
 
 /*