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

Signed-off-by: Krzysztof Opasiak <k.opas...@samsung.com>
---
 include/usbg/usbg.h |    7 +++++++
 src/usbg.c          |   28 ++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index f5d0098..0a1fdf5 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -885,6 +885,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 998bce8..488aa97 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -1963,6 +1963,34 @@ out:
        return u;
 }
 
+usbg_gadget *usbg_get_udc_gadget(usbg_udc *u)
+{
+       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 majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to