From: Daniel Thompson <daniel.thompson@linaro.org>
To: Doug Anderson <dianders@chromium.org>
Cc: Jason Wessel <jason.wessel@windriver.com>,
kgdb-bugreport@lists.sourceforge.net,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH v2 2/7] kdb: Use format-strings rather than '\0' injection in kdb_read()
Date: Tue, 23 Apr 2024 11:37:14 +0100 [thread overview]
Message-ID: <20240423103714.GB1567803@aspen.lan> (raw)
In-Reply-To: <CAD=FV=VXFHqOatn3cvwvYCey53+zuzB7ie4gYdvDVbfGL=Qm1Q@mail.gmail.com>
On Mon, Apr 22, 2024 at 04:52:04PM -0700, Doug Anderson wrote:
> Hi,
>
> On Mon, Apr 22, 2024 at 9:37 AM Daniel Thompson
> <daniel.thompson@linaro.org> wrote:
> >
> > Currently when kdb_read() needs to reposition the cursor it uses copy and
> > paste code that works by injecting an '\0' at the cursor position before
> > delivering a carriage-return and reprinting the line (which stops at the
> > '\0').
> >
> > Tidy up the code by hoisting the copy and paste code into an appropriately
> > named function. Additionally let's replace the '\0' injection with a
> > proper field width parameter so that the string will be abridged during
> > formatting instead.
> >
> > Cc: stable@vger.kernel.org # Not a bug fix but it is needed for later bug fixes
> > Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
> > ---
> > kernel/debug/kdb/kdb_io.c | 34 ++++++++++++++--------------------
> > 1 file changed, 14 insertions(+), 20 deletions(-)
>
> Looks like a nice fix, but I think this'll create a compile warning on
> some compilers. The variable "tmp" is no longer used, I think.
>
> Once the "tmp" variable is deleted, feel free to add my Reviewed-by.
Good spot. I'll fix that.
> NOTE: patch #7 in your series re-adds a user of "tmp", but since this
> one is "Cc: stable" you will need to delete it here and then re-add it
> in patch #7.
>
>
> > diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c
> > index 06dfbccb10336..a42607e4d1aba 100644
> > --- a/kernel/debug/kdb/kdb_io.c
> > +++ b/kernel/debug/kdb/kdb_io.c
> > @@ -184,6 +184,13 @@ char kdb_getchar(void)
> > unreachable();
> > }
> >
> > +static void kdb_position_cursor(char *prompt, char *buffer, char *cp)
> > +{
> > + kdb_printf("\r%s", kdb_prompt_str);
> > + if (cp > buffer)
> > + kdb_printf("%.*s", (int)(cp - buffer), buffer);
>
> nit: personally, I'd take the "if" statement out. I'm nearly certain
> that kdb_printf() can handle zero-length for the width argument and
> "buffer" can never be _after_ cp (so you can't get negative).
The kernel will correctly format zero-width fields... but kdb_printf()
will also inject the empty string into the log if running with
LOGGING=1. It is true the dmesg output with LOGGING=1 is pretty nasty
when doing line editing but I still didn't want to make it worse!
Oh... and we can't combine into one call to kdb_printf() since that
renders into a fixed length static buffer and we could get unwanted
truncation. I might just add a comment about that.
Daniel.
next prev parent reply other threads:[~2024-04-23 10:37 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-22 16:35 [PATCH v2 0/7] kdb: Refactor and fix bugs in kdb_read() Daniel Thompson
2024-04-22 16:35 ` [PATCH v2 1/7] kdb: Fix buffer overflow during tab-complete Daniel Thompson
2024-04-22 21:39 ` Justin Stitt
2024-04-22 23:51 ` Doug Anderson
2024-04-23 10:17 ` Daniel Thompson
2024-04-22 16:35 ` [PATCH v2 2/7] kdb: Use format-strings rather than '\0' injection in kdb_read() Daniel Thompson
2024-04-22 23:52 ` Doug Anderson
2024-04-23 10:37 ` Daniel Thompson [this message]
2024-04-22 16:35 ` [PATCH v2 3/7] kdb: Fix console handling when editing and tab-completing commands Daniel Thompson
2024-04-22 23:52 ` Doug Anderson
2024-04-22 16:35 ` [PATCH v2 4/7] kdb: Merge identical case statements in kdb_read() Daniel Thompson
2024-04-22 23:52 ` Doug Anderson
2024-04-22 16:35 ` [PATCH v2 5/7] kdb: Use format-specifiers rather than memset() for padding " Daniel Thompson
2024-04-22 23:52 ` Doug Anderson
2024-04-22 22:49 ` [PATCH v2 0/7] kdb: Refactor and fix bugs " Justin Stitt
2024-04-23 11:19 ` 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=20240423103714.GB1567803@aspen.lan \
--to=daniel.thompson@linaro.org \
--cc=dianders@chromium.org \
--cc=jason.wessel@windriver.com \
--cc=kgdb-bugreport@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox