From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39501) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wu3Ml-0001jN-Af for qemu-devel@nongnu.org; Mon, 09 Jun 2014 13:28:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wu3Mf-000154-VP for qemu-devel@nongnu.org; Mon, 09 Jun 2014 13:28:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:5794) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wu3Mf-00014y-NF for qemu-devel@nongnu.org; Mon, 09 Jun 2014 13:28:09 -0400 From: Igor Mammedov Date: Mon, 9 Jun 2014 19:28:01 +0200 Message-Id: <1402334881-19310-3-git-send-email-imammedo@redhat.com> In-Reply-To: <1402334881-19310-1-git-send-email-imammedo@redhat.com> References: <1402334881-19310-1-git-send-email-imammedo@redhat.com> Subject: [Qemu-devel] [PATCH 2/2] pc-dimm: fix large address sorting during auto-allocation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: vasilis.liaskovitis@profitbricks.com, andrey@xdel.ru, mst@redhat.com GCompareFunc(a, b) used by g_slist_insert_sorted() return 'gint', however it might be too small to fit difference between 2 addresses. So use 128bit calculate difference and normalize result to -1/0/1 return values. Reported-By: Andrey Korolyov Signed-off-by: Igor Mammedov --- hw/mem/pc-dimm.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 9f091c6..8c26568 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -73,8 +73,14 @@ static gint pc_dimm_addr_sort(gconstpointer a, gconstpointer b) { PCDIMMDevice *x = PC_DIMM(a); PCDIMMDevice *y = PC_DIMM(b); + Int128 diff = int128_sub(int128_make64(x->addr), int128_make64(y->addr)); - return x->addr - y->addr; + if (int128_lt(diff, int128_zero())) { + return -1; + } else if (int128_gt(diff, int128_zero())) { + return 1; + } + return 0; } static int pc_dimm_built_list(Object *obj, void *opaque) -- 1.9.3