diff options
author | Andreas Gruenbacher <agruen@linbit.com> | 2011-03-14 12:27:45 -0400 |
---|---|---|
committer | Philipp Reisner <philipp.reisner@linbit.com> | 2011-10-14 10:47:53 -0400 |
commit | 6e849ce88cd63efc6650a1826d18ed742eb31999 (patch) | |
tree | a8cf7681d66c6a4b46c0aa803a74649d15958a1b | |
parent | 1b3bb47d526c63a845e3374d6272a67fbe20a468 (diff) |
drbd: Get rid of P_MAX_CMD
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>
-rw-r--r-- | drivers/block/drbd/drbd_int.h | 1 | ||||
-rw-r--r-- | drivers/block/drbd/drbd_main.c | 3 | ||||
-rw-r--r-- | drivers/block/drbd/drbd_receiver.c | 10 |
3 files changed, 5 insertions, 9 deletions
diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h index 17e905d0582d..be52b58a97d7 100644 --- a/drivers/block/drbd/drbd_int.h +++ b/drivers/block/drbd/drbd_int.h | |||
@@ -225,7 +225,6 @@ enum drbd_packet { | |||
225 | P_CONN_ST_CHG_REPLY = 0x2b, /* meta sock: Connection side state req reply */ | 225 | P_CONN_ST_CHG_REPLY = 0x2b, /* meta sock: Connection side state req reply */ |
226 | P_RETRY_WRITE = 0x2c, /* Protocol C: retry conflicting write request */ | 226 | P_RETRY_WRITE = 0x2c, /* Protocol C: retry conflicting write request */ |
227 | 227 | ||
228 | P_MAX_CMD = 0x2d, | ||
229 | P_MAY_IGNORE = 0x100, /* Flag to test if (cmd > P_MAY_IGNORE) ... */ | 228 | P_MAY_IGNORE = 0x100, /* Flag to test if (cmd > P_MAY_IGNORE) ... */ |
230 | P_MAX_OPT_CMD = 0x101, | 229 | P_MAX_OPT_CMD = 0x101, |
231 | 230 | ||
diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c index b93c5eccd73d..f43752fb5b52 100644 --- a/drivers/block/drbd/drbd_main.c +++ b/drivers/block/drbd/drbd_main.c | |||
@@ -3019,7 +3019,6 @@ const char *cmdname(enum drbd_packet cmd) | |||
3019 | [P_DELAY_PROBE] = "DelayProbe", | 3019 | [P_DELAY_PROBE] = "DelayProbe", |
3020 | [P_OUT_OF_SYNC] = "OutOfSync", | 3020 | [P_OUT_OF_SYNC] = "OutOfSync", |
3021 | [P_RETRY_WRITE] = "RetryWrite", | 3021 | [P_RETRY_WRITE] = "RetryWrite", |
3022 | [P_MAX_CMD] = NULL, | ||
3023 | }; | 3022 | }; |
3024 | 3023 | ||
3025 | if (cmd == P_HAND_SHAKE_M) | 3024 | if (cmd == P_HAND_SHAKE_M) |
@@ -3028,7 +3027,7 @@ const char *cmdname(enum drbd_packet cmd) | |||
3028 | return "HandShakeS"; | 3027 | return "HandShakeS"; |
3029 | if (cmd == P_HAND_SHAKE) | 3028 | if (cmd == P_HAND_SHAKE) |
3030 | return "HandShake"; | 3029 | return "HandShake"; |
3031 | if (cmd >= P_MAX_CMD) | 3030 | if (cmd >= ARRAY_SIZE(cmdnames)) |
3032 | return "Unknown"; | 3031 | return "Unknown"; |
3033 | return cmdnames[cmd]; | 3032 | return cmdnames[cmd]; |
3034 | } | 3033 | } |
diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c index 8c82d8945cf6..262e5d97991c 100644 --- a/drivers/block/drbd/drbd_receiver.c +++ b/drivers/block/drbd/drbd_receiver.c | |||
@@ -3875,9 +3875,6 @@ static struct data_cmd drbd_cmd_handler[] = { | |||
3875 | [P_DELAY_PROBE] = { 0, sizeof(struct p_delay_probe93), receive_skip }, | 3875 | [P_DELAY_PROBE] = { 0, sizeof(struct p_delay_probe93), receive_skip }, |
3876 | [P_OUT_OF_SYNC] = { 0, sizeof(struct p_block_desc), receive_out_of_sync }, | 3876 | [P_OUT_OF_SYNC] = { 0, sizeof(struct p_block_desc), receive_out_of_sync }, |
3877 | [P_CONN_ST_CHG_REQ] = { 0, sizeof(struct p_req_state), receive_req_state }, | 3877 | [P_CONN_ST_CHG_REQ] = { 0, sizeof(struct p_req_state), receive_req_state }, |
3878 | /* anything missing from this table is in | ||
3879 | * the asender_tbl, see get_asender_cmd */ | ||
3880 | [P_MAX_CMD] = { 0, 0, NULL }, | ||
3881 | }; | 3878 | }; |
3882 | 3879 | ||
3883 | /* All handler functions that expect a sub-header get that sub-heder in | 3880 | /* All handler functions that expect a sub-header get that sub-heder in |
@@ -3899,7 +3896,8 @@ static void drbdd(struct drbd_tconn *tconn) | |||
3899 | if (!drbd_recv_header(tconn, &pi)) | 3896 | if (!drbd_recv_header(tconn, &pi)) |
3900 | goto err_out; | 3897 | goto err_out; |
3901 | 3898 | ||
3902 | if (unlikely(pi.cmd >= P_MAX_CMD || !drbd_cmd_handler[pi.cmd].function)) { | 3899 | if (unlikely(pi.cmd >= ARRAY_SIZE(drbd_cmd_handler) || |
3900 | !drbd_cmd_handler[pi.cmd].function)) { | ||
3903 | conn_err(tconn, "unknown packet type %d, l: %d!\n", pi.cmd, pi.size); | 3901 | conn_err(tconn, "unknown packet type %d, l: %d!\n", pi.cmd, pi.size); |
3904 | goto err_out; | 3902 | goto err_out; |
3905 | } | 3903 | } |
@@ -4678,9 +4676,9 @@ static struct asender_cmd *get_asender_cmd(int cmd) | |||
4678 | [P_RS_CANCEL] = { sizeof(struct p_block_ack), got_NegRSDReply}, | 4676 | [P_RS_CANCEL] = { sizeof(struct p_block_ack), got_NegRSDReply}, |
4679 | [P_CONN_ST_CHG_REPLY]={ sizeof(struct p_req_state_reply), got_RqSReply }, | 4677 | [P_CONN_ST_CHG_REPLY]={ sizeof(struct p_req_state_reply), got_RqSReply }, |
4680 | [P_RETRY_WRITE] = { sizeof(struct p_block_ack), got_BlockAck }, | 4678 | [P_RETRY_WRITE] = { sizeof(struct p_block_ack), got_BlockAck }, |
4681 | [P_MAX_CMD] = { 0, NULL }, | ||
4682 | }; | 4679 | }; |
4683 | if (cmd > P_MAX_CMD || asender_tbl[cmd].process == NULL) | 4680 | |
4681 | if (cmd >= ARRAY_SIZE(asender_tbl) || !asender_tbl[cmd].process) | ||
4684 | return NULL; | 4682 | return NULL; |
4685 | return &asender_tbl[cmd]; | 4683 | return &asender_tbl[cmd]; |
4686 | } | 4684 | } |