From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A77B4D7D59; Wed, 30 Sep 2026 15:39:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790782743; cv=none; b=WpQBIztzLr6Y3+9n6UzzQVNvK52U2n13b2/vk1J5Gji4Q0bssUhYBgGt4Us4RRmCwX/7JcJ6N9uVFaKbTEVInIuDDAIxcM/rk7mqX3PTQjaAA5RbpSAGbL9Zja2UzZNVj/cTOlXo8NVPPe2sobkE1HVM9y8+10mRkCnfnqHV9Yk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790782743; c=relaxed/simple; bh=2642IeGDeATCnw+cNb5UiLT3ExLRq2RVw3bPg63x/QU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=siw2ojb6GAegUgx1JCXUZMb+CSlQx7W3/6s/jdPytTd7h04DZFspY+h3zoDtWvo2JSZ7yUQauch8CMXg1HCyMMBgtsSfv6pP53CmcqT5FpkIW+5+lRyPkb3MKP40duuTVabGG7NrUl1ykH403vVfNW3JPLuu9j1lQq8eVd1PA1I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=p+O0GxyY; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="p+O0GxyY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 112511F000FF; Wed, 30 Sep 2026 15:38:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1790782740; bh=4LlSit2gkqZ/wHJgBUf1kmhQ11UE/7IU37VQShEIMmc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=p+O0GxyYHCxKrkGcypLH6fbkZePL/wPYmKUP41wav3eIExEJD4GKeSbVGFO/xdVhf VajHa+oUtBezpXOAVelUMrXfnuCV8Zen6xSR8t3UAp89crPQTyyEpz3uegBUJICIHM zO7LnyzurDrLkCGA34icmf0xMlzlabzbSoiXz9NY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yousef Alhouseen , Stefano Stabellini , Juergen Gross , Sasha Levin Subject: [PATCH 5.10 151/595] xen/front-pgdir-shbuf: free grant reference head on errors Date: Wed, 30 Sep 2026 17:20:44 +0200 Message-ID: <20260930152350.982430101@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930152347.700140858@linuxfoundation.org> References: <20260930152347.700140858@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yousef Alhouseen [ Upstream commit 678d59219ce0ae883f04c96936222c6168ef1164 ] grant_references() allocates a private grant-reference head before claiming references for the page directory and, for guest-owned buffers, the data pages. The success path frees the remaining head, but claim failures and grant_refs_for_buffer() errors return immediately. Unwind through a common exit path so the private grant-reference head is released even when granting fails part-way through setup. The caller still tears down any references already stored in buf->grefs. Signed-off-by: Yousef Alhouseen Reviewed-by: Stefano Stabellini Signed-off-by: Juergen Gross Message-ID: <20260629160517.29340-1-alhouseenyousef@gmail.com> Signed-off-by: Sasha Levin --- drivers/xen/xen-front-pgdir-shbuf.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/xen/xen-front-pgdir-shbuf.c b/drivers/xen/xen-front-pgdir-shbuf.c index 48a658dc7ccfc..4d67f91da5b30 100644 --- a/drivers/xen/xen-front-pgdir-shbuf.c +++ b/drivers/xen/xen-front-pgdir-shbuf.c @@ -449,8 +449,10 @@ static int grant_references(struct xen_front_pgdir_shbuf *buf) unsigned long frame; cur_ref = gnttab_claim_grant_reference(&priv_gref_head); - if (cur_ref < 0) - return cur_ref; + if (cur_ref < 0) { + ret = cur_ref; + goto out_free_refs; + } frame = xen_page_to_gfn(virt_to_page(buf->directory + PAGE_SIZE * i)); @@ -461,11 +463,13 @@ static int grant_references(struct xen_front_pgdir_shbuf *buf) if (buf->ops->grant_refs_for_buffer) { ret = buf->ops->grant_refs_for_buffer(buf, &priv_gref_head, j); if (ret) - return ret; + goto out_free_refs; } + ret = 0; +out_free_refs: gnttab_free_grant_references(priv_gref_head); - return 0; + return ret; } /** -- 2.53.0