]> xenbits.xensource.com Git - xen.git/commitdiff
tools/ocaml/evtchn: Misc cleanup
authorAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 30 Jan 2023 16:37:49 +0000 (16:37 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 6 Feb 2023 10:22:12 +0000 (10:22 +0000)
 * 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>
Acked-by: Christian Lindig <christian.lindig@citrix.com>
tools/ocaml/libs/eventchn/xeneventchn_stubs.c

index d7881ca95f983311efa41f52c53405ae2f926d9d..34dcfed30275f66e9e143eac6560b3e471c325a4 100644 (file)
@@ -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);
 }