All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sumit Garg <sumit.garg@linaro.org>
To: Douglas Anderson <dianders@chromium.org>
Cc: Jason Wessel <jason.wessel@windriver.com>,
	Daniel Thompson <daniel.thompson@linaro.org>,
	Chuhong Yuan <hslester96@gmail.com>,
	Dan Carpenter <dan.carpenter@oracle.com>,
	Masahiro Yamada <yamada.masahiro@socionext.com>,
	kgdb-bugreport@lists.sourceforge.net,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] kdb: Cleanup math with KDB_CMD_HISTORY_COUNT
Date: Fri, 8 May 2020 17:32:24 +0530	[thread overview]
Message-ID: <CAFA6WYNbrhiagmqLGOGq+-WRdmbA0Y8FP9PYYsOoerqHeQcmoQ@mail.gmail.com> (raw)
In-Reply-To: <20200507161125.1.I2cce9ac66e141230c3644b8174b6c15d4e769232@changeid>

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
>

  reply	other threads:[~2020-05-08 12:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-07 23:11 [PATCH] kdb: Cleanup math with KDB_CMD_HISTORY_COUNT Douglas Anderson
2020-05-08 12:02 ` Sumit Garg [this message]
2020-05-20 16:08 ` Daniel Thompson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAFA6WYNbrhiagmqLGOGq+-WRdmbA0Y8FP9PYYsOoerqHeQcmoQ@mail.gmail.com \
    --to=sumit.garg@linaro.org \
    --cc=dan.carpenter@oracle.com \
    --cc=daniel.thompson@linaro.org \
    --cc=dianders@chromium.org \
    --cc=hslester96@gmail.com \
    --cc=jason.wessel@windriver.com \
    --cc=kgdb-bugreport@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=yamada.masahiro@socionext.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.