From: Paolo Bonzini Subject: [PATCH kvm-unit-tests 04/10] alloc_page: fix off-by-one Date: Mon, 23 Oct 2017 15:53:28 +0200 Message-ID: <20171023135334.18864-5-pbonzini@redhat.com> References: <20171023135334.18864-1-pbonzini@redhat.com> Cc: drjones@redhat.com, david@redhat.com To: kvm@vger.kernel.org Return-path: Received: from mail-wr0-f194.google.com ([209.85.128.194]:46285 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932253AbdJWNxn (ORCPT ); Mon, 23 Oct 2017 09:53:43 -0400 Received: by mail-wr0-f194.google.com with SMTP id l1so17483512wrc.3 for ; Mon, 23 Oct 2017 06:53:43 -0700 (PDT) In-Reply-To: <20171023135334.18864-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 b02dfce..de6fd6f 100644 --- a/lib/alloc_page.c +++ b/lib/alloc_page.c @@ -19,7 +19,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