diff mbox series

[Xen-devel,11/27,v8] xen/arm: vpl011: Add a new console_init function in xenconsole

Message ID 1503910570-24427-12-git-send-email-bhupinder.thakur@linaro.org
State Superseded
Headers show
Series SBSA UART emulation support in Xen | expand

Commit Message

Bhupinder Thakur Aug. 28, 2017, 8:55 a.m. UTC
This patch introduces a new console_init function. This function
initializes the console structure.

Signed-off-by: Bhupinder Thakur <bhupinder.thakur@linaro.org>
---
CC: Ian Jackson <ian.jackson@eu.citrix.com>
CC: Wei Liu <wei.liu2@citrix.com>
CC: Stefano Stabellini <sstabellini@kernel.org>
CC: Julien Grall <julien.grall@arm.com>

Changes since v5:
- Split this change in a separate patch.

 tools/console/daemon/io.c | 65 ++++++++++++++++++++++++++++-------------------
 1 file changed, 39 insertions(+), 26 deletions(-)

Comments

Wei Liu Aug. 28, 2017, 4:40 p.m. UTC | #1
On Mon, Aug 28, 2017 at 02:25:54PM +0530, Bhupinder Thakur wrote:
> This patch introduces a new console_init function. This function
> initializes the console structure.
> 
> Signed-off-by: Bhupinder Thakur <bhupinder.thakur@linaro.org>

It appears that you forgot to collect my ack:

Acked-by: Wei Liu <wei.liu2@citrix.com>
diff mbox series

Patch

diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index a2a3496..1da08d7 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -655,20 +655,51 @@  static bool watch_domain(struct domain *dom, bool watch)
 	return success;
 }
 
-
-static struct domain *create_domain(int domid)
+static int console_init(struct console *con, struct domain *dom)
 {
-	struct domain *dom;
 	char *s;
+	int err = -1;
 	struct timespec ts;
-	struct console *con;
 
 	if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) {
 		dolog(LOG_ERR, "Cannot get time of day %s:%s:L%d",
 		      __FILE__, __FUNCTION__, __LINE__);
-		return NULL;
+		return err;
 	}
 
+	con->master_fd = -1;
+	con->master_pollfd_idx = -1;
+	con->slave_fd = -1;
+	con->log_fd = -1;
+	con->ring_ref = -1;
+	con->local_port = -1;
+	con->remote_port = -1;
+	con->xce_pollfd_idx = -1;
+	con->next_period = ((long long)ts.tv_sec * 1000) + (ts.tv_nsec / 1000000) + RATE_LIMIT_PERIOD;
+	con->d = dom;
+	con->xspath = xs_get_domain_path(xs, dom->domid);
+	s = realloc(con->xspath, strlen(con->xspath) +
+		    strlen("/console") + 1);
+	if (s) {
+		con->xspath = s;
+		strcat(con->xspath, "/console");
+		err = 0;
+	}
+
+	return err;
+}
+
+static void console_free(struct console *con)
+{
+	if (con->xspath)
+		free(con->xspath);
+}
+
+static struct domain *create_domain(int domid)
+{
+	struct domain *dom;
+	struct console *con;
+
 	dom = calloc(1, sizeof *dom);
 	if (dom == NULL) {
 		dolog(LOG_ERR, "Out of memory %s:%s():L%d",
@@ -677,28 +708,10 @@  static struct domain *create_domain(int domid)
 	}
 
 	dom->domid = domid;
-
 	con = &dom->console;
-	con->xspath = xs_get_domain_path(xs, dom->domid);
-	s = realloc(con->xspath, strlen(con->xspath) +
-		    strlen("/console") + 1);
-	if (s == NULL)
-		goto out;
-	con->xspath = s;
-	strcat(con->xspath, "/console");
-
-	con->master_fd = -1;
-	con->master_pollfd_idx = -1;
-	con->slave_fd = -1;
-	con->log_fd = -1;
-	con->xce_pollfd_idx = -1;
-	con->d = dom;
-
-	con->next_period = ((long long)ts.tv_sec * 1000) + (ts.tv_nsec / 1000000) + RATE_LIMIT_PERIOD;
 
-	con->ring_ref = -1;
-	con->local_port = -1;
-	con->remote_port = -1;
+	if (console_init(con, dom))
+		goto out;
 
 	if (!watch_domain(dom, true))
 		goto out;
@@ -710,7 +723,7 @@  static struct domain *create_domain(int domid)
 
 	return dom;
  out:
-	free(con->xspath);
+	console_free(con);
 	free(dom);
 	return NULL;
 }