[PATCH v3 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 |   10 ++++++++++
 src/usbg.c          |   42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)

diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index 3baa9aa..f79ace4 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -290,6 +290,16 @@ extern int usbg_remove_binding(usbg_binding *b);
 extern int usbg_remove_config(usbg_config *c, int recursive);
 
 /**
+ * @brief Remove existing USB function
+ * @details This function frees also the memory allocated for function
+ * @param f Function to be removed
+ * @param recursive If different than 0 all bindings pointing
+ *  to this function will be also removed before removing function
+ * @return 0 on success, usbg_error if error occurred
+ */
+extern int usbg_remove_function(usbg_function *f, int recursive);
+
+/**
  * @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 36923a5..36237c7 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -1226,6 +1226,48 @@ out:
 	return ret;
 }
 
+int usbg_remove_function(usbg_function *f, int recursive)
+{
+	int ret = USBG_ERROR_INVALID_PARAM;
+	usbg_gadget *g;
+
+	if (!f)
+		return ret;
+
+	g = f->parent;
+
+	if (recursive) {
+		/* 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_remove_binding(b);
+					if (ret != USBG_SUCCESS)
+						return ret;
+
+					b = b_next;
+				} else {
+					b = TAILQ_NEXT(b, bnode);
+				}
+			} /* while */
+		} /* TAILQ_FOREACH */
+	}
+
+	ret = usbg_remove_dir(f->path, f->name);
+	if (ret == USBG_SUCCESS) {
+		TAILQ_REMOVE(&(g->functions), f, fnode);
+		usbg_free_function(f);
+	}
+
+	return ret;
+}
+
 int usbg_remove_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