diff mbox series

[v3,15/21] xen/tpmfront: use xenbus_setup_ring() and xenbus_teardown_ring()

Message ID 20220505081640.17425-16-jgross@suse.com (mailing list archive)
State New
Headers show
Series xen: simplify frontend side ring setup | expand

Commit Message

Juergen Gross May 5, 2022, 8:16 a.m. UTC
Simplify tpmfront's ring creation and removal via xenbus_setup_ring()
and xenbus_teardown_ring().

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 drivers/char/tpm/xen-tpmfront.c | 18 +++---------------
 1 file changed, 3 insertions(+), 15 deletions(-)

Comments

Jarkko Sakkinen May 6, 2022, 10:32 p.m. UTC | #1
On Thu, May 05, 2022 at 10:16:34AM +0200, Juergen Gross wrote:
> Simplify tpmfront's ring creation and removal via xenbus_setup_ring()
> and xenbus_teardown_ring().
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Please add to the commit message why these provide an equivalent
functionality.

BR, Jarkko
Juergen Gross May 18, 2022, 9:41 a.m. UTC | #2
On 07.05.22 00:32, Jarkko Sakkinen wrote:
> On Thu, May 05, 2022 at 10:16:34AM +0200, Juergen Gross wrote:
>> Simplify tpmfront's ring creation and removal via xenbus_setup_ring()
>> and xenbus_teardown_ring().
>>
>> Signed-off-by: Juergen Gross <jgross@suse.com>
> 
> Please add to the commit message why these provide an equivalent
> functionality.

Would you be fine with:

   Simplify tpmfront's ring creation and removal via xenbus_setup_ring()
   and xenbus_teardown_ring(), which are provided exactly for the use
   pattern as seen in this driver.


Juergen
Jarkko Sakkinen May 18, 2022, 2:57 p.m. UTC | #3
On Wed, May 18, 2022 at 11:41:51AM +0200, Juergen Gross wrote:
> On 07.05.22 00:32, Jarkko Sakkinen wrote:
> > On Thu, May 05, 2022 at 10:16:34AM +0200, Juergen Gross wrote:
> > > Simplify tpmfront's ring creation and removal via xenbus_setup_ring()
> > > and xenbus_teardown_ring().
> > > 
> > > Signed-off-by: Juergen Gross <jgross@suse.com>
> > 
> > Please add to the commit message why these provide an equivalent
> > functionality.
> 
> Would you be fine with:
> 
>   Simplify tpmfront's ring creation and removal via xenbus_setup_ring()
>   and xenbus_teardown_ring(), which are provided exactly for the use
>   pattern as seen in this driver.
> 
> 
> Juergen

Looks fine to me!

BR, Jarkko
diff mbox series

Patch

diff --git a/drivers/char/tpm/xen-tpmfront.c b/drivers/char/tpm/xen-tpmfront.c
index 69df04ae2401..379291826261 100644
--- a/drivers/char/tpm/xen-tpmfront.c
+++ b/drivers/char/tpm/xen-tpmfront.c
@@ -253,20 +253,12 @@  static int setup_ring(struct xenbus_device *dev, struct tpm_private *priv)
 	struct xenbus_transaction xbt;
 	const char *message = NULL;
 	int rv;
-	grant_ref_t gref;
 
-	priv->shr = (void *)__get_free_page(GFP_KERNEL|__GFP_ZERO);
-	if (!priv->shr) {
-		xenbus_dev_fatal(dev, -ENOMEM, "allocating shared ring");
-		return -ENOMEM;
-	}
-
-	rv = xenbus_grant_ring(dev, priv->shr, 1, &gref);
+	rv = xenbus_setup_ring(dev, GFP_KERNEL, (void **)&priv->shr, 1,
+			       &priv->ring_ref);
 	if (rv < 0)
 		return rv;
 
-	priv->ring_ref = gref;
-
 	rv = xenbus_alloc_evtchn(dev, &priv->evtchn);
 	if (rv)
 		return rv;
@@ -331,11 +323,7 @@  static void ring_free(struct tpm_private *priv)
 	if (!priv)
 		return;
 
-	if (priv->ring_ref)
-		gnttab_end_foreign_access(priv->ring_ref,
-				(unsigned long)priv->shr);
-	else
-		free_page((unsigned long)priv->shr);
+	xenbus_teardown_ring((void **)&priv->shr, 1, &priv->ring_ref);
 
 	if (priv->irq)
 		unbind_from_irqhandler(priv->irq, priv);