From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0488BC43458 for ; Wed, 1 Jul 2026 13:52:48 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.1349989.1607573 (Exim 4.92) (envelope-from ) id 1wevMi-0007I8-4H; Wed, 01 Jul 2026 13:52:36 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1349989.1607573; Wed, 01 Jul 2026 13:52:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wevMi-0007I1-0D; Wed, 01 Jul 2026 13:52:36 +0000 Received: by outflank-mailman (input) for mailman id 1349989; Wed, 01 Jul 2026 13:52:34 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wevMg-0007Hs-SP for xen-devel@lists.xenproject.org; Wed, 01 Jul 2026 13:52:34 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wevMg-00B58B-5Z for xen-devel@lists.xenproject.org; Wed, 01 Jul 2026 15:52:34 +0200 Received: from [10.42.69.8] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a451b9f-2eae-0a2a0a5409dd-0a2a45088f56-6 for ; Wed, 01 Jul 2026 15:52:34 +0200 Received: from [209.85.221.46] (helo=mail-wr1-f46.google.com) by tlsNG-c1860d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6a451ba1-edec-0a2a45080019-d155dd2ef026-3 for ; Wed, 01 Jul 2026 15:52:33 +0200 Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-4763b0c1dcdso798018f8f.2 for ; Wed, 01 Jul 2026 06:52:33 -0700 (PDT) Received: from localhost.localdomain (host-78-146-248-75.as13285.net. [78.146.248.75]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4756636ce7esm18672970f8f.23.2026.07.01.06.52.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jul 2026 06:52:32 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=google header.d=citrix.com header.i="@citrix.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1782913953; x=1783518753; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=xl3e4suKSPl7CWk+sb8bPatN3ANB8eUSjC46flYftEE=; b=DknmK2MOxsjafHEumZJq0pswxDGKZal8eKAmaAM6Kh+0PPVO8c+VKgALVXbT3Kjx+3 UkoO5E+XfDUsdt4jCTEAK/nA3YyRYzWHcRPP9WYWXc9rWRzEB8ijM5+FXR9WIzjxG5wU Qn4mWx2Um0+nx0w1uFYdm7upvJtPrftqqrSIY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782913953; x=1783518753; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=xl3e4suKSPl7CWk+sb8bPatN3ANB8eUSjC46flYftE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a97d-477b5677843mr793528f8f.40.1782913952815; Wed, 01 Jul 2026 06:52:32 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Anthony PERARD , Frediano Ziglio Subject: [PATCH v6 1.9/16] libs/guest: Allocate rec_pfns earlier in write_batch() Date: Wed, 1 Jul 2026 14:52:30 +0100 Message-Id: <20260701135230.794306-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260619130501.272832-3-frediano.ziglio@citrix.com> References: <20260619130501.272832-3-frediano.ziglio@citrix.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-purgate-ID: tlsNG-c1860d/1782913954-A2D3B3FC-A57FC2C9/0/0 X-purgate-type: clean X-purgate-size: 2133 For reasons which escape me, rec_pfns are allocated separately to the rest of the batch allocations. Allocate them all together. This will allow for future simplifications to be performed in an incremental mannor. No functional change. Signed-off-by: Andrew Cooper --- CC: Anthony PERARD CC: Frediano Ziglio --- tools/libs/guest/xg_sr_save.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index fdbceab52e46..69fe991a8113 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_save.c @@ -116,8 +116,10 @@ static int write_batch(struct xc_sr_context *ctx) local_pages = calloc(nr_pfns, sizeof(*local_pages)); /* iovec[] for writev(). */ iov = malloc((nr_pfns + 4) * sizeof(*iov)); + /* page_data record PFNs list */ + rec_pfns = malloc(nr_pfns * sizeof(*rec_pfns)); - if ( !mfns || !types || !errors || !guest_data || !local_pages || !iov ) + if ( !mfns || !types || !errors || !guest_data || !local_pages || !iov || !rec_pfns ) { ERROR("Unable to allocate arrays for a batch of %u pages", nr_pfns); @@ -208,14 +210,6 @@ static int write_batch(struct xc_sr_context *ctx) } } - rec_pfns = malloc(nr_pfns * sizeof(*rec_pfns)); - if ( !rec_pfns ) - { - ERROR("Unable to allocate %zu bytes of memory for page data pfn list", - nr_pfns * sizeof(*rec_pfns)); - goto err; - } - hdr.count = nr_pfns; rec.length = sizeof(hdr); @@ -264,11 +258,11 @@ static int write_batch(struct xc_sr_context *ctx) rc = ctx->save.nr_batch_pfns = 0; err: - free(rec_pfns); if ( guest_mapping ) xenforeignmemory_unmap(xch->fmem, guest_mapping, nr_pages_mapped); for ( i = 0; local_pages && i < nr_pfns; ++i ) free(local_pages[i]); + free(rec_pfns); free(iov); free(local_pages); free(guest_data); -- 2.39.5