Re: [PATCH v2 6/7] kdb: Replace double memcpy() with memmove() in kdb_read()
From: Doug Anderson
Date: Mon Apr 22 2024 - 19:53:25 EST
Hi,
On Mon, Apr 22, 2024 at 9:38 AM Daniel Thompson
<daniel.thompson@xxxxxxxxxx> wrote:
>
> At several points in kdb_read() there are variants of the following
> code pattern (with offsets slightly altered):
>
> memcpy(tmpbuffer, cp, lastchar - cp);
> memcpy(cp-1, tmpbuffer, lastchar - cp);
> *(--lastchar) = '\0';
>
> There is no need to use tmpbuffer here, since we can use memmove() instead
> so refactor in the obvious way. Additionally the strings that are being
> copied are already properly terminated so let's also change the code so
> that the library calls also move the terminator.
>
> Changing how the terminators are managed has no functional effect for now
> but might allow us to retire lastchar at a later point. lastchar, although
> stored as a pointer, is functionally equivalent to caching strlen(buffer).
>
> Signed-off-by: Daniel Thompson <daniel.thompson@xxxxxxxxxx>
> ---
> kernel/debug/kdb/kdb_io.c | 19 +++++++------------
> 1 file changed, 7 insertions(+), 12 deletions(-)
Reviewed-by: Douglas Anderson <dianders@xxxxxxxxxxxx>