Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1585810 > unrolled thread
| Started by | "Gustavo A. R. Silva" <garsilva@embeddedor.com> |
|---|---|
| First post | 2017-02-22 00:40 +0100 |
| Last post | 2017-02-22 06:30 +0100 |
| Articles | 4 — 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.
[PATCH] usb: misc: add a missing continue and refactor code "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-02-22 00:40 +0100
Re: [PATCH] usb: misc: add a missing continue and refactor code Alan Stern <stern@rowland.harvard.edu> - 2017-02-22 02:50 +0100
Re: [PATCH] usb: misc: add a missing continue and refactor code "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-02-22 03:50 +0100
Re: [PATCH] usb: misc: add a missing continue and refactor code "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-02-22 06:30 +0100
| From | "Gustavo A. R. Silva" <garsilva@embeddedor.com> |
|---|---|
| Date | 2017-02-22 00:40 +0100 |
| Subject | [PATCH] usb: misc: add a missing continue and refactor code |
| Message-ID | <tdsch-18h-7@gated-at.bofh.it> |
Code refactoring to make the flow easier to follow and add missing
'continue' for case USB_ENDPOINT_XFER_INT.
Addresses-Coverity-ID: 1248733
Cc: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
---
drivers/usb/misc/usbtest.c | 50 +++++++++++++++++++++++++++-------------------
1 file changed, 30 insertions(+), 20 deletions(-)
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index 3525626..8723e33 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -124,6 +124,32 @@ static struct usb_device *testdev_to_usbdev(struct usbtest_dev *test)
/*-------------------------------------------------------------------------*/
+static inline void try_intr(struct usb_host_endpoint *e,
+ struct usb_host_endpoint *int_in,
+ struct usb_host_endpoint *int_out)
+{
+ if (usb_endpoint_dir_in(&e->desc)) {
+ if (!int_in)
+ int_in = e;
+ } else {
+ if (!int_out)
+ int_out = e;
+ }
+}
+
+static inline void try_iso(struct usb_host_endpoint *e,
+ struct usb_host_endpoint *iso_in,
+ struct usb_host_endpoint *iso_out)
+{
+ if (usb_endpoint_dir_in(&e->desc)) {
+ if (!iso_in)
+ iso_in = e;
+ } else {
+ if (!iso_out)
+ iso_out = e;
+ }
+}
+
static int
get_endpoints(struct usbtest_dev *dev, struct usb_interface *intf)
{
@@ -158,11 +184,12 @@ get_endpoints(struct usbtest_dev *dev, struct usb_interface *intf)
break;
case USB_ENDPOINT_XFER_INT:
if (dev->info->intr)
- goto try_intr;
+ try_intr(e, int_in, int_out);
+ continue;
case USB_ENDPOINT_XFER_ISOC:
if (dev->info->iso)
- goto try_iso;
- /* FALLTHROUGH */
+ try_iso(e, iso_in, iso_out);
+ /* fall through */
default:
continue;
}
@@ -174,23 +201,6 @@ get_endpoints(struct usbtest_dev *dev, struct usb_interface *intf)
out = e;
}
continue;
-try_intr:
- if (usb_endpoint_dir_in(&e->desc)) {
- if (!int_in)
- int_in = e;
- } else {
- if (!int_out)
- int_out = e;
- }
- continue;
-try_iso:
- if (usb_endpoint_dir_in(&e->desc)) {
- if (!iso_in)
- iso_in = e;
- } else {
- if (!iso_out)
- iso_out = e;
- }
}
if ((in && out) || iso_in || iso_out || int_in || int_out)
goto found;
--
2.5.0
[toc] | [next] | [standalone]
| From | Alan Stern <stern@rowland.harvard.edu> |
|---|---|
| Date | 2017-02-22 02:50 +0100 |
| Message-ID | <tdue5-2or-1@gated-at.bofh.it> |
| In reply to | #1585810 |
On Tue, 21 Feb 2017, Gustavo A. R. Silva wrote:
> Code refactoring to make the flow easier to follow and add missing
> 'continue' for case USB_ENDPOINT_XFER_INT.
>
> Addresses-Coverity-ID: 1248733
> Cc: Alan Stern <stern@rowland.harvard.edu>
> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
> ---
> drivers/usb/misc/usbtest.c | 50 +++++++++++++++++++++++++++-------------------
> 1 file changed, 30 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
> index 3525626..8723e33 100644
> --- a/drivers/usb/misc/usbtest.c
> +++ b/drivers/usb/misc/usbtest.c
> @@ -124,6 +124,32 @@ static struct usb_device *testdev_to_usbdev(struct usbtest_dev *test)
>
> /*-------------------------------------------------------------------------*/
>
> +static inline void try_intr(struct usb_host_endpoint *e,
> + struct usb_host_endpoint *int_in,
> + struct usb_host_endpoint *int_out)
> +{
> + if (usb_endpoint_dir_in(&e->desc)) {
> + if (!int_in)
> + int_in = e;
> + } else {
> + if (!int_out)
> + int_out = e;
> + }
> +}
> +
> +static inline void try_iso(struct usb_host_endpoint *e,
> + struct usb_host_endpoint *iso_in,
> + struct usb_host_endpoint *iso_out)
> +{
> + if (usb_endpoint_dir_in(&e->desc)) {
> + if (!iso_in)
> + iso_in = e;
> + } else {
> + if (!iso_out)
> + iso_out = e;
> + }
> +}
> +
This is not at all what I had in mind. First, it's incorrect (can you
see why?). Second, by "inline" I meant moving the code to be actually
in-line next to the conditional, not some place else in a separate
subroutine (even if the subroutine is declared inline).
Also, the code for the USB_ENDPOINT_XFER_BULK case should look like the
other two.
Alan Stern
[toc] | [prev] | [next] | [standalone]
| From | "Gustavo A. R. Silva" <garsilva@embeddedor.com> |
|---|---|
| Date | 2017-02-22 03:50 +0100 |
| Message-ID | <tdvaa-37s-7@gated-at.bofh.it> |
| In reply to | #1585856 |
Hi Alan,
Quoting Alan Stern <stern@rowland.harvard.edu>:
> On Tue, 21 Feb 2017, Gustavo A. R. Silva wrote:
>
>> Code refactoring to make the flow easier to follow and add missing
>> 'continue' for case USB_ENDPOINT_XFER_INT.
>>
>> Addresses-Coverity-ID: 1248733
>> Cc: Alan Stern <stern@rowland.harvard.edu>
>> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
>> ---
>> drivers/usb/misc/usbtest.c | 50
>> +++++++++++++++++++++++++++-------------------
>> 1 file changed, 30 insertions(+), 20 deletions(-)
>>
>> diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
>> index 3525626..8723e33 100644
>> --- a/drivers/usb/misc/usbtest.c
>> +++ b/drivers/usb/misc/usbtest.c
>> @@ -124,6 +124,32 @@ static struct usb_device
>> *testdev_to_usbdev(struct usbtest_dev *test)
>>
>>
>> /*-------------------------------------------------------------------------*/
>>
>> +static inline void try_intr(struct usb_host_endpoint *e,
>> + struct usb_host_endpoint *int_in,
>> + struct usb_host_endpoint *int_out)
>> +{
>> + if (usb_endpoint_dir_in(&e->desc)) {
>> + if (!int_in)
>> + int_in = e;
>> + } else {
>> + if (!int_out)
>> + int_out = e;
>> + }
>> +}
>> +
>> +static inline void try_iso(struct usb_host_endpoint *e,
>> + struct usb_host_endpoint *iso_in,
>> + struct usb_host_endpoint *iso_out)
>> +{
>> + if (usb_endpoint_dir_in(&e->desc)) {
>> + if (!iso_in)
>> + iso_in = e;
>> + } else {
>> + if (!iso_out)
>> + iso_out = e;
>> + }
>> +}
>> +
>
> This is not at all what I had in mind. First, it's incorrect (can you
> see why?). Second, by "inline" I meant moving the code to be actually
> in-line next to the conditional, not some place else in a separate
> subroutine (even if the subroutine is declared inline).
>
Interesting... let me double check.
I thought it would've been better to have separate inline subroutines
for those "goto".
> Also, the code for the USB_ENDPOINT_XFER_BULK case should look like the
> other two.
>
Do you mean a 'continue' instead of the 'break'?
Thanks for you comments.
--
Gustavo A. R. Silva
[toc] | [prev] | [next] | [standalone]
| From | "Gustavo A. R. Silva" <garsilva@embeddedor.com> |
|---|---|
| Date | 2017-02-22 06:30 +0100 |
| Message-ID | <tdxEZ-551-7@gated-at.bofh.it> |
| In reply to | #1585894 |
Quoting "Gustavo A. R. Silva" <garsilva@embeddedor.com>:
> Hi Alan,
>
> Quoting Alan Stern <stern@rowland.harvard.edu>:
>
>> On Tue, 21 Feb 2017, Gustavo A. R. Silva wrote:
>>
>>> Code refactoring to make the flow easier to follow and add missing
>>> 'continue' for case USB_ENDPOINT_XFER_INT.
>>>
>>> Addresses-Coverity-ID: 1248733
>>> Cc: Alan Stern <stern@rowland.harvard.edu>
>>> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
>>> ---
>>> drivers/usb/misc/usbtest.c | 50
>>> +++++++++++++++++++++++++++-------------------
>>> 1 file changed, 30 insertions(+), 20 deletions(-)
>>>
>>> diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
>>> index 3525626..8723e33 100644
>>> --- a/drivers/usb/misc/usbtest.c
>>> +++ b/drivers/usb/misc/usbtest.c
>>> @@ -124,6 +124,32 @@ static struct usb_device
>>> *testdev_to_usbdev(struct usbtest_dev *test)
>>>
>>> /*-------------------------------------------------------------------------*/
>>>
>>> +static inline void try_intr(struct usb_host_endpoint *e,
>>> + struct usb_host_endpoint *int_in,
>>> + struct usb_host_endpoint *int_out)
>>> +{
>>> + if (usb_endpoint_dir_in(&e->desc)) {
>>> + if (!int_in)
>>> + int_in = e;
>>> + } else {
>>> + if (!int_out)
>>> + int_out = e;
>>> + }
>>> +}
>>> +
>>> +static inline void try_iso(struct usb_host_endpoint *e,
>>> + struct usb_host_endpoint *iso_in,
>>> + struct usb_host_endpoint *iso_out)
>>> +{
>>> + if (usb_endpoint_dir_in(&e->desc)) {
>>> + if (!iso_in)
>>> + iso_in = e;
>>> + } else {
>>> + if (!iso_out)
>>> + iso_out = e;
>>> + }
>>> +}
>>> +
>>
>> This is not at all what I had in mind. First, it's incorrect (can you
>> see why?). Second, by "inline" I meant moving the code to be actually
>> in-line next to the conditional, not some place else in a separate
>> subroutine (even if the subroutine is declared inline).
>>
>
> Interesting... let me double check.
>
> I thought it would've been better to have separate inline
> subroutines for those "goto".
>
>> Also, the code for the USB_ENDPOINT_XFER_BULK case should look like the
>> other two.
>>
>
> Do you mean a 'continue' instead of the 'break'?
>
Oh I see, the following piece of code should be part of the
USB_ENDPOINT_XFER_BULK case:
if (usb_endpoint_dir_in(&e->desc)) {
if (!in)
in = e;
} else {
if (!out)
out = e;
}
continue;
--
Gustavo A. R. Silva
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web