Index: uspace/drv/bus/usb/usbmast/main.c
===================================================================
--- uspace/drv/bus/usb/usbmast/main.c	(revision 87037cc964953580eab1f30e5a171547c9e01cb3)
+++ uspace/drv/bus/usb/usbmast/main.c	(revision 3002434fa388f59c77ee7bd7c849335a51dbc72a)
@@ -82,4 +82,29 @@
     void *arg);
 
+/** Callback when a device is removed from the system.
+ *
+ * @param dev Representation of USB device.
+ * @return Error code.
+ */
+static int usbmast_device_gone(usb_device_t *dev)
+{
+	usbmast_dev_t *mdev = dev->driver_data;
+	assert(mdev);
+
+	for (size_t i = 0; i < mdev->lun_count; ++i) {
+		const int rc = ddf_fun_unbind(mdev->luns[i]);
+		if (rc != EOK) {
+			usb_log_error("Failed to unbind LUN function %zu: "
+			    "%s\n", i, str_error(rc));
+			return rc;
+		}
+		ddf_fun_destroy(mdev->luns[i]);
+		mdev->luns[i] = NULL;
+	}
+	free(mdev->luns);
+	free(mdev);
+	return EOK;
+}
+
 /** Callback when new device is attached and recognized as a mass storage.
  *
@@ -128,5 +153,17 @@
 	return EOK;
 error:
-	/* XXX Destroy functions */
+	/* Destroy functions */
+	for (size_t i = 0; i < mdev->lun_count; ++i) {
+		if (mdev->luns[i] == NULL)
+			continue;
+		const int rc = ddf_fun_unbind(mdev->luns[i]);
+		if (rc != EOK) {
+			usb_log_warning("Failed to unbind LUN function %zu: "
+			    "%s.\n", i, str_error(rc));
+		}
+		ddf_fun_destroy(mdev->luns[i]);
+	}
+	free(mdev->luns);
+	free(mdev);
 	return rc;
 }
@@ -303,4 +340,5 @@
 static usb_driver_ops_t usbmast_driver_ops = {
 	.device_add = usbmast_device_add,
+	.device_gone = usbmast_device_gone,
 };
 
