summaryrefslogtreecommitdiff
path: root/drivers/tty/sysrq.c
diff options
context:
space:
mode:
authorJiri Slaby <jirislaby@kernel.org>2023-07-12 10:18:05 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-07-25 19:21:03 +0200
commita27f3b72337dd6884a5c8761574503cfdd9cf37e (patch)
tree5a49770bd6c762b37b0e10f99341bf3fd8c7f6e0 /drivers/tty/sysrq.c
parent8ac20a03da56d56a54b01dd0b62254826a84474d (diff)
tty: sysrq: use switch in sysrq_key_table_key2index()
Using switch with range cases makes the code more aligned and readable. Expand also that 36 as explicit addition of 10 + 26 to make the source of the constant more obvious. Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org> Link: https://lore.kernel.org/r/20230712081811.29004-5-jirislaby@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty/sysrq.c')
-rw-r--r--drivers/tty/sysrq.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
index 0a556628a255..28127bcb146d 100644
--- a/drivers/tty/sysrq.c
+++ b/drivers/tty/sysrq.c
@@ -532,17 +532,16 @@ static const struct sysrq_key_op *sysrq_key_table[62] = {
/* key2index calculation, -1 on invalid index */
static int sysrq_key_table_key2index(u8 key)
{
- int retval;
-
- if ((key >= '0') && (key <= '9'))
- retval = key - '0';
- else if ((key >= 'a') && (key <= 'z'))
- retval = key + 10 - 'a';
- else if ((key >= 'A') && (key <= 'Z'))
- retval = key + 36 - 'A';
- else
- retval = -1;
- return retval;
+ switch (key) {
+ case '0' ... '9':
+ return key - '0';
+ case 'a' ... 'z':
+ return key - 'a' + 10;
+ case 'A' ... 'Z':
+ return key - 'A' + 10 + 26;
+ default:
+ return -1;
+ }
}
/*