From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matthew Daley Subject: [PATCH v2] libvchan: handle libxc evtchn failures properly in init functions Date: Thu, 31 Oct 2013 16:41:32 +1300 Message-ID: <1383190892-15639-1-git-send-email-mattjd@gmail.com> References: <1383119525-26033-25-git-send-email-mattjd@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1383119525-26033-25-git-send-email-mattjd@gmail.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: Daniel De Graaf , Matthew Daley , Ian Jackson , Ian Campbell , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org The reasoning behind this patch is that ctrl->event_port is a uint32_t (ie. unsigned), so the current checks on it for negative error results, non-negative port presence etc. are incorrect. Fix by using evtchn_port_or_error_t in the init functions instead, adjusting the error handling, and removing the now-unnecessary check from the close function. Coverity-ID: 1055609 Coverity-ID: 1055610 Coverity-ID: 1055611 Signed-off-by: Matthew Daley Reviewed-by: Daniel De Graaf --- v2: Elaborate patch purpose in commit message. Change from int to evtchn_port_or_error_t, suggested by Daniel De Graaf. tools/libvchan/init.c | 47 +++++++++++++++++++++++++++++++++++++++-------- tools/libvchan/io.c | 2 +- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/tools/libvchan/init.c b/tools/libvchan/init.c index 0c7cff6..c080a1c 100644 --- a/tools/libvchan/init.c +++ b/tools/libvchan/init.c @@ -215,15 +215,30 @@ static int init_gnt_cli(struct libxenvchan *ctrl, int domain, uint32_t ring_ref) static int init_evt_srv(struct libxenvchan *ctrl, int domain, xentoollog_logger *logger) { + evtchn_port_or_error_t port; + ctrl->event = xc_evtchn_open(logger, 0); if (!ctrl->event) return -1; - ctrl->event_port = xc_evtchn_bind_unbound_port(ctrl->event, domain); - if (ctrl->event_port < 0) - return -1; + + port = xc_evtchn_bind_unbound_port(ctrl->event, domain); + if (port < 0) + goto fail; + ctrl->event_port = port; + if (xc_evtchn_unmask(ctrl->event, ctrl->event_port)) - return -1; + goto fail; + return 0; + +fail: + if (port >= 0) + xc_evtchn_unbind(ctrl->event, port); + + xc_evtchn_close(ctrl->event); + ctrl->event = NULL; + + return -1; } static int init_xs_srv(struct libxenvchan *ctrl, int domain, const char* xs_base, int ring_ref) @@ -330,15 +345,31 @@ out: static int init_evt_cli(struct libxenvchan *ctrl, int domain, xentoollog_logger *logger) { + evtchn_port_or_error_t port; + ctrl->event = xc_evtchn_open(logger, 0); if (!ctrl->event) return -1; - ctrl->event_port = xc_evtchn_bind_interdomain(ctrl->event, + + port = xc_evtchn_bind_interdomain(ctrl->event, domain, ctrl->event_port); - if (ctrl->event_port < 0) - return -1; - xc_evtchn_unmask(ctrl->event, ctrl->event_port); + if (port < 0) + goto fail; + ctrl->event_port = port; + + if (xc_evtchn_unmask(ctrl->event, ctrl->event_port)) + goto fail; + return 0; + +fail: + if (port >= 0) + xc_evtchn_unbind(ctrl->event, port); + + xc_evtchn_close(ctrl->event); + ctrl->event = NULL; + + return -1; } diff --git a/tools/libvchan/io.c b/tools/libvchan/io.c index 3c8d236..2383364 100644 --- a/tools/libvchan/io.c +++ b/tools/libvchan/io.c @@ -337,7 +337,7 @@ void libxenvchan_close(struct libxenvchan *ctrl) } } if (ctrl->event) { - if (ctrl->event_port >= 0 && ctrl->ring) + if (ctrl->ring) xc_evtchn_notify(ctrl->event, ctrl->event_port); xc_evtchn_close(ctrl->event); } -- 1.7.10.4