diff options
author | Kent Gibson <warthog618@gmail.com> | 2022-07-14 10:03:16 +0800 |
---|---|---|
committer | Bartosz Golaszewski <brgl@bgdev.pl> | 2022-07-19 10:01:25 +0200 |
commit | cfa53463ac62d30e4f30ec6e171b9228689d5a83 (patch) | |
tree | 47880f8f0b68c64389a6a8de4d96858a3d6eef6f /drivers/gpio/gpiolib-cdev.c | |
parent | 2487a812236cdeecd0729cfc673fa352db44da5d (diff) | |
download | linux-cfa53463ac62d30e4f30ec6e171b9228689d5a83.tar.bz2 |
gpiolib: cdev: replace if-else chains with switches
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>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Diffstat (limited to 'drivers/gpio/gpiolib-cdev.c')
-rw-r--r-- | drivers/gpio/gpiolib-cdev.c | 31 |
1 files 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++; |