mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Liam R. Howlett (Google)" <liam@infradead.org>
To: Fei Li <fei1.li@intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-kernel@vger.kernel.org,
	"Liam R. Howlett (Google)" <liam@infradead.org>
Subject: [PATCH] samples/acrn: check posix_memalign() for any error
Date: Mon, 19 Oct 2026 23:26:52 -0400	[thread overview]
Message-ID: <20261020032652.1920998-1-liam@infradead.org> (raw)

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@infradead.org>
---
 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


                 reply	other threads:[~2026-10-20  3:27 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261020032652.1920998-1-liam@infradead.org \
    --to=liam@infradead.org \
    --cc=fei1.li@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®