Hi,

On Tue, Sep 09, 2014 at 03:20:58PM +0200, François MULLER wrote:
> Hi all,
> 
> I've backported some commits to my kernel (3.4) to get gadget state
> tracking.
> 
> I think that I missed something or there is a small error on this one that
> hasn't been spotted:
> 
> http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=49401f4169c0e5a1b38f1a676d6f12eecaf77485
> 
> -----------------
> +void usb_gadget_set_state(struct usb_gadget *gadget,
> + enum usb_device_state state)
> +{
> + gadget->state = state;
> + sysfs_notify(&gadget->dev.kobj, NULL, "status");
> +}
> -----------------
> 
> The sysfs_notify is done on the gadget kobject and the sysfs group is under
> the udc kobject :
> 
> -----------------
> static struct attribute *usb_udc_attrs[] = {
> (...)
> +    &dev_attr_state.attr,
> 
> int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget
> *gadget,
> (...)
>     udc->dev.groups = usb_udc_attr_groups;
> -----------------
> 
> To make it work correctly we need to do the sysfs_notify on the udc kobject
> too.
> We've done this using this following patch :
> 
> -----------------
> diff --git a/drivers/usb/gadget/udc-core.c b/drivers/usb/gadget/udc-core.c
> index 7d8d839..03e9f49 100644
> --- a/drivers/usb/gadget/udc-core.c
> +++ b/drivers/usb/gadget/udc-core.c
> @@ -129,8 +129,18 @@ static inline int usb_gadget_start(struct usb_gadget
> *gadget,
>  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;
> +       udc = NULL;
> +found:
> +       mutex_unlock(&udc_lock);
> 
> -       sysfs_notify(&gadget->dev.kobj, NULL, "state");
> +       if(udc)
> +               sysfs_notify(&udc->dev.kobj, NULL, "state");
>  }
> 
>  void usb_gadget_set_state(struct usb_gadget *gadget,
> -----------------
> 
> If there is something I missed, please tell me.

you haven't missed anything, you're correct. Do you want to send this in
a proper patch format so it's included in all supported kernels which
are affected by this bug ?

Please have a read at Documentation/CodingStyle,
Documentation/SubmittingPatches, Documentation/SubmitChecklist and
Documentation/stable_kernel_rules.txt

With that, you should be able to send a patch in the proper format. From
a code standpoint, you really found a good bug :-)

Don't forget to add:

Fixes: 49401f4 (usb: gadget: introduce gadget state tracking)
Cc: <sta...@vger.kernel.org> # v3.10+

to your commit log, right above your Signed-off-by line.

cheers

-- 
balbi

Attachment: signature.asc
Description: Digital signature

Reply via email to