[PATCH 4/7] tools/ocaml/evtchn: Misc cleanup

Andrew Cooper posted 7 patches 1 year, 9 months ago
[PATCH 4/7] tools/ocaml/evtchn: Misc cleanup
Posted by Andrew Cooper 1 year, 9 months ago
 * Remove local integers when all we're returning is Val_int() of another
   variable.  The CAMLlocal*() can't be optimised automatically, as it's
   registered with the GC.
 * Rename "virq_type" to "virq" and "_port" to "port".
 * In stub_eventchn_pending(), rename 'port' to 'rc', to be consistent with
   all other stubs that return xenevtchn_port_or_error_t.
 * In stub_eventchn_unmask(), check for rc == -1 to be consistent with all
   other stubs.

No practical change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Christian Lindig <christian.lindig@citrix.com>
CC: David Scott <dave@recoil.org>
CC: Edwin Török <edwin.torok@cloud.com>
CC: Rob Hoes <Rob.Hoes@citrix.com>
---
 tools/ocaml/libs/eventchn/xeneventchn_stubs.c | 45 +++++++++++----------------
 1 file changed, 18 insertions(+), 27 deletions(-)

diff --git a/tools/ocaml/libs/eventchn/xeneventchn_stubs.c b/tools/ocaml/libs/eventchn/xeneventchn_stubs.c
index d7881ca95f98..34dcfed30275 100644
--- a/tools/ocaml/libs/eventchn/xeneventchn_stubs.c
+++ b/tools/ocaml/libs/eventchn/xeneventchn_stubs.c
@@ -98,17 +98,15 @@ CAMLprim value stub_eventchn_fdopen(value fdval)
 CAMLprim value stub_eventchn_fd(value xce_val)
 {
 	CAMLparam1(xce_val);
-	CAMLlocal1(result);
 	xenevtchn_handle *xce = xce_of_val(xce_val);
 	int fd;
 
+	/* Don't drop the GC lock.  This is a simple read out of memory */
 	fd = xenevtchn_fd(xce);
 	if (fd == -1)
 		caml_failwith("evtchn fd failed");
 
-	result = Val_int(fd);
-
-	CAMLreturn(result);
+	CAMLreturn(Val_int(fd));
 }
 
 CAMLprim value stub_eventchn_notify(value xce_val, value port)
@@ -131,37 +129,34 @@ CAMLprim value stub_eventchn_bind_interdomain(value xce_val, value domid,
                                               value remote_port)
 {
 	CAMLparam3(xce_val, domid, remote_port);
-	CAMLlocal1(port);
 	xenevtchn_handle *xce = xce_of_val(xce_val);
 	xenevtchn_port_or_error_t rc;
 
 	caml_enter_blocking_section();
-	rc = xenevtchn_bind_interdomain(xce, Int_val(domid), Int_val(remote_port));
+	rc = xenevtchn_bind_interdomain(xce, Int_val(domid),
+					Int_val(remote_port));
 	caml_leave_blocking_section();
 
 	if (rc == -1)
 		caml_failwith("evtchn bind_interdomain failed");
-	port = Val_int(rc);
 
-	CAMLreturn(port);
+	CAMLreturn(Val_int(rc));
 }
 
-CAMLprim value stub_eventchn_bind_virq(value xce_val, value virq_type)
+CAMLprim value stub_eventchn_bind_virq(value xce_val, value virq)
 {
-	CAMLparam2(xce_val, virq_type);
-	CAMLlocal1(port);
+	CAMLparam2(xce_val, virq);
 	xenevtchn_handle *xce = xce_of_val(xce_val);
 	xenevtchn_port_or_error_t rc;
 
 	caml_enter_blocking_section();
-	rc = xenevtchn_bind_virq(xce, Int_val(virq_type));
+	rc = xenevtchn_bind_virq(xce, Int_val(virq));
 	caml_leave_blocking_section();
 
 	if (rc == -1)
 		caml_failwith("evtchn bind_virq failed");
-	port = Val_int(rc);
 
-	CAMLreturn(port);
+	CAMLreturn(Val_int(rc));
 }
 
 CAMLprim value stub_eventchn_unbind(value xce_val, value port)
@@ -183,35 +178,31 @@ CAMLprim value stub_eventchn_unbind(value xce_val, value port)
 CAMLprim value stub_eventchn_pending(value xce_val)
 {
 	CAMLparam1(xce_val);
-	CAMLlocal1(result);
 	xenevtchn_handle *xce = xce_of_val(xce_val);
-	xenevtchn_port_or_error_t port;
+	xenevtchn_port_or_error_t rc;
 
 	caml_enter_blocking_section();
-	port = xenevtchn_pending(xce);
+	rc = xenevtchn_pending(xce);
 	caml_leave_blocking_section();
 
-	if (port == -1)
+	if (rc == -1)
 		caml_failwith("evtchn pending failed");
-	result = Val_int(port);
 
-	CAMLreturn(result);
+	CAMLreturn(Val_int(rc));
 }
 
-CAMLprim value stub_eventchn_unmask(value xce_val, value _port)
+CAMLprim value stub_eventchn_unmask(value xce_val, value port)
 {
-	CAMLparam2(xce_val, _port);
+	CAMLparam2(xce_val, port);
 	xenevtchn_handle *xce = xce_of_val(xce_val);
-	evtchn_port_t port;
 	int rc;
 
-	port = Int_val(_port);
-
 	caml_enter_blocking_section();
-	rc = xenevtchn_unmask(xce, port);
+	rc = xenevtchn_unmask(xce, Int_val(port));
 	caml_leave_blocking_section();
 
-	if (rc)
+	if (rc == -1)
 		caml_failwith("evtchn unmask failed");
+
 	CAMLreturn(Val_unit);
 }
-- 
2.11.0