hwspinlock: Convert to use 'switch' statement
authorBaolin Wang <baolin.wang@linaro.org>
Sun, 8 Apr 2018 03:06:56 +0000 (11:06 +0800)
committerBjorn Andersson <bjorn.andersson@linaro.org>
Tue, 17 Apr 2018 21:48:22 +0000 (14:48 -0700)
We have different hwspinlock modes to select, thus it will be more
readable to handle different modes with using 'switch' statement
instead of 'if' statement.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
drivers/hwspinlock/hwspinlock_core.c

index 4074441444fed29128574a1f0a5c1143de857cd7..f4a59f5631e47921493130bd47b1b8e8c172ced0 100644 (file)
@@ -106,12 +106,17 @@ int __hwspin_trylock(struct hwspinlock *hwlock, int mode, unsigned long *flags)
         *    problems with hwspinlock usage (e.g. scheduler checks like
         *    'scheduling while atomic' etc.)
         */
-       if (mode == HWLOCK_IRQSTATE)
+       switch (mode) {
+       case HWLOCK_IRQSTATE:
                ret = spin_trylock_irqsave(&hwlock->lock, *flags);
-       else if (mode == HWLOCK_IRQ)
+               break;
+       case HWLOCK_IRQ:
                ret = spin_trylock_irq(&hwlock->lock);
-       else
+               break;
+       default:
                ret = spin_trylock(&hwlock->lock);
+               break;
+       }
 
        /* is lock already taken by another context on the local cpu ? */
        if (!ret)
@@ -122,12 +127,17 @@ int __hwspin_trylock(struct hwspinlock *hwlock, int mode, unsigned long *flags)
 
        /* if hwlock is already taken, undo spin_trylock_* and exit */
        if (!ret) {
-               if (mode == HWLOCK_IRQSTATE)
+               switch (mode) {
+               case HWLOCK_IRQSTATE:
                        spin_unlock_irqrestore(&hwlock->lock, *flags);
-               else if (mode == HWLOCK_IRQ)
+                       break;
+               case HWLOCK_IRQ:
                        spin_unlock_irq(&hwlock->lock);
-               else
+                       break;
+               default:
                        spin_unlock(&hwlock->lock);
+                       break;
+               }
 
                return -EBUSY;
        }
@@ -249,12 +259,17 @@ void __hwspin_unlock(struct hwspinlock *hwlock, int mode, unsigned long *flags)
        hwlock->bank->ops->unlock(hwlock);
 
        /* Undo the spin_trylock{_irq, _irqsave} called while locking */
-       if (mode == HWLOCK_IRQSTATE)
+       switch (mode) {
+       case HWLOCK_IRQSTATE:
                spin_unlock_irqrestore(&hwlock->lock, *flags);
-       else if (mode == HWLOCK_IRQ)
+               break;
+       case HWLOCK_IRQ:
                spin_unlock_irq(&hwlock->lock);
-       else
+               break;
+       default:
                spin_unlock(&hwlock->lock);
+               break;
+       }
 }
 EXPORT_SYMBOL_GPL(__hwspin_unlock);