linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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 02/10] n_gsm: introduce enum gsm_dlci_state
Date: Wed, 19 Feb 2020 09:49:41 +0100	[thread overview]
Message-ID: <20200219084949.28074-2-jslaby@suse.cz> (raw)
In-Reply-To: <20200219084949.28074-1-jslaby@suse.cz>

gsm_dlci->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).

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/tty/n_gsm.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index 828c0c7babdd..1d0a140027ff 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -100,6 +100,13 @@ struct gsm_msg {
 	unsigned char buffer[];
 };
 
+enum gsm_dlci_state {
+	DLCI_CLOSED,
+	DLCI_OPENING,		/* Sending SABM not seen UA */
+	DLCI_OPEN,		/* SABM/UA complete */
+	DLCI_CLOSING,		/* Sending DISC not seen UA/DM */
+};
+
 /*
  *	Each active data link has a gsm_dlci structure associated which ties
  *	the link layer to an optional tty (if the tty side is open). To avoid
@@ -113,11 +120,7 @@ struct gsm_msg {
 struct gsm_dlci {
 	struct gsm_mux *gsm;
 	int addr;
-	int state;
-#define DLCI_CLOSED		0
-#define DLCI_OPENING		1	/* Sending SABM not seen UA */
-#define DLCI_OPEN		2	/* SABM/UA complete */
-#define DLCI_CLOSING		3	/* Sending DISC not seen UA/DM */
+	enum gsm_dlci_state state;
 	struct mutex mutex;
 
 	/* Link layer */
@@ -1495,6 +1498,9 @@ static void gsm_dlci_t1(struct timer_list *t)
 		} else
 			gsm_dlci_close(dlci);
 		break;
+	default:
+		pr_debug("%s: unhandled state: %d\n", __func__, dlci->state);
+		break;
 	}
 }
 
@@ -1808,6 +1814,10 @@ static void gsm_queue(struct gsm_mux *gsm)
 		case DLCI_OPENING:
 			gsm_dlci_open(dlci);
 			break;
+		default:
+			pr_debug("%s: unhandled state: %d\n", __func__,
+					dlci->state);
+			break;
 		}
 		break;
 	case DM:	/* DM can be valid unsolicited */
-- 
2.25.0


  reply	other threads:[~2020-02-19  8:49 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 ` Jiri Slaby [this message]
2020-02-19  8:49 ` [PATCH 03/10] n_gsm: introduce enum gsm_dlci_mode Jiri Slaby
2020-02-19  8:49 ` [PATCH 04/10] n_gsm: introduce enum gsm_mux_state Jiri Slaby
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-2-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).