n_gsm: introduce enum gsm_dlci_state
authorJiri Slaby <jslaby@suse.cz>
Wed, 19 Feb 2020 08:49:41 +0000 (09:49 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 19 Feb 2020 11:46:47 +0000 (12:46 +0100)
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>
Link: https://lore.kernel.org/r/20200219084949.28074-2-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/n_gsm.c

index 828c0c7babddb618722677df6a12ecb9308de8f2..1d0a140027fffdc014ddc7516c68bae8fe903528 100644 (file)
@@ -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 */