diff options
-rw-r--r-- | include/usbg/usbg.h | 7 | ||||
-rw-r--r-- | src/usbg.c | 28 |
2 files changed, 35 insertions, 0 deletions
diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h index d2cb4e9..8a973e7 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 */ @@ -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; |