drbd: Get rid of P_MAX_CMD
authorAndreas Gruenbacher <agruen@linbit.com>
Mon, 14 Mar 2011 16:27:45 +0000 (17:27 +0100)
committerPhilipp Reisner <philipp.reisner@linbit.com>
Fri, 14 Oct 2011 14:47:53 +0000 (16:47 +0200)
Instead of artificially enlarging the command decoding arrays to
P_MAX_CMD entries, check if an index is within the valid range using the
ARRAY_SIZE() macro.

Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
drivers/block/drbd/drbd_int.h
drivers/block/drbd/drbd_main.c
drivers/block/drbd/drbd_receiver.c

index 17e905d0582d9c35ebb7135b9724bcfabff1185f..be52b58a97d79e406f0f5665085140a78860f208 100644 (file)
@@ -225,7 +225,6 @@ enum drbd_packet {
        P_CONN_ST_CHG_REPLY   = 0x2b, /* meta sock: Connection side state req reply */
        P_RETRY_WRITE         = 0x2c, /* Protocol C: retry conflicting write request */
 
-       P_MAX_CMD             = 0x2d,
        P_MAY_IGNORE          = 0x100, /* Flag to test if (cmd > P_MAY_IGNORE) ... */
        P_MAX_OPT_CMD         = 0x101,
 
index b93c5eccd73d5827725bc948c32fbaed007e9f7c..f43752fb5b52cd4fe9e3f59c2a3b33135d4ae27e 100644 (file)
@@ -3019,7 +3019,6 @@ const char *cmdname(enum drbd_packet cmd)
                [P_DELAY_PROBE]         = "DelayProbe",
                [P_OUT_OF_SYNC]         = "OutOfSync",
                [P_RETRY_WRITE]         = "RetryWrite",
-               [P_MAX_CMD]             = NULL,
        };
 
        if (cmd == P_HAND_SHAKE_M)
@@ -3028,7 +3027,7 @@ const char *cmdname(enum drbd_packet cmd)
                return "HandShakeS";
        if (cmd == P_HAND_SHAKE)
                return "HandShake";
-       if (cmd >= P_MAX_CMD)
+       if (cmd >= ARRAY_SIZE(cmdnames))
                return "Unknown";
        return cmdnames[cmd];
 }
index 8c82d8945cf606ace45e5ea2dcca9e984ce66222..262e5d97991c6b174e6158ff7bd1075364879519 100644 (file)
@@ -3875,9 +3875,6 @@ static struct data_cmd drbd_cmd_handler[] = {
        [P_DELAY_PROBE]     = { 0, sizeof(struct p_delay_probe93), receive_skip },
        [P_OUT_OF_SYNC]     = { 0, sizeof(struct p_block_desc), receive_out_of_sync },
        [P_CONN_ST_CHG_REQ] = { 0, sizeof(struct p_req_state), receive_req_state },
-       /* anything missing from this table is in
-        * the asender_tbl, see get_asender_cmd */
-       [P_MAX_CMD]         = { 0, 0, NULL },
 };
 
 /* All handler functions that expect a sub-header get that sub-heder in
@@ -3899,7 +3896,8 @@ static void drbdd(struct drbd_tconn *tconn)
                if (!drbd_recv_header(tconn, &pi))
                        goto err_out;
 
-               if (unlikely(pi.cmd >= P_MAX_CMD || !drbd_cmd_handler[pi.cmd].function)) {
+               if (unlikely(pi.cmd >= ARRAY_SIZE(drbd_cmd_handler) ||
+                   !drbd_cmd_handler[pi.cmd].function)) {
                        conn_err(tconn, "unknown packet type %d, l: %d!\n", pi.cmd, pi.size);
                        goto err_out;
                }
@@ -4678,9 +4676,9 @@ static struct asender_cmd *get_asender_cmd(int cmd)
        [P_RS_CANCEL]       = { sizeof(struct p_block_ack), got_NegRSDReply},
        [P_CONN_ST_CHG_REPLY]={ sizeof(struct p_req_state_reply), got_RqSReply },
        [P_RETRY_WRITE]     = { sizeof(struct p_block_ack), got_BlockAck },
-       [P_MAX_CMD]         = { 0, NULL },
        };
-       if (cmd > P_MAX_CMD || asender_tbl[cmd].process == NULL)
+
+       if (cmd >= ARRAY_SIZE(asender_tbl) || !asender_tbl[cmd].process)
                return NULL;
        return &asender_tbl[cmd];
 }
This page took 0.031617 seconds and 5 git commands to generate.