video: tegra: host: power module before access
Bibek Basu [Wed, 30 Jul 2014 06:27:09 +0000 (11:27 +0530)]
There could be race in refcount update leading to
access of module registers without enabling the clock
and power.This patch tries to catch such instances
and enables power.

Bug 1478467

Change-Id: Ia32da44bfcd7838e312815b6261ccadf4470a761
Signed-off-by: Bibek Basu <bbasu@nvidia.com>
Reviewed-on: http://git-master/r/448701
Reviewed-by: Automatic_Commit_Validation_User
GVS: Gerrit_Virtual_Submit
Reviewed-by: Venkat Moganty <vmoganty@nvidia.com>
Reviewed-by: Matthew Pedro <mapedro@nvidia.com>

drivers/video/tegra/host/nvhost_acm.c

index 5bde55a..fcedb5c 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Tegra Graphics Host Automatic Clock Management
  *
- * Copyright (c) 2010-2012, NVIDIA Corporation. All rights reserved.
+ * Copyright (c) 2010-2014, NVIDIA Corporation. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
@@ -219,8 +219,11 @@ void nvhost_module_busy(struct nvhost_device *dev)
        cancel_delayed_work(&dev->powerstate_down);
 
        dev->refcount++;
-       if (dev->refcount > 0 && !nvhost_module_powered(dev))
+       if (unlikely(dev->refcount <= 0))
+               pr_err("unbalanced refcount %d\n", dev->refcount);
+       if (!nvhost_module_powered(dev))
                to_state_running_locked(dev);
+
        mutex_unlock(&dev->lock);
 }