Index: uspace/lib/usbdev/src/hub.c
===================================================================
--- uspace/lib/usbdev/src/hub.c	(revision 10059a68788a72850b73bfc6dc8e4acdd530bd51)
+++ uspace/lib/usbdev/src/hub.c	(revision 90d7033846a8edda8717433838bf02e35cf19f72)
@@ -171,5 +171,5 @@
  *
  * @param[in] parent Parent device (i.e. the hub device).
- * @param[in] connection Connection to host controller.
+ * @param[in] connection Connection to host controller. Must be non-null.
  * @param[in] dev_speed New device speed.
  * @param[in] enable_port Function for enabling signaling through the port the
@@ -181,6 +181,7 @@
  *	as @c driver_data.
  * @param[out] new_fun Storage where pointer to allocated child function
- *	will be written.
+ *	will be written. Must be non-null.
  * @return Error code.
+ * @retval EINVAL Either connection or new_fun is a NULL pointer.
  * @retval ENOENT Connection to HC not opened.
  * @retval EADDRNOTAVAIL Failed retrieving free address from host controller.
@@ -195,6 +196,9 @@
     ddf_dev_ops_t *dev_ops, void *new_dev_data, ddf_fun_t **new_fun)
 {
-	assert(connection != NULL);
+	if (new_fun == NULL || connection == NULL)
+		return EINVAL;
+
 	// FIXME: this is awful, we are accessing directly the structure.
+	// TODO: Why not use provided connection?
 	usb_hc_connection_t hc_conn = {
 		.hc_handle = connection->hc_handle,
@@ -321,5 +325,4 @@
 	    parent, dev_ops, new_dev_data, &child_fun);
 	if (rc != EOK) {
-		rc = ESTALL;
 		goto leave_release_free_address;
 	}
@@ -328,5 +331,5 @@
 	 * And now inform the host controller about the handle.
 	 */
-	usb_hub_attached_device_t new_device = {
+	const usb_hub_attached_device_t new_device = {
 		.address = dev_addr,
 		.fun = child_fun,
@@ -334,8 +337,10 @@
 	rc = usb_hc_register_device(&hc_conn, &new_device);
 	if (rc != EOK) {
+		/* The child function is already created. */
+		child_fun->driver_data = NULL;
+		ddf_fun_destroy(child_fun);
 		rc = EDESTADDRREQ;
 		goto leave_release_free_address;
 	}
-
 
 	/*
