[PATCH v4 4/6] libusbg: Add remove function functionality.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add function which allow to remove USB function.
This functions also remove function from internal
library structures what means that after this
operation all pointers to removed function are invalid.

Signed-off-by: Krzysztof Opasiak <k.opasiak@xxxxxxxxxxx>
---
 include/usbg/usbg.h |    9 +++++++++
 src/usbg.c          |   42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)

diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index 4bfa058..4b04551 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -303,6 +303,15 @@ extern int usbg_rm_binding(usbg_binding *b);
 extern int usbg_rm_config(usbg_config *c, int opts);
 
 /**
+ * @brief Remove existing USB function
+ * @details This function frees also the memory allocated for function
+ * @param f Function to be removed
+ * @param opts Additional options for configuration removal.
+ * @return 0 on success, usbg_error if error occurred
+ */
+extern int usbg_rm_function(usbg_function *f, int opts);
+
+/**
  * @brief Remove configuration strings for given language
  * @param c Pointer to configuration
  * @param lang Language of strings which should be deleted
diff --git a/src/usbg.c b/src/usbg.c
index 7fae9fe..bb7e836 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -1387,6 +1387,48 @@ out:
 	return ret;
 }
 
+int usbg_rm_function(usbg_function *f, int opts)
+{
+	int ret = USBG_ERROR_INVALID_PARAM;
+	usbg_gadget *g;
+
+	if (!f)
+		return ret;
+
+	g = f->parent;
+
+	if (opts & USBG_RM_RECURSE) {
+		/* Recursive flag was given
+		 * so remove all bindings to this function */
+		usbg_config *c;
+		usbg_binding *b;
+
+		TAILQ_FOREACH(c, &g->configs, cnode) {
+			b = TAILQ_FIRST(&c->bindings);
+			while (b != NULL) {
+				if (b->target == f) {
+					usbg_binding *b_next = TAILQ_NEXT(b, bnode);
+					ret = usbg_rm_binding(b);
+					if (ret != USBG_SUCCESS)
+						return ret;
+
+					b = b_next;
+				} else {
+					b = TAILQ_NEXT(b, bnode);
+				}
+			} /* while */
+		} /* TAILQ_FOREACH */
+	}
+
+	ret = usbg_rm_dir(f->path, f->name);
+	if (ret == USBG_SUCCESS) {
+		TAILQ_REMOVE(&(g->functions), f, fnode);
+		usbg_free_function(f);
+	}
+
+	return ret;
+}
+
 int usbg_rm_config_strs(usbg_config *c, int lang)
 {
 	int ret = USBG_SUCCESS;
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux