From: Paolo Bonzini Subject: [PATCH kvm-unit-tests 04/18] alloc_page: fix off-by-one Date: Tue, 24 Oct 2017 17:21:31 +0200 Message-ID: <20171024152145.28456-5-pbonzini@redhat.com> References: <20171024152145.28456-1-pbonzini@redhat.com> Cc: drjones@redhat.com, david@redhat.com To: kvm@vger.kernel.org Return-path: Received: from mail-wm0-f67.google.com ([74.125.82.67]:56227 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932084AbdJXPVy (ORCPT ); Tue, 24 Oct 2017 11:21:54 -0400 Received: by mail-wm0-f67.google.com with SMTP id u138so17092892wmu.4 for ; Tue, 24 Oct 2017 08:21:54 -0700 (PDT) In-Reply-To: <20171024152145.28456-1-pbonzini@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: It is okay to free up to the very last page of virtual address space, in which case mem+size is zero. Signed-off-by: Paolo Bonzini --- lib/alloc_page.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/alloc_page.c b/lib/alloc_page.c index 15f6721..52992ad 100644 --- a/lib/alloc_page.c +++ b/lib/alloc_page.c @@ -22,7 +22,8 @@ void free_pages(void *mem, unsigned long size) assert_msg(size % PAGE_SIZE == 0, "size not page aligned: %#lx", size); - assert_msg(size == 0 || mem + size > mem, + assert_msg(size == 0 || (uintptr_t)mem == -size || + (uintptr_t)mem + size > (uintptr_t)mem, "mem + size overflow: %p + %#lx", mem, size); if (size == 0) { -- 2.14.2