RE: [PATCH] samples/acrn: check posix_memalign() for any error
From: Li, Fei1
Date: Wed Oct 21 2026 - 01:04:57 EST
> -----Original Message-----
> From: Liam R. Howlett (Google) <liam@xxxxxxxxxxxxx>
> Sent: Tuesday, October 20, 2026 11:27 AM
> To: Li, Fei1 <fei1.li@xxxxxxxxx>
> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>; linux-
> kernel@xxxxxxxxxxxxxxx; Liam R. Howlett (Google) <liam@xxxxxxxxxxxxx>
> Subject: [PATCH] samples/acrn: check posix_memalign() for any error
>
> posix_memalign() returns zero or a positive error number and does not set
> errno. The check for a negative return is incorrect and a failed allocation goes
> on to copy the guest code through guest_memory unset.
>
> Test for a non-zero return.
>
> Fixes: 32118bdc9471 ("virt: acrn: Replace obsolete memalign() with
> posix_memalign()")
> Signed-off-by: Liam R. Howlett (Google) <liam@xxxxxxxxxxxxx>
Reviewed-by: Fei Li <fei1.li@xxxxxxxxx>
Thanks.
> ---
> samples/acrn/vm-sample.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/samples/acrn/vm-sample.c b/samples/acrn/vm-sample.c index
> c61e0f91456e0..0f98d2d75ae7c 100644
> --- a/samples/acrn/vm-sample.c
> +++ b/samples/acrn/vm-sample.c
> @@ -54,7 +54,7 @@ int main(int argc, char **argv)
> argv = argv;
>
> ret = posix_memalign(&guest_memory, 4096, GUEST_MEMORY_SIZE);
> - if (ret < 0) {
> + if (ret) {
> printf("Not enough memory!\n");
> return -1;
> }
> --
> 2.47.3