[PATCH 1/3] xen/lzo: Implement COPY{4,8} using memcpy()

Andrew Cooper posted 3 patches 6 months ago
[PATCH 1/3] xen/lzo: Implement COPY{4,8} using memcpy()
Posted by Andrew Cooper 6 months ago
This is simpler and easier for both humans and compilers to read.

It also addresses 6 instances of MISRA R5.3 violation (shadowing of the ptr_
local variable inside both {put,get}_unaligned()).

No change, not even in the compiled binary.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: George Dunlap <George.Dunlap@citrix.com>
CC: Jan Beulich <JBeulich@suse.com>
CC: Stefano Stabellini <sstabellini@kernel.org>
CC: Julien Grall <julien@xen.org>
CC: Roberto Bagnara <roberto.bagnara@bugseng.com>
CC: consulting@bugseng.com <consulting@bugseng.com>
CC: Oleksii Kurochko <oleksii.kurochko@gmail.com>
---
 xen/common/lzo.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/xen/common/lzo.c b/xen/common/lzo.c
index cc03f0f5547f..3454ce4a7e24 100644
--- a/xen/common/lzo.c
+++ b/xen/common/lzo.c
@@ -25,15 +25,8 @@
  */
 
 
-#define COPY4(dst, src)    \
-        put_unaligned(get_unaligned((const u32 *)(src)), (u32 *)(dst))
-#if defined(__x86_64__)
-#define COPY8(dst, src)    \
-        put_unaligned(get_unaligned((const u64 *)(src)), (u64 *)(dst))
-#else
-#define COPY8(dst, src)    \
-        COPY4(dst, src); COPY4((dst) + 4, (src) + 4)
-#endif
+#define COPY4(dst, src) memcpy(dst, src, 4)
+#define COPY8(dst, src) memcpy(dst, src, 8)
 
 #ifdef __MINIOS__
 # include <lib.h>
-- 
2.30.2
Re: [PATCH 1/3] xen/lzo: Implement COPY{4,8} using memcpy()
Posted by Stefano Stabellini 6 months ago
On Tue, 21 May 2024, Andrew Cooper wrote:
> This is simpler and easier for both humans and compilers to read.
> 
> It also addresses 6 instances of MISRA R5.3 violation (shadowing of the ptr_
> local variable inside both {put,get}_unaligned()).
> 
> No change, not even in the compiled binary.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>


> ---
> CC: George Dunlap <George.Dunlap@citrix.com>
> CC: Jan Beulich <JBeulich@suse.com>
> CC: Stefano Stabellini <sstabellini@kernel.org>
> CC: Julien Grall <julien@xen.org>
> CC: Roberto Bagnara <roberto.bagnara@bugseng.com>
> CC: consulting@bugseng.com <consulting@bugseng.com>
> CC: Oleksii Kurochko <oleksii.kurochko@gmail.com>
> ---
>  xen/common/lzo.c | 11 ++---------
>  1 file changed, 2 insertions(+), 9 deletions(-)
> 
> diff --git a/xen/common/lzo.c b/xen/common/lzo.c
> index cc03f0f5547f..3454ce4a7e24 100644
> --- a/xen/common/lzo.c
> +++ b/xen/common/lzo.c
> @@ -25,15 +25,8 @@
>   */
>  
>  
> -#define COPY4(dst, src)    \
> -        put_unaligned(get_unaligned((const u32 *)(src)), (u32 *)(dst))
> -#if defined(__x86_64__)
> -#define COPY8(dst, src)    \
> -        put_unaligned(get_unaligned((const u64 *)(src)), (u64 *)(dst))
> -#else
> -#define COPY8(dst, src)    \
> -        COPY4(dst, src); COPY4((dst) + 4, (src) + 4)
> -#endif
> +#define COPY4(dst, src) memcpy(dst, src, 4)
> +#define COPY8(dst, src) memcpy(dst, src, 8)
>  
>  #ifdef __MINIOS__
>  # include <lib.h>
> -- 
> 2.30.2
>