Index: uspace/drv/char/i8042/i8042.c
===================================================================
--- uspace/drv/char/i8042/i8042.c	(revision e7588a831a1d2d5847475a67a5b1bc4b10366d7c)
+++ uspace/drv/char/i8042/i8042.c	(revision ac307b25a02622848f9ee9d1bff85d6cd4c35ca2)
@@ -136,6 +136,4 @@
 	const uint8_t data = IPC_GET_ARG2(*call);
 	
-	circ_buf_t *cbuf = (status & i8042_AUX_DATA) ?
-	    &controller->aux_buffer : &controller->kbd_buffer;
 	i8042_port_t *port = (status & i8042_AUX_DATA) ?
 	    controller->aux : controller->kbd;
@@ -143,5 +141,5 @@
 	fibril_mutex_lock(&port->buf_lock);
 	
-	rc = circ_buf_push(cbuf, &data);
+	rc = circ_buf_push(&port->cbuf, &data);
 	if (rc != EOK)
 		ddf_msg(LVL_ERROR, "Buffer overrun");
@@ -170,12 +168,11 @@
 	const size_t cmd_count = sizeof(i8042_cmds) / sizeof(irq_cmd_t);
 	irq_cmd_t cmds[cmd_count];
+	ddf_fun_t *kbd_fun;
+	ddf_fun_t *aux_fun;
 	i8042_regs_t *ar;
-
+	
 	int rc;
 	bool kbd_bound = false;
 	bool aux_bound = false;
-
-	dev->kbd_fun = NULL;
-	dev->aux_fun = NULL;
 	
 	if (regs->size < sizeof(i8042_regs_t)) {
@@ -189,11 +186,11 @@
 	}
 	
-	dev->kbd_fun = ddf_fun_create(ddf_dev, fun_inner, "ps2a");
-	if (dev->kbd_fun == NULL) {
+	kbd_fun = ddf_fun_create(ddf_dev, fun_inner, "ps2a");
+	if (kbd_fun == NULL) {
 		rc = ENOMEM;
 		goto error;
 	};
 	
-	dev->kbd = ddf_fun_data_alloc(dev->kbd_fun, sizeof(i8042_port_t));
+	dev->kbd = ddf_fun_data_alloc(kbd_fun, sizeof(i8042_port_t));
 	if (dev->kbd == NULL) {
 		rc = ENOMEM;
@@ -201,4 +198,5 @@
 	}
 	
+	dev->kbd->fun = kbd_fun;
 	dev->kbd->ctl = dev;
 	chardev_srvs_init(&dev->kbd->cds);
@@ -208,15 +206,15 @@
 	fibril_condvar_initialize(&dev->kbd->buf_cv);
 	
-	rc = ddf_fun_add_match_id(dev->kbd_fun, "char/xtkbd", 90);
+	rc = ddf_fun_add_match_id(dev->kbd->fun, "char/xtkbd", 90);
 	if (rc != EOK)
 		goto error;
 	
-	dev->aux_fun = ddf_fun_create(ddf_dev, fun_inner, "ps2b");
-	if (dev->aux_fun == NULL) {
+	aux_fun = ddf_fun_create(ddf_dev, fun_inner, "ps2b");
+	if (aux_fun == NULL) {
 		rc = ENOMEM;
 		goto error;
 	}
 	
-	dev->aux = ddf_fun_data_alloc(dev->aux_fun, sizeof(i8042_port_t));
+	dev->aux = ddf_fun_data_alloc(aux_fun, sizeof(i8042_port_t));
 	if (dev->aux == NULL) {
 		rc = ENOMEM;
@@ -224,4 +222,5 @@
 	}
 	
+	dev->aux->fun = aux_fun;
 	dev->aux->ctl = dev;
 	chardev_srvs_init(&dev->aux->cds);
@@ -231,27 +230,27 @@
 	fibril_condvar_initialize(&dev->aux->buf_cv);
 	
-	rc = ddf_fun_add_match_id(dev->aux_fun, "char/ps2mouse", 90);
+	rc = ddf_fun_add_match_id(dev->aux->fun, "char/ps2mouse", 90);
 	if (rc != EOK)
 		goto error;
 	
-	ddf_fun_set_conn_handler(dev->kbd_fun, i8042_char_conn);
-	ddf_fun_set_conn_handler(dev->aux_fun, i8042_char_conn);
-	
-	circ_buf_init(&dev->kbd_buffer, dev->kbd_data, BUFFER_SIZE, 1);
-	circ_buf_init(&dev->aux_buffer, dev->aux_data, BUFFER_SIZE, 1);
+	ddf_fun_set_conn_handler(dev->kbd->fun, i8042_char_conn);
+	ddf_fun_set_conn_handler(dev->aux->fun, i8042_char_conn);
+	
+	circ_buf_init(&dev->kbd->cbuf, dev->kbd->buf_data, BUFFER_SIZE, 1);
+	circ_buf_init(&dev->aux->cbuf, dev->aux->buf_data, BUFFER_SIZE, 1);
 	fibril_mutex_initialize(&dev->write_guard);
 	
-	rc = ddf_fun_bind(dev->kbd_fun);
+	rc = ddf_fun_bind(dev->kbd->fun);
 	if (rc != EOK) {
 		ddf_msg(LVL_ERROR, "Failed to bind keyboard function: %s.",
-		    ddf_fun_get_name(dev->kbd_fun));
+		    ddf_fun_get_name(dev->kbd->fun));
 		goto error;
 	}
 	kbd_bound = true;
 	
-	rc = ddf_fun_bind(dev->aux_fun);
+	rc = ddf_fun_bind(dev->aux->fun);
 	if (rc != EOK) {
 		ddf_msg(LVL_ERROR, "Failed to bind aux function: %s.",
-		    ddf_fun_get_name(dev->aux_fun));
+		    ddf_fun_get_name(dev->aux->fun));
 		goto error;
 	}
@@ -332,11 +331,11 @@
 error:
 	if (kbd_bound)
-		ddf_fun_unbind(dev->kbd_fun);
+		ddf_fun_unbind(dev->kbd->fun);
 	if (aux_bound)
-		ddf_fun_unbind(dev->aux_fun);
-	if (dev->kbd_fun != NULL)
-		ddf_fun_destroy(dev->kbd_fun);
-	if (dev->aux_fun != NULL)
-		ddf_fun_destroy(dev->aux_fun);
+		ddf_fun_unbind(dev->aux->fun);
+	if (dev->kbd->fun != NULL)
+		ddf_fun_destroy(dev->kbd->fun);
+	if (dev->aux->fun != NULL)
+		ddf_fun_destroy(dev->aux->fun);
 
 	return rc;
@@ -393,19 +392,15 @@
 	i8042_port_t *port = (i8042_port_t *)srv->srvs->sarg;
 	size_t p;
-	i8042_t *i8042 = port->ctl;
 	uint8_t *destp = (uint8_t *)dest;
 	int rc;
 	
-	circ_buf_t *cbuf = (port == i8042->aux) ?
-	    &i8042->aux_buffer : &i8042->kbd_buffer;
-	
 	fibril_mutex_lock(&port->buf_lock);
 	
-	while (circ_buf_nused(cbuf) == 0)
+	while (circ_buf_nused(&port->cbuf) == 0)
 		fibril_condvar_wait(&port->buf_cv, &port->buf_lock);
 
 	p = 0;
 	while (p < size) {
-		rc = circ_buf_pop(cbuf, &destp[p]);
+		rc = circ_buf_pop(&port->cbuf, &destp[p]);
 		if (rc != EOK)
 			break;
