From: Kent Gibson <warthog618@gmail.com>
To: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org,
brgl@bgdev.pl, linus.walleij@linaro.org, dipenp@nvidia.com,
andy.shevchenko@gmail.com
Cc: Kent Gibson <warthog618@gmail.com>
Subject: [PATCH v2 3/6] gpiolib: cdev: replace if-else chains with switches
Date: Thu, 14 Jul 2022 10:03:16 +0800 [thread overview]
Message-ID: <20220714020319.72952-4-warthog618@gmail.com> (raw)
In-Reply-To: <20220714020319.72952-1-warthog618@gmail.com>
Improve readability by replacing if-else chains with switch
statements.
Signed-off-by: Kent Gibson <warthog618@gmail.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
---
drivers/gpio/gpiolib-cdev.c | 31 ++++++++++++++++++-------------
1 file changed, 18 insertions(+), 13 deletions(-)
diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
index f635bbbb6a6d..bc7c8822ede0 100644
--- a/drivers/gpio/gpiolib-cdev.c
+++ b/drivers/gpio/gpiolib-cdev.c
@@ -588,7 +588,8 @@ static enum hte_return process_hw_ts_thread(void *p)
le.timestamp_ns = line->timestamp_ns;
eflags = READ_ONCE(line->eflags);
- if (eflags == GPIO_V2_LINE_FLAG_EDGE_BOTH) {
+ switch (eflags) {
+ case GPIO_V2_LINE_FLAG_EDGE_BOTH:
if (line->raw_level >= 0) {
if (test_bit(FLAG_ACTIVE_LOW, &line->desc->flags))
level = !line->raw_level;
@@ -602,13 +603,16 @@ static enum hte_return process_hw_ts_thread(void *p)
le.id = GPIO_V2_LINE_EVENT_RISING_EDGE;
else
le.id = GPIO_V2_LINE_EVENT_FALLING_EDGE;
- } else if (eflags == GPIO_V2_LINE_FLAG_EDGE_RISING) {
+ break;
+ case GPIO_V2_LINE_FLAG_EDGE_RISING:
/* Emit low-to-high event */
le.id = GPIO_V2_LINE_EVENT_RISING_EDGE;
- } else if (eflags == GPIO_V2_LINE_FLAG_EDGE_FALLING) {
+ break;
+ case GPIO_V2_LINE_FLAG_EDGE_FALLING:
/* Emit high-to-low event */
le.id = GPIO_V2_LINE_EVENT_FALLING_EDGE;
- } else {
+ break;
+ default:
return HTE_CB_HANDLED;
}
le.line_seqno = line->line_seqno;
@@ -660,7 +664,6 @@ static irqreturn_t edge_irq_thread(int irq, void *p)
struct line *line = p;
struct linereq *lr = line->req;
struct gpio_v2_line_event le;
- u64 eflags;
/* Do not leak kernel stack to userspace */
memset(&le, 0, sizeof(le));
@@ -679,23 +682,25 @@ static irqreturn_t edge_irq_thread(int irq, void *p)
}
line->timestamp_ns = 0;
- eflags = READ_ONCE(line->eflags);
- if (eflags == GPIO_V2_LINE_FLAG_EDGE_BOTH) {
- int level = gpiod_get_value_cansleep(line->desc);
-
- if (level)
+ switch (READ_ONCE(line->eflags)) {
+ case GPIO_V2_LINE_FLAG_EDGE_BOTH:
+ if (gpiod_get_value_cansleep(line->desc))
/* Emit low-to-high event */
le.id = GPIO_V2_LINE_EVENT_RISING_EDGE;
else
/* Emit high-to-low event */
le.id = GPIO_V2_LINE_EVENT_FALLING_EDGE;
- } else if (eflags == GPIO_V2_LINE_FLAG_EDGE_RISING) {
+
+ break;
+ case GPIO_V2_LINE_FLAG_EDGE_RISING:
/* Emit low-to-high event */
le.id = GPIO_V2_LINE_EVENT_RISING_EDGE;
- } else if (eflags == GPIO_V2_LINE_FLAG_EDGE_FALLING) {
+ break;
+ case GPIO_V2_LINE_FLAG_EDGE_FALLING:
/* Emit high-to-low event */
le.id = GPIO_V2_LINE_EVENT_FALLING_EDGE;
- } else {
+ break;
+ default:
return IRQ_NONE;
}
line->line_seqno++;
--
2.37.1
next prev parent reply other threads:[~2022-07-14 2:04 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-14 2:03 [PATCH v2 0/6] gpiolib: cdev: code cleanup following hte integration Kent Gibson
2022-07-14 2:03 ` [PATCH v2 1/6] gpiolib: cdev: simplify linereq_free Kent Gibson
2022-07-15 5:09 ` Dipen Patel
2022-07-18 9:28 ` Linus Walleij
2022-07-14 2:03 ` [PATCH v2 2/6] gpiolib: cdev: simplify parameter in call to hte_edge_setup Kent Gibson
2022-07-15 5:10 ` Dipen Patel
2022-07-18 9:29 ` Linus Walleij
2022-07-14 2:03 ` Kent Gibson [this message]
2022-07-18 9:30 ` [PATCH v2 3/6] gpiolib: cdev: replace if-else chains with switches Linus Walleij
2022-07-14 2:03 ` [PATCH v2 4/6] gpiolib: cdev: simplify line event identification Kent Gibson
2022-07-18 9:31 ` Linus Walleij
2022-07-14 2:03 ` [PATCH v2 5/6] gpiolib: cdev: consolidate edge detector configuration flags Kent Gibson
2022-07-18 9:33 ` Linus Walleij
2022-07-18 9:46 ` Kent Gibson
2022-07-14 2:03 ` [PATCH v2 6/6] gpiolib: cdev: compile out HTE unless CONFIG_HTE selected Kent Gibson
2022-07-18 9:34 ` Linus Walleij
2022-07-18 21:32 ` [PATCH v2 0/6] gpiolib: cdev: code cleanup following hte integration Dipen Patel
2022-07-19 8:03 ` Bartosz Golaszewski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220714020319.72952-4-warthog618@gmail.com \
--to=warthog618@gmail.com \
--cc=andy.shevchenko@gmail.com \
--cc=brgl@bgdev.pl \
--cc=dipenp@nvidia.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).