[PATCH 8/9] libusbg: Allow to get gadget enabled on given UDC

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

 



Add usbg_get_udc_gadget() which allows user to learn
which gadget is attached to selected UDC.

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

diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index 7b0c756..e5a29a8 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -825,6 +825,13 @@ extern int usbg_cpy_udc_name(usbg_udc *u, char *buf, size_t len);
  */
 extern usbg_udc *usbg_get_gadget_udc(usbg_gadget *g);
 
+/**
+ * @brief Get gadget which is attached to this UDC
+ * @param u Pointer to udc
+ * @return Pointer to gadget or NULL if UDC is free
+ */
+extern usbg_gadget *usbg_get_udc_gadget(usbg_udc *u);
+
 /*
  * USB function-specific attribute configuration
  */
diff --git a/src/usbg.c b/src/usbg.c
index 78490c1..d82f1e9 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -1899,6 +1899,36 @@ out:
 	return u;
 }
 
+usbg_gadget *usbg_get_udc_gadget(usbg_udc *u)
+{
+	char buf[USBG_MAX_STR_LENGTH];
+	int ret;
+	usbg_gadget *g = NULL;
+
+	if (!u)
+		goto out;
+	/*
+	 * if gadget was enabled on this UDC we have to check if kernel
+	 * didn't modify this due to some errors.
+	 * For example some FFS daemon could just get a segmentation fault
+	 * what causes detach of gadget
+	 */
+	if (u->gadget) {
+		usbg_udc *u_checked;
+
+		u_checked = usbg_get_gadget_udc(u->gadget);
+		if (u_checked) {
+			g = u->gadget;
+		} else {
+			u->gadget->udc = NULL;
+			u->gadget = NULL;
+		}
+	}
+
+out:
+	return g;
+}
+
 int usbg_set_gadget_attrs(usbg_gadget *g, usbg_gadget_attrs *g_attrs)
 {
 	int ret;
-- 
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