Index: uspace/lib/drv/generic/driver.c
===================================================================
--- uspace/lib/drv/generic/driver.c	(revision 4d94002d4fa05a47f00a4d66be68ebcea93e03e3)
+++ uspace/lib/drv/generic/driver.c	(revision bfe7867b8b6d864abc1f0ba5490a1a568432d127)
@@ -673,7 +673,13 @@
 }
 
-/** Increase function reference count. */
+/** Increase function reference count.
+ *
+ * This also increases reference count on the device. The device structure
+ * will thus not be deallocated while there are some associated function
+ * structures.
+ */
 static void fun_add_ref(ddf_fun_t *fun)
 {
+	dev_add_ref(fun->dev);
 	atomic_inc(&fun->refcnt);
 }
@@ -685,6 +691,10 @@
 static void fun_del_ref(ddf_fun_t *fun)
 {
+	ddf_dev_t *dev = fun->dev;
+
 	if (atomic_predec(&fun->refcnt) == 0)
 		delete_function(fun);
+
+	dev_del_ref(dev);
 }
 
@@ -721,8 +731,8 @@
 
 	/* Add one reference that will be dropped by ddf_fun_destroy() */
+	fun->dev = dev;
 	fun_add_ref(fun);
 
 	fun->bound = false;
-	fun->dev = dev;
 	fun->ftype = ftype;
 
