From patchwork Sun Apr 8 03:06:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "(Exiting) Baolin Wang" X-Patchwork-Id: 10328085 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4AAA76020F for ; Sun, 8 Apr 2018 03:07:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39CD81FF81 for ; Sun, 8 Apr 2018 03:07:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2DE3228ED6; Sun, 8 Apr 2018 03:07:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8BD151FF81 for ; Sun, 8 Apr 2018 03:07:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752509AbeDHDHS (ORCPT ); Sat, 7 Apr 2018 23:07:18 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:45363 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752460AbeDHDHS (ORCPT ); Sat, 7 Apr 2018 23:07:18 -0400 Received: by mail-pf0-f194.google.com with SMTP id l27so3509072pfk.12 for ; Sat, 07 Apr 2018 20:07:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=84SSzDTkY2hCkcoLRIfG5McYSjtdMhfQSuVKVSRjK1M=; b=O7RI3IlHCnSu1+dOHGZ/GMDqZYI+gqnD1Mxev+/l0Hip9//I9u6C4KZ1IzsLvyRM+g nTzC+XeDag5v/W8uAlwO1h2bWpYYvvkG2GgZkUtpVYZYZlh60PzG1ybNTkgZ5YEbh+TZ uXtL/Fcon8vYJnHVKe8igHaprpe3rD+GGZ4vY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=84SSzDTkY2hCkcoLRIfG5McYSjtdMhfQSuVKVSRjK1M=; b=IdymQQ/GmuxpNUVGyxodHhw0eVedLBwoQRe9XjhE5RHP7wwzNiHC9jC9m8iLh/LqhY lLdII4Mp0pCbJd695uqffLhgyp9b25E7j7bMiJUAAOou69/SpDwHg0qtzkNEul/OQQTK LDrohF4Hg2E+pKYW2sEwMcOfh4d+skbVX3z7ILtbI+CPcAqt4cufQfGE97G94KWyjktx JqpQFpHnYcJ6FhGKqhQqCOFrAV7Fw23Z8Dlo3X85fbJM18oCAVzaxZhRndoHCdV61v/R 00AWBzvqwwlza1G7Fal1MWaNeslOPs9x6CoMH+z6iu6yqQPirQsvqGj3Gjt+yrQF+74U MUzA== X-Gm-Message-State: AElRT7F1gFxBj40M5nYdclrLrsfOPfpKugo3racAssw6umIY/6IBJxBz YKe/VYRAACgjLTZXURcy3UZY0A== X-Google-Smtp-Source: AIpwx4/PdzLfK4gMEqmel8RygXBxe2I5xYmt5L0lbsfx4oUrqT4t6o0QgU0bEVQ9R2lmJ9DwoqCehw== X-Received: by 10.101.73.74 with SMTP id q10mr21893538pgs.323.1523156837857; Sat, 07 Apr 2018 20:07:17 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id t25sm28279825pfj.187.2018.04.07.20.07.15 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 07 Apr 2018 20:07:17 -0700 (PDT) From: Baolin Wang To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: arnd@arndb.de, broonie@kernel.org, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, baolin.wang@linaro.org Subject: [PATCH 1/2] hwspinlock: Convert to use 'switch' statement Date: Sun, 8 Apr 2018 11:06:56 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- drivers/hwspinlock/hwspinlock_core.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/drivers/hwspinlock/hwspinlock_core.c b/drivers/hwspinlock/hwspinlock_core.c index 4074441..f4a59f5 100644 --- a/drivers/hwspinlock/hwspinlock_core.c +++ b/drivers/hwspinlock/hwspinlock_core.c @@ -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);