Re: [PATCH] cmd/mem.c: use memmove in do_mem_cp()

2023-12-26 Thread Simon Glass
Hi Rasmus,

On Tue, Dec 19, 2023 at 11:57 AM Rasmus Villemoes
 wrote:
>
> There's no 'mv' shell command for handling overlapping src and dst
> regions, and there's no point introducing one, when we can just make
> the existing 'cp' command DTRT in all cases. memmove() should at most
> be a few instructions more then memcpy() (to detect the appropriate
> direction to do the copy), which is of course completely in the noise
> with all the string processing that a shell command does.
>
> Signed-off-by: Rasmus Villemoes 
> ---
>  cmd/mem.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass 

Is there any size growth? I assume not.

>
> diff --git a/cmd/mem.c b/cmd/mem.c
> index 66c2d36a148..c696b92a274 100644
> --- a/cmd/mem.c
> +++ b/cmd/mem.c
> @@ -361,7 +361,7 @@ static int do_mem_cp(struct cmd_tbl *cmdtp, int flag, int 
> argc,
> }
>  #endif
>
> -   memcpy(dst, src, count * size);
> +   memmove(dst, src, count * size);
>
> unmap_sysmem(src);
> unmap_sysmem(dst);
> --
> 2.40.1.1.g1c60b9335d
>

Would you like to add to doc/usage/cmd/ and test/cmd as well?

Regards,
Simon


[PATCH] cmd/mem.c: use memmove in do_mem_cp()

2023-12-19 Thread Rasmus Villemoes
There's no 'mv' shell command for handling overlapping src and dst
regions, and there's no point introducing one, when we can just make
the existing 'cp' command DTRT in all cases. memmove() should at most
be a few instructions more then memcpy() (to detect the appropriate
direction to do the copy), which is of course completely in the noise
with all the string processing that a shell command does.

Signed-off-by: Rasmus Villemoes 
---
 cmd/mem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cmd/mem.c b/cmd/mem.c
index 66c2d36a148..c696b92a274 100644
--- a/cmd/mem.c
+++ b/cmd/mem.c
@@ -361,7 +361,7 @@ static int do_mem_cp(struct cmd_tbl *cmdtp, int flag, int 
argc,
}
 #endif
 
-   memcpy(dst, src, count * size);
+   memmove(dst, src, count * size);
 
unmap_sysmem(src);
unmap_sysmem(dst);
-- 
2.40.1.1.g1c60b9335d