xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Wei Liu <wei.liu2@citrix.com>
To: Xen-devel <xen-devel@lists.xenproject.org>
Cc: George Dunlap <george.dunlap@eu.citrix.com>,
	Ian Jackson <ian.jackson@eu.citrix.com>,
	Wei Liu <wei.liu2@citrix.com>,
	Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: [PATCH] xentrace: simplify map_page function in xenctx
Date: Thu, 3 Mar 2016 13:10:07 +0000	[thread overview]
Message-ID: <1457010607-8223-1-git-send-email-wei.liu2@citrix.com> (raw)

There were several problems:

1. Variable mapped was set to NULL so the following two "if"s were
   useless.
2. Variable previous_mfn was set but never used.

Simplify the function by removing two "if"s and previous_mfn.  Check if
mfn == 0 instead. Finally remove the now unused out label.

Wrapped long lines while I was there.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
Compile test only.

Cc: George Dunlap <george.dunlap@eu.citrix.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
---
 tools/xentrace/xenctx.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/tools/xentrace/xenctx.c b/tools/xentrace/xenctx.c
index e647179..ee6f800 100644
--- a/tools/xentrace/xenctx.c
+++ b/tools/xentrace/xenctx.c
@@ -686,28 +686,27 @@ static void print_ctx(vcpu_guest_context_any_t *ctx_any)
 #ifndef NO_TRANSLATION
 static void *map_page(vcpu_guest_context_any_t *ctx, int vcpu, guest_word_t virt)
 {
-    static unsigned long previous_mfn = 0;
     static void *mapped = NULL;
-
-    unsigned long mfn = xc_translate_foreign_address(xenctx.xc_handle, xenctx.domid, vcpu, virt);
+    unsigned long mfn;
     unsigned long offset = virt & ~XC_PAGE_MASK;
 
-    if (mapped && mfn == previous_mfn)
-        goto out;
-
-    if (mapped)
-        munmap(mapped, XC_PAGE_SIZE);
 
-    previous_mfn = mfn;
+    mfn = xc_translate_foreign_address(xenctx.xc_handle, xenctx.domid,
+                                       vcpu, virt);
+    if (mfn == 0) {
+        fprintf(stderr, "\nfailed to translate "FMT_32B_WORD" into MFN.\n",
+                virt);
+        return NULL;
+    }
 
-    mapped = xc_map_foreign_range(xenctx.xc_handle, xenctx.domid, XC_PAGE_SIZE, PROT_READ, mfn);
+    mapped = xc_map_foreign_range(xenctx.xc_handle, xenctx.domid,
+                                  XC_PAGE_SIZE, PROT_READ, mfn);
 
     if (mapped == NULL) {
         fprintf(stderr, "\nfailed to map page for "FMT_32B_WORD".\n", virt);
         return NULL;
     }
 
- out:
     return (void *)(mapped + offset);
 }
 
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

             reply	other threads:[~2016-03-03 13:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-03 13:10 Wei Liu [this message]
2016-03-17 11:48 ` George Dunlap
2016-03-17 11:54   ` Wei Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1457010607-8223-1-git-send-email-wei.liu2@citrix.com \
    --to=wei.liu2@citrix.com \
    --cc=george.dunlap@eu.citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    --subject='Re: [PATCH] xentrace: simplify map_page function in xenctx' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).