* [PATCH] xen/front-pgdir-shbuf: free grant reference head on errors
@ 2026-06-29 16:05 Yousef Alhouseen
2026-06-30 22:27 ` Stefano Stabellini
0 siblings, 1 reply; 2+ messages in thread
From: Yousef Alhouseen @ 2026-06-29 16:05 UTC (permalink / raw)
To: Juergen Gross
Cc: Stefano Stabellini, Oleksandr Tyshchenko, xen-devel,
linux-kernel, Yousef Alhouseen
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 <alhouseenyousef@gmail.com>
---
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 9c7d8af6e6a1..428187edf85d 100644
--- a/drivers/xen/xen-front-pgdir-shbuf.c
+++ b/drivers/xen/xen-front-pgdir-shbuf.c
@@ -445,8 +445,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));
@@ -457,11 +459,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.54.0
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] xen/front-pgdir-shbuf: free grant reference head on errors
2026-06-29 16:05 [PATCH] xen/front-pgdir-shbuf: free grant reference head on errors Yousef Alhouseen
@ 2026-06-30 22:27 ` Stefano Stabellini
0 siblings, 0 replies; 2+ messages in thread
From: Stefano Stabellini @ 2026-06-30 22:27 UTC (permalink / raw)
To: Yousef Alhouseen
Cc: Juergen Gross, Stefano Stabellini, Oleksandr Tyshchenko,
xen-devel, linux-kernel
On Mon, 29 Jun 2026, Yousef Alhouseen wrote:
> 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 <alhouseenyousef@gmail.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
> ---
> 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 9c7d8af6e6a1..428187edf85d 100644
> --- a/drivers/xen/xen-front-pgdir-shbuf.c
> +++ b/drivers/xen/xen-front-pgdir-shbuf.c
> @@ -445,8 +445,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));
> @@ -457,11 +459,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.54.0
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-06-30 22:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-29 16:05 [PATCH] xen/front-pgdir-shbuf: free grant reference head on errors Yousef Alhouseen
2026-06-30 22:27 ` Stefano Stabellini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox