Re: [PATCH v2] usb: gadget: f_sourcesink: fix function params handling

2015-10-14 Thread Robert Baldyga
Hi Felipe,

On 09/24/2015 06:49 PM, Felipe Balbi wrote:
> On Thu, Sep 24, 2015 at 05:23:09PM +0200, Robert Baldyga wrote:
>> Move function parameters to struct f_sourcesink to make them per instance
>> instead of having them as global variables. Since we can have multiple
>> instances of USB function we also want to have separate set of parameters
>> for each instance.
>>
>> Cc:  # 3.10+
>> Signed-off-by: Robert Baldyga 
> 
> why do you think this is stable material ? Looks like it's not
> fixing anything to me; just implementing a brand new requirement.

I will not insist on stable backporting of this patch, as it's actually
not very important fix (especially in case of sourcesink function).

Should I resend this patch without CC:stable?

Thanks,
Robert

> 
>> ---
>>  drivers/usb/gadget/function/f_sourcesink.c | 120 
>> +++--
>>  1 file changed, 62 insertions(+), 58 deletions(-)
>>
>> diff --git a/drivers/usb/gadget/function/f_sourcesink.c 
>> b/drivers/usb/gadget/function/f_sourcesink.c
>> index 1353465..128abfb 100644
>> --- a/drivers/usb/gadget/function/f_sourcesink.c
>> +++ b/drivers/usb/gadget/function/f_sourcesink.c
>> @@ -50,6 +50,13 @@ struct f_sourcesink {
>>  struct usb_ep   *iso_in_ep;
>>  struct usb_ep   *iso_out_ep;
>>  int cur_alt;
>> +
>> +unsigned pattern;
>> +unsigned isoc_interval;
>> +unsigned isoc_maxpacket;
>> +unsigned isoc_mult;
>> +unsigned isoc_maxburst;
>> +unsigned buflen;
>>  };
>>  
>>  static inline struct f_sourcesink *func_to_ss(struct usb_function *f)
>> @@ -57,13 +64,6 @@ static inline struct f_sourcesink *func_to_ss(struct 
>> usb_function *f)
>>  return container_of(f, struct f_sourcesink, function);
>>  }
>>  
>> -static unsigned pattern;
>> -static unsigned isoc_interval;
>> -static unsigned isoc_maxpacket;
>> -static unsigned isoc_mult;
>> -static unsigned isoc_maxburst;
>> -static unsigned buflen;
>> -
>>  
>> /*-*/
>>  
>>  static struct usb_interface_descriptor source_sink_intf_alt0 = {
>> @@ -298,7 +298,9 @@ static struct usb_gadget_strings *sourcesink_strings[] = 
>> {
>>  
>>  static inline struct usb_request *ss_alloc_ep_req(struct usb_ep *ep, int 
>> len)
>>  {
>> -return alloc_ep_req(ep, len, buflen);
>> +struct f_sourcesink *ss = ep->driver_data;
>> +
>> +return alloc_ep_req(ep, len, ss->buflen);
>>  }
>>  
>>  void free_ep_req(struct usb_ep *ep, struct usb_request *req)
>> @@ -357,22 +359,22 @@ autoconf_fail:
>>  goto autoconf_fail;
>>  
>>  /* sanity check the isoc module parameters */
>> -if (isoc_interval < 1)
>> -isoc_interval = 1;
>> -if (isoc_interval > 16)
>> -isoc_interval = 16;
>> -if (isoc_mult > 2)
>> -isoc_mult = 2;
>> -if (isoc_maxburst > 15)
>> -isoc_maxburst = 15;
>> +if (ss->isoc_interval < 1)
>> +ss->isoc_interval = 1;
>> +if (ss->isoc_interval > 16)
>> +ss->isoc_interval = 16;
>> +if (ss->isoc_mult > 2)
>> +ss->isoc_mult = 2;
>> +if (ss->isoc_maxburst > 15)
>> +ss->isoc_maxburst = 15;
>>  
>>  /* fill in the FS isoc descriptors from the module parameters */
>> -fs_iso_source_desc.wMaxPacketSize = isoc_maxpacket > 1023 ?
>> -1023 : isoc_maxpacket;
>> -fs_iso_source_desc.bInterval = isoc_interval;
>> -fs_iso_sink_desc.wMaxPacketSize = isoc_maxpacket > 1023 ?
>> -1023 : isoc_maxpacket;
>> -fs_iso_sink_desc.bInterval = isoc_interval;
>> +fs_iso_source_desc.wMaxPacketSize = ss->isoc_maxpacket > 1023 ?
>> +1023 : ss->isoc_maxpacket;
>> +fs_iso_source_desc.bInterval = ss->isoc_interval;
>> +fs_iso_sink_desc.wMaxPacketSize = ss->isoc_maxpacket > 1023 ?
>> +1023 : ss->isoc_maxpacket;
>> +fs_iso_sink_desc.bInterval = ss->isoc_interval;
>>  
>>  /* allocate iso endpoints */
>>  ss->iso_in_ep = usb_ep_autoconfig(cdev->gadget, _iso_source_desc);
>> @@ -394,8 +396,8 @@ no_iso:
>>  ss_source_sink_descs[SS_ALT_IFC_1_OFFSET] = NULL;
>>  }
>>  
>> -if (isoc_maxpacket > 1024)
>> -isoc_maxpacket = 1024;
>> +if (ss->isoc_maxpacket > 1024)
>> +ss->isoc_maxpacket = 1024;
>>  
>>  /* support high speed hardware */
>>  hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress;
>> @@ -406,15 +408,15 @@ no_iso:
>>   * We assume that the user knows what they are doing and won't
>>   * give parameters that their UDC doesn't support.
>>   */
>> -hs_iso_source_desc.wMaxPacketSize = isoc_maxpacket;
>> -hs_iso_source_desc.wMaxPacketSize |= isoc_mult << 11;
>> -hs_iso_source_desc.bInterval 

Re: [PATCH v2] usb: gadget: f_sourcesink: fix function params handling

2015-10-14 Thread Felipe Balbi

Hi,

Robert Baldyga  writes:
> Hi Felipe,
>
> On 09/24/2015 06:49 PM, Felipe Balbi wrote:
>> On Thu, Sep 24, 2015 at 05:23:09PM +0200, Robert Baldyga wrote:
>>> Move function parameters to struct f_sourcesink to make them per instance
>>> instead of having them as global variables. Since we can have multiple
>>> instances of USB function we also want to have separate set of parameters
>>> for each instance.
>>>
>>> Cc:  # 3.10+
>>> Signed-off-by: Robert Baldyga 
>> 
>> why do you think this is stable material ? Looks like it's not
>> fixing anything to me; just implementing a brand new requirement.
>
> I will not insist on stable backporting of this patch, as it's actually
> not very important fix (especially in case of sourcesink function).
>
> Should I resend this patch without CC:stable?

please, thank you.

-- 
balbi


signature.asc
Description: PGP signature


[PATCH v2] usb: gadget: f_sourcesink: fix function params handling

2015-09-24 Thread Robert Baldyga
Move function parameters to struct f_sourcesink to make them per instance
instead of having them as global variables. Since we can have multiple
instances of USB function we also want to have separate set of parameters
for each instance.

Cc:  # 3.10+
Signed-off-by: Robert Baldyga 
---
 drivers/usb/gadget/function/f_sourcesink.c | 120 +++--
 1 file changed, 62 insertions(+), 58 deletions(-)

diff --git a/drivers/usb/gadget/function/f_sourcesink.c 
b/drivers/usb/gadget/function/f_sourcesink.c
index 1353465..128abfb 100644
--- a/drivers/usb/gadget/function/f_sourcesink.c
+++ b/drivers/usb/gadget/function/f_sourcesink.c
@@ -50,6 +50,13 @@ struct f_sourcesink {
struct usb_ep   *iso_in_ep;
struct usb_ep   *iso_out_ep;
int cur_alt;
+
+   unsigned pattern;
+   unsigned isoc_interval;
+   unsigned isoc_maxpacket;
+   unsigned isoc_mult;
+   unsigned isoc_maxburst;
+   unsigned buflen;
 };
 
 static inline struct f_sourcesink *func_to_ss(struct usb_function *f)
@@ -57,13 +64,6 @@ static inline struct f_sourcesink *func_to_ss(struct 
usb_function *f)
return container_of(f, struct f_sourcesink, function);
 }
 
-static unsigned pattern;
-static unsigned isoc_interval;
-static unsigned isoc_maxpacket;
-static unsigned isoc_mult;
-static unsigned isoc_maxburst;
-static unsigned buflen;
-
 /*-*/
 
 static struct usb_interface_descriptor source_sink_intf_alt0 = {
@@ -298,7 +298,9 @@ static struct usb_gadget_strings *sourcesink_strings[] = {
 
 static inline struct usb_request *ss_alloc_ep_req(struct usb_ep *ep, int len)
 {
-   return alloc_ep_req(ep, len, buflen);
+   struct f_sourcesink *ss = ep->driver_data;
+
+   return alloc_ep_req(ep, len, ss->buflen);
 }
 
 void free_ep_req(struct usb_ep *ep, struct usb_request *req)
@@ -357,22 +359,22 @@ autoconf_fail:
goto autoconf_fail;
 
/* sanity check the isoc module parameters */
-   if (isoc_interval < 1)
-   isoc_interval = 1;
-   if (isoc_interval > 16)
-   isoc_interval = 16;
-   if (isoc_mult > 2)
-   isoc_mult = 2;
-   if (isoc_maxburst > 15)
-   isoc_maxburst = 15;
+   if (ss->isoc_interval < 1)
+   ss->isoc_interval = 1;
+   if (ss->isoc_interval > 16)
+   ss->isoc_interval = 16;
+   if (ss->isoc_mult > 2)
+   ss->isoc_mult = 2;
+   if (ss->isoc_maxburst > 15)
+   ss->isoc_maxburst = 15;
 
/* fill in the FS isoc descriptors from the module parameters */
-   fs_iso_source_desc.wMaxPacketSize = isoc_maxpacket > 1023 ?
-   1023 : isoc_maxpacket;
-   fs_iso_source_desc.bInterval = isoc_interval;
-   fs_iso_sink_desc.wMaxPacketSize = isoc_maxpacket > 1023 ?
-   1023 : isoc_maxpacket;
-   fs_iso_sink_desc.bInterval = isoc_interval;
+   fs_iso_source_desc.wMaxPacketSize = ss->isoc_maxpacket > 1023 ?
+   1023 : ss->isoc_maxpacket;
+   fs_iso_source_desc.bInterval = ss->isoc_interval;
+   fs_iso_sink_desc.wMaxPacketSize = ss->isoc_maxpacket > 1023 ?
+   1023 : ss->isoc_maxpacket;
+   fs_iso_sink_desc.bInterval = ss->isoc_interval;
 
/* allocate iso endpoints */
ss->iso_in_ep = usb_ep_autoconfig(cdev->gadget, _iso_source_desc);
@@ -394,8 +396,8 @@ no_iso:
ss_source_sink_descs[SS_ALT_IFC_1_OFFSET] = NULL;
}
 
-   if (isoc_maxpacket > 1024)
-   isoc_maxpacket = 1024;
+   if (ss->isoc_maxpacket > 1024)
+   ss->isoc_maxpacket = 1024;
 
/* support high speed hardware */
hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress;
@@ -406,15 +408,15 @@ no_iso:
 * We assume that the user knows what they are doing and won't
 * give parameters that their UDC doesn't support.
 */
-   hs_iso_source_desc.wMaxPacketSize = isoc_maxpacket;
-   hs_iso_source_desc.wMaxPacketSize |= isoc_mult << 11;
-   hs_iso_source_desc.bInterval = isoc_interval;
+   hs_iso_source_desc.wMaxPacketSize = ss->isoc_maxpacket;
+   hs_iso_source_desc.wMaxPacketSize |= ss->isoc_mult << 11;
+   hs_iso_source_desc.bInterval = ss->isoc_interval;
hs_iso_source_desc.bEndpointAddress =
fs_iso_source_desc.bEndpointAddress;
 
-   hs_iso_sink_desc.wMaxPacketSize = isoc_maxpacket;
-   hs_iso_sink_desc.wMaxPacketSize |= isoc_mult << 11;
-   hs_iso_sink_desc.bInterval = isoc_interval;
+   hs_iso_sink_desc.wMaxPacketSize = ss->isoc_maxpacket;
+   hs_iso_sink_desc.wMaxPacketSize |= ss->isoc_mult << 11;
+   

Re: [PATCH v2] usb: gadget: f_sourcesink: fix function params handling

2015-09-24 Thread Krzysztof Opasiak



On 09/24/2015 06:49 PM, Felipe Balbi wrote:

On Thu, Sep 24, 2015 at 05:23:09PM +0200, Robert Baldyga wrote:

Move function parameters to struct f_sourcesink to make them per instance
instead of having them as global variables. Since we can have multiple
instances of USB function we also want to have separate set of parameters
for each instance.

Cc:  # 3.10+
Signed-off-by: Robert Baldyga 


why do you think this is stable material ? Looks like it's not
fixing anything to me; just implementing a brand new requirement.



Please see my answer in loopback patch[1]. It's totally the same case. 
Both those functions have the same bug.


Footnotes:
1 - http://marc.info/?l=linux-usb=144311466118170=2
--
Krzysztof Opasiak
Samsung R Institute Poland
Samsung Electronics
--
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


Re: [PATCH v2] usb: gadget: f_sourcesink: fix function params handling

2015-09-24 Thread Felipe Balbi
On Thu, Sep 24, 2015 at 05:23:09PM +0200, Robert Baldyga wrote:
> Move function parameters to struct f_sourcesink to make them per instance
> instead of having them as global variables. Since we can have multiple
> instances of USB function we also want to have separate set of parameters
> for each instance.
> 
> Cc:  # 3.10+
> Signed-off-by: Robert Baldyga 

why do you think this is stable material ? Looks like it's not
fixing anything to me; just implementing a brand new requirement.

> ---
>  drivers/usb/gadget/function/f_sourcesink.c | 120 
> +++--
>  1 file changed, 62 insertions(+), 58 deletions(-)
> 
> diff --git a/drivers/usb/gadget/function/f_sourcesink.c 
> b/drivers/usb/gadget/function/f_sourcesink.c
> index 1353465..128abfb 100644
> --- a/drivers/usb/gadget/function/f_sourcesink.c
> +++ b/drivers/usb/gadget/function/f_sourcesink.c
> @@ -50,6 +50,13 @@ struct f_sourcesink {
>   struct usb_ep   *iso_in_ep;
>   struct usb_ep   *iso_out_ep;
>   int cur_alt;
> +
> + unsigned pattern;
> + unsigned isoc_interval;
> + unsigned isoc_maxpacket;
> + unsigned isoc_mult;
> + unsigned isoc_maxburst;
> + unsigned buflen;
>  };
>  
>  static inline struct f_sourcesink *func_to_ss(struct usb_function *f)
> @@ -57,13 +64,6 @@ static inline struct f_sourcesink *func_to_ss(struct 
> usb_function *f)
>   return container_of(f, struct f_sourcesink, function);
>  }
>  
> -static unsigned pattern;
> -static unsigned isoc_interval;
> -static unsigned isoc_maxpacket;
> -static unsigned isoc_mult;
> -static unsigned isoc_maxburst;
> -static unsigned buflen;
> -
>  /*-*/
>  
>  static struct usb_interface_descriptor source_sink_intf_alt0 = {
> @@ -298,7 +298,9 @@ static struct usb_gadget_strings *sourcesink_strings[] = {
>  
>  static inline struct usb_request *ss_alloc_ep_req(struct usb_ep *ep, int len)
>  {
> - return alloc_ep_req(ep, len, buflen);
> + struct f_sourcesink *ss = ep->driver_data;
> +
> + return alloc_ep_req(ep, len, ss->buflen);
>  }
>  
>  void free_ep_req(struct usb_ep *ep, struct usb_request *req)
> @@ -357,22 +359,22 @@ autoconf_fail:
>   goto autoconf_fail;
>  
>   /* sanity check the isoc module parameters */
> - if (isoc_interval < 1)
> - isoc_interval = 1;
> - if (isoc_interval > 16)
> - isoc_interval = 16;
> - if (isoc_mult > 2)
> - isoc_mult = 2;
> - if (isoc_maxburst > 15)
> - isoc_maxburst = 15;
> + if (ss->isoc_interval < 1)
> + ss->isoc_interval = 1;
> + if (ss->isoc_interval > 16)
> + ss->isoc_interval = 16;
> + if (ss->isoc_mult > 2)
> + ss->isoc_mult = 2;
> + if (ss->isoc_maxburst > 15)
> + ss->isoc_maxburst = 15;
>  
>   /* fill in the FS isoc descriptors from the module parameters */
> - fs_iso_source_desc.wMaxPacketSize = isoc_maxpacket > 1023 ?
> - 1023 : isoc_maxpacket;
> - fs_iso_source_desc.bInterval = isoc_interval;
> - fs_iso_sink_desc.wMaxPacketSize = isoc_maxpacket > 1023 ?
> - 1023 : isoc_maxpacket;
> - fs_iso_sink_desc.bInterval = isoc_interval;
> + fs_iso_source_desc.wMaxPacketSize = ss->isoc_maxpacket > 1023 ?
> + 1023 : ss->isoc_maxpacket;
> + fs_iso_source_desc.bInterval = ss->isoc_interval;
> + fs_iso_sink_desc.wMaxPacketSize = ss->isoc_maxpacket > 1023 ?
> + 1023 : ss->isoc_maxpacket;
> + fs_iso_sink_desc.bInterval = ss->isoc_interval;
>  
>   /* allocate iso endpoints */
>   ss->iso_in_ep = usb_ep_autoconfig(cdev->gadget, _iso_source_desc);
> @@ -394,8 +396,8 @@ no_iso:
>   ss_source_sink_descs[SS_ALT_IFC_1_OFFSET] = NULL;
>   }
>  
> - if (isoc_maxpacket > 1024)
> - isoc_maxpacket = 1024;
> + if (ss->isoc_maxpacket > 1024)
> + ss->isoc_maxpacket = 1024;
>  
>   /* support high speed hardware */
>   hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress;
> @@ -406,15 +408,15 @@ no_iso:
>* We assume that the user knows what they are doing and won't
>* give parameters that their UDC doesn't support.
>*/
> - hs_iso_source_desc.wMaxPacketSize = isoc_maxpacket;
> - hs_iso_source_desc.wMaxPacketSize |= isoc_mult << 11;
> - hs_iso_source_desc.bInterval = isoc_interval;
> + hs_iso_source_desc.wMaxPacketSize = ss->isoc_maxpacket;
> + hs_iso_source_desc.wMaxPacketSize |= ss->isoc_mult << 11;
> + hs_iso_source_desc.bInterval = ss->isoc_interval;
>   hs_iso_source_desc.bEndpointAddress =
>   fs_iso_source_desc.bEndpointAddress;
>  
> -