From: Jiri Slaby <jslaby@suse.cz>
To: gregkh@linuxfoundation.org
Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
Jiri Slaby <jslaby@suse.cz>
Subject: [PATCH 04/10] n_gsm: introduce enum gsm_mux_state
Date: Wed, 19 Feb 2020 09:49:43 +0100 [thread overview]
Message-ID: <20200219084949.28074-4-jslaby@suse.cz> (raw)
In-Reply-To: <20200219084949.28074-1-jslaby@suse.cz>
gsm_mux->state is clearly an enumeration. So introduce one and use it
-- compiler now checks if valid values are assigned to the field.
Note that a compiler warns about unhandled cases in switch. Add default
cases with a pr_debug (which is not printed by default).
The values of the states are preserved thanks to the nature of enum.
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
drivers/tty/n_gsm.c | 33 +++++++++++++++++++++------------
1 file changed, 21 insertions(+), 12 deletions(-)
diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index 7fee5a580f21..82e3d88c1f3f 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -173,6 +173,20 @@ struct gsm_control {
int error; /* Error if any */
};
+enum gsm_mux_state {
+ GSM_SEARCH,
+ GSM_START,
+ GSM_ADDRESS,
+ GSM_CONTROL,
+ GSM_LEN,
+ GSM_DATA,
+ GSM_FCS,
+ GSM_OVERRUN,
+ GSM_LEN0,
+ GSM_LEN1,
+ GSM_SSOF,
+};
+
/*
* Each GSM mux we have is represented by this structure. If we are
* operating as an ldisc then we use this structure as our ldisc
@@ -197,18 +211,7 @@ struct gsm_mux {
/* Framing Layer */
unsigned char *buf;
- int state;
-#define GSM_SEARCH 0
-#define GSM_START 1
-#define GSM_ADDRESS 2
-#define GSM_CONTROL 3
-#define GSM_LEN 4
-#define GSM_DATA 5
-#define GSM_FCS 6
-#define GSM_OVERRUN 7
-#define GSM_LEN0 8
-#define GSM_LEN1 9
-#define GSM_SSOF 10
+ enum gsm_mux_state state;
unsigned int len;
unsigned int address;
unsigned int count;
@@ -1934,6 +1937,9 @@ static void gsm0_receive(struct gsm_mux *gsm, unsigned char c)
break;
}
break;
+ default:
+ pr_debug("%s: unhandled state: %d\n", __func__, gsm->state);
+ break;
}
}
@@ -2008,6 +2014,9 @@ static void gsm1_receive(struct gsm_mux *gsm, unsigned char c)
break;
case GSM_OVERRUN: /* Over-long - eg a dropped SOF */
break;
+ default:
+ pr_debug("%s: unhandled state: %d\n", __func__, gsm->state);
+ break;
}
}
--
2.25.0
next prev parent reply other threads:[~2020-02-19 8:50 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-19 8:49 [PATCH 01/10] n_gsm: drop unneeded gsm_dlci->fifo field Jiri Slaby
2020-02-19 8:49 ` [PATCH 02/10] n_gsm: introduce enum gsm_dlci_state Jiri Slaby
2020-02-19 8:49 ` [PATCH 03/10] n_gsm: introduce enum gsm_dlci_mode Jiri Slaby
2020-02-19 8:49 ` Jiri Slaby [this message]
2020-02-19 8:49 ` [PATCH 05/10] n_gsm: add missing __user annotations Jiri Slaby
2020-02-19 8:49 ` [PATCH 06/10] n_gsm: add missing \n to prints Jiri Slaby
2020-02-19 8:49 ` [PATCH 07/10] n_gsm: switch dead to bool Jiri Slaby
2020-02-19 8:49 ` [PATCH 08/10] n_gsm: switch throttled " Jiri Slaby
2020-02-19 8:49 ` [PATCH 09/10] n_gsm: switch constipated " Jiri Slaby
2020-02-19 8:49 ` [PATCH 10/10] n_gsm: switch escape " Jiri Slaby
2020-02-20 19:44 ` [PATCH 01/10] n_gsm: drop unneeded gsm_dlci->fifo field Tony Lindgren
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=20200219084949.28074-4-jslaby@suse.cz \
--to=jslaby@suse.cz \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@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).