Skip to contentSkip to conversation

samples/acrn: check posix_memalign() for any error

PATCH In review Liam R. Howlett (Google) 2 participants 2 messages Oct 20 – Oct 21

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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()")
---
 samples/acrn/vm-sample.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
samples/acrn/vm-sample.c +1 -1
index c61e0f91456e0..0f98d2d75ae7c 100644
@@ -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;
 	}
Signature · 1 line
2.47.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 12 lines

-----Original Message-----
From: Liam R. Howlett (Google) <[email protected]>
Sent: Tuesday, October 20, 2026 11:27 AM
To: Li, Fei1 <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>; linux- [email protected]; Liam R. Howlett (Google) <[email protected]>
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.

Quoted 5 lines

Test for a non-zero return.

Fixes 32118bdc9471 ("virt: acrn: Replace obsolete memalign() with

posix_memalign()")

Thanks.

Quoted 19 lines
---
 samples/acrn/vm-sample.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
samples/acrn/vm-sample.c index renamed from samples/acrn/vm-sample.c +0 -0

c61e0f91456e0..0f98d2d75ae7c 100644

samples/acrn/vm-sample.c +1 -2
@@ -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