memory: tegra20: Protect debug code with a lock
authorDmitry Osipenko <digetx@gmail.com>
Tue, 23 Mar 2021 21:04:46 +0000 (00:04 +0300)
committerKrzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Thu, 1 Apr 2021 17:58:22 +0000 (19:58 +0200)
Simultaneous accesses to MC_STAT h/w shouldn't be allowed since one
collection process stomps on another. There is no good reason for
polling stats in parallel in practice, nevertheless let's add a
protection lock, just for consistency.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
Link: https://lore.kernel.org/r/20210323210446.24867-2-digetx@gmail.com
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
drivers/memory/tegra/tegra20.c

index 4659c0cea30d95d1e97cc43accc88cb4a586bea7..2db68a913b7af0af5a3b9ee23282e77db3887ff7 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <linux/bitfield.h>
 #include <linux/delay.h>
+#include <linux/mutex.h>
 #include <linux/of_device.h>
 #include <linux/slab.h>
 #include <linux/string.h>
@@ -55,6 +56,8 @@
 /* we store collected statistics as a fixed point values */
 #define MC_FX_FRAC_SCALE                       100
 
+static DEFINE_MUTEX(tegra20_mc_stat_lock);
+
 struct tegra20_mc_stat_gather {
        unsigned int pri_filter;
        unsigned int pri_event;
@@ -615,8 +618,12 @@ static int tegra20_mc_stats_show(struct seq_file *s, void *unused)
        if (!stats)
                return -ENOMEM;
 
+       mutex_lock(&tegra20_mc_stat_lock);
+
        tegra20_mc_collect_stats(mc, stats);
 
+       mutex_unlock(&tegra20_mc_stat_lock);
+
        seq_puts(s, "Memory client   Events   Timeout   High priority   Bandwidth ARB   RW change   Successive   Page miss\n");
        seq_puts(s, "-----------------------------------------------------------------------------------------------------\n");