Skip to content

Commit 1b31003

Browse files
diandersDaniel Thompson
authored andcommitted
kdb: Cleanup math with KDB_CMD_HISTORY_COUNT
From code inspection the math in handle_ctrl_cmd() looks super sketchy because it subjects -1 from cmdptr and then does a "% KDB_CMD_HISTORY_COUNT". It turns out that this code works because "cmdptr" is unsigned and KDB_CMD_HISTORY_COUNT is a nice power of 2. Let's make this a little less sketchy. This patch should be a no-op. Signed-off-by: Douglas Anderson <[email protected]> Link: https://lore.kernel.org/r/20200507161125.1.I2cce9ac66e141230c3644b8174b6c15d4e769232@changeid Reviewed-by: Sumit Garg <[email protected]> Signed-off-by: Daniel Thompson <[email protected]>
1 parent 195867f commit 1b31003

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

kernel/debug/kdb/kdb_main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,8 @@ static int handle_ctrl_cmd(char *cmd)
11081108
switch (*cmd) {
11091109
case CTRL_P:
11101110
if (cmdptr != cmd_tail)
1111-
cmdptr = (cmdptr-1) % KDB_CMD_HISTORY_COUNT;
1111+
cmdptr = (cmdptr + KDB_CMD_HISTORY_COUNT - 1) %
1112+
KDB_CMD_HISTORY_COUNT;
11121113
strscpy(cmd_cur, cmd_hist[cmdptr], CMD_BUFLEN);
11131114
return 1;
11141115
case CTRL_N:

0 commit comments

Comments
 (0)