soc/tegra: pmc: Ensure mutex is always initialised
authorJon Hunter <jonathanh@nvidia.com>
Tue, 28 Jun 2016 10:38:26 +0000 (11:38 +0100)
committerThierry Reding <treding@nvidia.com>
Thu, 30 Jun 2016 10:23:07 +0000 (12:23 +0200)
The mutex used by the PMC driver may not be initialised if early
initialisation of the driver fails. If this does happen, then it could
be possible for callers of the public PMC functions to still attempt to
acquire the mutex. Fix this by initialising the mutex as soon as
possible to ensure it will always be initialised.

Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>
drivers/soc/tegra/pmc.c

index ed2b2c8..483d546 100644 (file)
@@ -1504,6 +1504,8 @@ static int __init tegra_pmc_early_init(void)
        bool invert;
        u32 value;
 
+       mutex_init(&pmc->powergates_lock);
+
        np = of_find_matching_node_and_match(NULL, tegra_pmc_match, &match);
        if (!np) {
                /*
@@ -1548,8 +1550,6 @@ static int __init tegra_pmc_early_init(void)
                return -ENXIO;
        }
 
-       mutex_init(&pmc->powergates_lock);
-
        if (np) {
                pmc->soc = match->data;