ratelimit: Fix/allow use in atomic contexts
[firefly-linux-kernel-4.4.55.git] / lib / ratelimit.c
index 0e2c28e8a0ca979a8cf6e2b48b1a43fbea743393..69bfcacda16dce314b9f2658e84f2a7902a1dc6b 100644 (file)
@@ -28,7 +28,15 @@ int __ratelimit(struct ratelimit_state *rs)
        if (!rs->interval)
                return 1;
 
-       spin_lock_irqsave(&rs->lock, flags);
+       /*
+        * If we contend on this state's lock then almost
+        * by definition we are too busy to print a message,
+        * in addition to the one that will be printed by
+        * the entity that is holding the lock already:
+        */
+       if (!spin_trylock_irqsave(&rs->lock, flags))
+               return 1;
+
        if (!rs->begin)
                rs->begin = jiffies;