summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/linux/usb/gadget.h13
1 files changed, 11 insertions, 2 deletions
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index f1b0dca60f1..16892ab59c8 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -533,6 +533,7 @@ struct usb_gadget {
unsigned b_hnp_enable:1;
unsigned a_hnp_support:1;
unsigned a_alt_hnp_support:1;
+ atomic_t connect_count;
const char *name;
struct device dev;
unsigned out_epnum;
@@ -724,7 +725,11 @@ static inline int usb_gadget_connect(struct usb_gadget *gadget)
{
if (!gadget->ops->pullup)
return -EOPNOTSUPP;
- return gadget->ops->pullup(gadget, 1);
+
+ if (atomic_inc_return(&gadget->connect_count) == 1)
+ return gadget->ops->pullup(gadget, 1);
+
+ return 0;
}
/**
@@ -746,7 +751,11 @@ static inline int usb_gadget_disconnect(struct usb_gadget *gadget)
{
if (!gadget->ops->pullup)
return -EOPNOTSUPP;
- return gadget->ops->pullup(gadget, 0);
+
+ if (atomic_dec_and_test(&gadget->connect_count))
+ return gadget->ops->pullup(gadget, 0);
+
+ return 0;
}