* [PATCH] kdb: Cleanup math with KDB_CMD_HISTORY_COUNT
@ 2020-05-07 23:11 Douglas Anderson
2020-05-08 12:02 ` Sumit Garg
2020-05-20 16:08 ` Daniel Thompson
0 siblings, 2 replies; 3+ messages in thread
From: Douglas Anderson @ 2020-05-07 23:11 UTC (permalink / raw)
To: Jason Wessel, Daniel Thompson
Cc: sumit.garg, Douglas Anderson, Chuhong Yuan, Dan Carpenter,
Masahiro Yamada, kgdb-bugreport, linux-kernel
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 <dianders@chromium.org>
---
kernel/debug/kdb/kdb_main.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
index 515379cbf209..6865a0f58d38 100644
--- a/kernel/debug/kdb/kdb_main.c
+++ b/kernel/debug/kdb/kdb_main.c
@@ -1108,7 +1108,8 @@ static int handle_ctrl_cmd(char *cmd)
switch (*cmd) {
case CTRL_P:
if (cmdptr != cmd_tail)
- cmdptr = (cmdptr-1) % KDB_CMD_HISTORY_COUNT;
+ cmdptr = (cmdptr + KDB_CMD_HISTORY_COUNT - 1) %
+ KDB_CMD_HISTORY_COUNT;
strscpy(cmd_cur, cmd_hist[cmdptr], CMD_BUFLEN);
return 1;
case CTRL_N:
--
2.26.2.645.ge9eca65c58-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] kdb: Cleanup math with KDB_CMD_HISTORY_COUNT
2020-05-07 23:11 [PATCH] kdb: Cleanup math with KDB_CMD_HISTORY_COUNT Douglas Anderson
@ 2020-05-08 12:02 ` Sumit Garg
2020-05-20 16:08 ` Daniel Thompson
1 sibling, 0 replies; 3+ messages in thread
From: Sumit Garg @ 2020-05-08 12:02 UTC (permalink / raw)
To: Douglas Anderson
Cc: Jason Wessel, Daniel Thompson, Chuhong Yuan, Dan Carpenter,
Masahiro Yamada, kgdb-bugreport, Linux Kernel Mailing List
On Fri, 8 May 2020 at 04:42, Douglas Anderson <dianders@chromium.org> wrote:
>
> 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 <dianders@chromium.org>
> ---
>
Reviewed-by: Sumit Garg <sumit.garg@linaro.org>
> kernel/debug/kdb/kdb_main.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
> index 515379cbf209..6865a0f58d38 100644
> --- a/kernel/debug/kdb/kdb_main.c
> +++ b/kernel/debug/kdb/kdb_main.c
> @@ -1108,7 +1108,8 @@ static int handle_ctrl_cmd(char *cmd)
> switch (*cmd) {
> case CTRL_P:
> if (cmdptr != cmd_tail)
> - cmdptr = (cmdptr-1) % KDB_CMD_HISTORY_COUNT;
> + cmdptr = (cmdptr + KDB_CMD_HISTORY_COUNT - 1) %
> + KDB_CMD_HISTORY_COUNT;
> strscpy(cmd_cur, cmd_hist[cmdptr], CMD_BUFLEN);
> return 1;
> case CTRL_N:
> --
> 2.26.2.645.ge9eca65c58-goog
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] kdb: Cleanup math with KDB_CMD_HISTORY_COUNT
2020-05-07 23:11 [PATCH] kdb: Cleanup math with KDB_CMD_HISTORY_COUNT Douglas Anderson
2020-05-08 12:02 ` Sumit Garg
@ 2020-05-20 16:08 ` Daniel Thompson
1 sibling, 0 replies; 3+ messages in thread
From: Daniel Thompson @ 2020-05-20 16:08 UTC (permalink / raw)
To: Douglas Anderson
Cc: Jason Wessel, sumit.garg, Chuhong Yuan, Dan Carpenter,
Masahiro Yamada, kgdb-bugreport, linux-kernel
On Thu, May 07, 2020 at 04:11:46PM -0700, Douglas Anderson wrote:
> 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 <dianders@chromium.org>
Applied, thanks!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-05-20 16:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-07 23:11 [PATCH] kdb: Cleanup math with KDB_CMD_HISTORY_COUNT Douglas Anderson
2020-05-08 12:02 ` Sumit Garg
2020-05-20 16:08 ` Daniel Thompson
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.