Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1225200 > unrolled thread

[PATCH 05/26] usb: gadget: f_ecm: eliminate abuse of ep->driver data

Started byRobert Baldyga <r.baldyga@samsung.com>
First post2015-09-15 16:30 +0200
Last post2015-09-16 11:50 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 05/26] usb: gadget: f_ecm: eliminate abuse of ep->driver data Robert Baldyga <r.baldyga@samsung.com> - 2015-09-15 16:30 +0200
    Re: [PATCH 05/26] usb: gadget: f_ecm: eliminate abuse of ep->driver  data Krzysztof Opasiak <k.opasiak@samsung.com> - 2015-09-15 17:50 +0200
      Re: [PATCH 05/26] usb: gadget: f_ecm: eliminate abuse of ep->driver  data Robert Baldyga <r.baldyga@samsung.com> - 2015-09-16 11:50 +0200

#1225200 — [PATCH 05/26] usb: gadget: f_ecm: eliminate abuse of ep->driver data

FromRobert Baldyga <r.baldyga@samsung.com>
Date2015-09-15 16:30 +0200
Subject[PATCH 05/26] usb: gadget: f_ecm: eliminate abuse of ep->driver data
Message-ID<q8Zpb-7qt-83@gated-at.bofh.it>
Since ep->driver_data is not used for endpoint claiming, neither for
enabled/disabled state storing, we can reduce number of places where
we read or modify it's value, as now it has no particular meaning for
function or framework logic.

In case of f_ecm, ep->driver_data was used only for endpoint claiming
and marking endpoints as enabled, so we can simplify code by reducing
it.

Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
---
 drivers/usb/gadget/function/f_ecm.c | 31 +++++++------------------------
 1 file changed, 7 insertions(+), 24 deletions(-)

diff --git a/drivers/usb/gadget/function/f_ecm.c b/drivers/usb/gadget/function/f_ecm.c
index 7b7424f..4abca70 100644
--- a/drivers/usb/gadget/function/f_ecm.c
+++ b/drivers/usb/gadget/function/f_ecm.c
@@ -541,24 +541,21 @@ static int ecm_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
 		if (alt != 0)
 			goto fail;
 
-		if (ecm->notify->driver_data) {
-			VDBG(cdev, "reset ecm control %d\n", intf);
-			usb_ep_disable(ecm->notify);
-		}
+		VDBG(cdev, "reset ecm control %d\n", intf);
+		usb_ep_disable(ecm->notify);
 		if (!(ecm->notify->desc)) {
 			VDBG(cdev, "init ecm ctrl %d\n", intf);
 			if (config_ep_by_speed(cdev->gadget, f, ecm->notify))
 				goto fail;
 		}
 		usb_ep_enable(ecm->notify);
-		ecm->notify->driver_data = ecm;
 
 	/* Data interface has two altsettings, 0 and 1 */
 	} else if (intf == ecm->data_id) {
 		if (alt > 1)
 			goto fail;
 
-		if (ecm->port.in_ep->driver_data) {
+		if (ecm->port.in_ep->enabled) {
 			DBG(cdev, "reset ecm\n");
 			gether_disconnect(&ecm->port);
 		}
@@ -618,7 +615,7 @@ static int ecm_get_alt(struct usb_function *f, unsigned intf)
 
 	if (intf == ecm->ctrl_id)
 		return 0;
-	return ecm->port.in_ep->driver_data ? 1 : 0;
+	return ecm->port.in_ep->enabled ? 1 : 0;
 }
 
 static void ecm_disable(struct usb_function *f)
@@ -628,14 +625,11 @@ static void ecm_disable(struct usb_function *f)
 
 	DBG(cdev, "ecm deactivated\n");
 
-	if (ecm->port.in_ep->driver_data)
+	if (ecm->port.in_ep->enabled)
 		gether_disconnect(&ecm->port);
 
-	if (ecm->notify->driver_data) {
-		usb_ep_disable(ecm->notify);
-		ecm->notify->driver_data = NULL;
-		ecm->notify->desc = NULL;
-	}
+	usb_ep_disable(ecm->notify);
+	ecm->notify->desc = NULL;
 }
 
 /*-------------------------------------------------------------------------*/
@@ -750,13 +744,11 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f)
 	if (!ep)
 		goto fail;
 	ecm->port.in_ep = ep;
-	ep->driver_data = cdev;	/* claim */
 
 	ep = usb_ep_autoconfig(cdev->gadget, &fs_ecm_out_desc);
 	if (!ep)
 		goto fail;
 	ecm->port.out_ep = ep;
-	ep->driver_data = cdev;	/* claim */
 
 	/* NOTE:  a status/notification endpoint is *OPTIONAL* but we
 	 * don't treat it that way.  It's simpler, and some newer CDC
@@ -766,7 +758,6 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f)
 	if (!ep)
 		goto fail;
 	ecm->notify = ep;
-	ep->driver_data = cdev;	/* claim */
 
 	status = -ENOMEM;
 
@@ -820,14 +811,6 @@ fail:
 		usb_ep_free_request(ecm->notify, ecm->notify_req);
 	}
 
-	/* we might as well release our claims on endpoints */
-	if (ecm->notify)
-		ecm->notify->driver_data = NULL;
-	if (ecm->port.out_ep)
-		ecm->port.out_ep->driver_data = NULL;
-	if (ecm->port.in_ep)
-		ecm->port.in_ep->driver_data = NULL;
-
 	ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
 
 	return status;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1225336 — Re: [PATCH 05/26] usb: gadget: f_ecm: eliminate abuse of ep->driver data

FromKrzysztof Opasiak <k.opasiak@samsung.com>
Date2015-09-15 17:50 +0200
SubjectRe: [PATCH 05/26] usb: gadget: f_ecm: eliminate abuse of ep->driver data
Message-ID<q90Ey-Jd-11@gated-at.bofh.it>
In reply to#1225200

On 09/15/2015 04:26 PM, Robert Baldyga wrote:
> Since ep->driver_data is not used for endpoint claiming, neither for
> enabled/disabled state storing, we can reduce number of places where
> we read or modify it's value, as now it has no particular meaning for
> function or framework logic.
>
> In case of f_ecm, ep->driver_data was used only for endpoint claiming
> and marking endpoints as enabled, so we can simplify code by reducing
> it.
>
> Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>

( ... )

>
> @@ -820,14 +811,6 @@ fail:
>   		usb_ep_free_request(ecm->notify, ecm->notify_req);
>   	}
>
> -	/* we might as well release our claims on endpoints */
> -	if (ecm->notify)
> -		ecm->notify->driver_data = NULL;
> -	if (ecm->port.out_ep)
> -		ecm->port.out_ep->driver_data = NULL;
> -	if (ecm->port.in_ep)
> -		ecm->port.in_ep->driver_data = NULL;
> -
>   	ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
>
>   	return status;
>

You have done this in almost all functions but personally I'm really 
concern about this change.

By convention function should free all allocated resources when exiting 
with non 0 code. Endpoints are some kind of resources, they are 
"allocated" using usb_ep_autoconfig() and if you are not going to use 
them because error occurred you should free the using 
usb_ep_autoconfig_release(). Moreover, you have done this in source sink 
function so why not do this in all other?


Best regards,
-- 
Krzysztof Opasiak
Samsung R&D Institute Poland
Samsung Electronics
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1225901 — Re: [PATCH 05/26] usb: gadget: f_ecm: eliminate abuse of ep->driver data

FromRobert Baldyga <r.baldyga@samsung.com>
Date2015-09-16 11:50 +0200
SubjectRe: [PATCH 05/26] usb: gadget: f_ecm: eliminate abuse of ep->driver data
Message-ID<q9hvI-G1-13@gated-at.bofh.it>
In reply to#1225336
On 09/15/2015 05:45 PM, Krzysztof Opasiak wrote:
> 
> 
> On 09/15/2015 04:26 PM, Robert Baldyga wrote:
>> Since ep->driver_data is not used for endpoint claiming, neither for
>> enabled/disabled state storing, we can reduce number of places where
>> we read or modify it's value, as now it has no particular meaning for
>> function or framework logic.
>>
>> In case of f_ecm, ep->driver_data was used only for endpoint claiming
>> and marking endpoints as enabled, so we can simplify code by reducing
>> it.
>>
>> Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
> 
> ( ... )
> 
>>
>> @@ -820,14 +811,6 @@ fail:
>>   		usb_ep_free_request(ecm->notify, ecm->notify_req);
>>   	}
>>
>> -	/* we might as well release our claims on endpoints */
>> -	if (ecm->notify)
>> -		ecm->notify->driver_data = NULL;
>> -	if (ecm->port.out_ep)
>> -		ecm->port.out_ep->driver_data = NULL;
>> -	if (ecm->port.in_ep)
>> -		ecm->port.in_ep->driver_data = NULL;
>> -
>>   	ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
>>
>>   	return status;
>>
> 
> You have done this in almost all functions but personally I'm really 
> concern about this change.
> 
> By convention function should free all allocated resources when exiting 
> with non 0 code. Endpoints are some kind of resources, they are 
> "allocated" using usb_ep_autoconfig() and if you are not going to use 
> them because error occurred you should free the using 
> usb_ep_autoconfig_release(). Moreover, you have done this in source sink 
> function so why not do this in all other?


Well, if bind() returns an error code, composite calls
usb_ep_autoconfig_reset() anyway, so manual endpoint releasing in error
path isn't necessary. We can compare the way it works with devm_*
functions family - you don't need to care about resource lifetime as
it's managed for you.

The function f_sourcesink is a bit different, because it can work with
two different endpoint configurations {bulk-in, bulk-out} or {bulk-in,
bulk-out, iso-in, iso-out}. When bulk endpoints are obtained
successfully it tries to get iso endpoints, but if one if them is not
available it releases previously obtained iso and ends with success. In
such case it simply starts in bulk-only configuration.

Best regards,
Robert
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web