Skip to contentSkip to conversation

usb: gadget: udc_core: Use right kobj when calling sysfs_notify

PATCH In review Andreas Larsson 3 participants 4 messages Sep 15, 2014 – Sep 16, 2014 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: gadget: udc_core: Use right kobj when calling sysfs_notify

The state attribute is connected to the kobj of the udc, not the gadget.

---
 drivers/usb/gadget/udc/udc-core.c |   14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/usb/gadget/udc/udc-core.c +13 -1
index b0d9817..37c129a 100644
@@ -109,8 +109,20 @@ EXPORT_SYMBOL_GPL(usb_gadget_unmap_request);
 static void usb_gadget_state_work(struct work_struct *work)
 {
 	struct usb_gadget	*gadget = work_to_gadget(work);
+	struct usb_udc		*udc = NULL;
+
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list)
+		if (udc->gadget == gadget)
+			goto found;
+	mutex_unlock(&udc_lock);
+
+	return;
+
+found:
+	mutex_unlock(&udc_lock);
 
-	sysfs_notify(&gadget->dev.kobj, NULL, "state");
+	sysfs_notify(&udc->dev.kobj, NULL, "state");
 }
 
 void usb_gadget_set_state(struct usb_gadget *gadget,
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 23 lines · Andreas Larsson

The state attribute is connected to the kobj of the udc, not the gadget.

---
 drivers/usb/gadget/udc/udc-core.c |   14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/usb/gadget/udc/udc-core.c +8 -0
index b0d9817..37c129a 100644
@@ -109,8 +109,20 @@ EXPORT_SYMBOL_GPL(usb_gadget_unmap_request);
 static void usb_gadget_state_work(struct work_struct *work)
 {
 	struct usb_gadget	*gadget = work_to_gadget(work);
+	struct usb_udc		*udc = NULL;
+
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list)
+		if (udc->gadget == gadget)
+			goto found;
+	mutex_unlock(&udc_lock);
+

drivers/usb/gadget/udc/udc-core.c EXPORT_SYMBOL_GPL(usb_gadget_unmap_request); · line 128

Quoted 10 lines
drivers/usb/gadget/udc/udc-core.c +5 -1
+	return;
+
+found:
+	mutex_unlock(&udc_lock);
 
-	sysfs_notify(&gadget->dev.kobj, NULL, "state");
+	sysfs_notify(&udc->dev.kobj, NULL, "state");
 }
 
 void usb_gadget_set_state(struct usb_gadget *gadget,

What's the user mode difference with and without this patch?

Signature · 2 lines
Best Regards,
Peter Chen
#2 lore raw

Hi,

Quoted 29 lines · Peter Chen
Quoted 28 lines · Andreas Larsson

The state attribute is connected to the kobj of the udc, not the gadget.

---
 drivers/usb/gadget/udc/udc-core.c |   14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/usb/gadget/udc/udc-core.c +12 -0
index b0d9817..37c129a 100644
@@ -109,8 +109,20 @@ EXPORT_SYMBOL_GPL(usb_gadget_unmap_request);
 static void usb_gadget_state_work(struct work_struct *work)
 {
 	struct usb_gadget	*gadget = work_to_gadget(work);
+	struct usb_udc		*udc = NULL;
+
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list)
+		if (udc->gadget == gadget)
+			goto found;
+	mutex_unlock(&udc_lock);
+
+	return;
+
+found:
+	mutex_unlock(&udc_lock);
 
Quoted 7 lines

drivers/usb/gadget/udc/udc-core.c EXPORT_SYMBOL_GPL(usb_gadget_unmap_request); · line 128

Quoted 5 lines
drivers/usb/gadget/udc/udc-core.c +1 -1
-	sysfs_notify(&gadget->dev.kobj, NULL, "state");
+	sysfs_notify(&udc->dev.kobj, NULL, "state");
 }
 
 void usb_gadget_set_state(struct usb_gadget *gadget,

What's the user mode difference with and without this patch?

poll() will actually wakeup ?

Signature · 1 line
balbi
#3 lore raw
Quoted 36 lines · Felipe Balbi

Hi,

Quoted 33 lines · Peter Chen
Quoted 32 lines · Andreas Larsson

The state attribute is connected to the kobj of the udc, not the gadget.

---
  drivers/usb/gadget/udc/udc-core.c |   14 +++++++++++++-
  1 file changed, 13 insertions(+), 1 deletion(-)
drivers/usb/gadget/udc/udc-core.c +13 -1
index b0d9817..37c129a 100644
@@ -109,8 +109,20 @@ EXPORT_SYMBOL_GPL(usb_gadget_unmap_request);
  static void usb_gadget_state_work(struct work_struct *work)
  {
  	struct usb_gadget	*gadget = work_to_gadget(work);
+	struct usb_udc		*udc = NULL;
+
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list)
+		if (udc->gadget == gadget)
+			goto found;
+	mutex_unlock(&udc_lock);
+
+	return;
+
+found:
+	mutex_unlock(&udc_lock);
 
-	sysfs_notify(&gadget->dev.kobj, NULL, "state");
+	sysfs_notify(&udc->dev.kobj, NULL, "state");
  }
 
Quoted 5 lines
Quoted 3 lines

drivers/usb/gadget/udc/udc-core.c EXPORT_SYMBOL_GPL(usb_gadget_unmap_request); · line 128

Quoted 1 line
drivers/usb/gadget/udc/udc-core.c +0 -0
  void usb_gadget_set_state(struct usb_gadget *gadget,

What's the user mode difference with and without this patch?

poll() will actually wakeup ?

Yes, that is indeed the difference.

Cheers,
Andreas Larsson