All of lore.kernel.org
 help / color / mirror / Atom feed
* [2/2] usb: dwc3: debug: purge usage of strcat
@ 2019-02-06  6:31 Felipe Balbi
  0 siblings, 0 replies; 4+ messages in thread
From: Felipe Balbi @ 2019-02-06  6:31 UTC (permalink / raw)
  To: Jack Pham; +Cc: Linux USB

Felipe Balbi <felipe.balbi@linux.intel.com> writes:

> Hi,
>
> Jack Pham <jackp@codeaurora.org> writes:
>> On Tue, Feb 05, 2019 at 01:11:18PM +0200, Felipe Balbi wrote:
>>> Now that buffer size is always passed around, we don't need to rely on
>>> strcat anymore.
>>> 
>>> Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
>>> ---
>>>  drivers/usb/dwc3/debug.h | 14 +++++++++-----
>>>  1 file changed, 9 insertions(+), 5 deletions(-)
>>> 
>>> diff --git a/drivers/usb/dwc3/debug.h b/drivers/usb/dwc3/debug.h
>>> index e925a6b73005..6759a7efd8d5 100644
>>> --- a/drivers/usb/dwc3/debug.h
>>> +++ b/drivers/usb/dwc3/debug.h
>>> @@ -545,21 +545,25 @@ static inline const char *dwc3_ep_event_string(char *str, size_t size,
>>>  				status & DEPEVT_STATUS_TRANSFER_ACTIVE ?
>>>  				" (Active)" : " (Not Active)");
>>>  
>>> +		len = strlen(str);
>>> +
>>
>> I don't see 'len' used after this. Did you mean to s/ret/len/ in the
>> snprintf() calls below?
>>
>> Alternatively couldn't you just use 'ret' as an accumulator each time
>> snprintf() is called to keep count of the bytes written to the buffer
>> instead of needing to call strlen() [O(n) each time] multiple times?
>
> yeah, this is leftover. Just forgot to remove it.

Just to be clear, removed on a separate patch :-)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [2/2] usb: dwc3: debug: purge usage of strcat
@ 2019-02-06  6:29 Felipe Balbi
  0 siblings, 0 replies; 4+ messages in thread
From: Felipe Balbi @ 2019-02-06  6:29 UTC (permalink / raw)
  To: Jack Pham; +Cc: Linux USB

Hi,

Jack Pham <jackp@codeaurora.org> writes:
> On Tue, Feb 05, 2019 at 01:11:18PM +0200, Felipe Balbi wrote:
>> Now that buffer size is always passed around, we don't need to rely on
>> strcat anymore.
>> 
>> Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
>> ---
>>  drivers/usb/dwc3/debug.h | 14 +++++++++-----
>>  1 file changed, 9 insertions(+), 5 deletions(-)
>> 
>> diff --git a/drivers/usb/dwc3/debug.h b/drivers/usb/dwc3/debug.h
>> index e925a6b73005..6759a7efd8d5 100644
>> --- a/drivers/usb/dwc3/debug.h
>> +++ b/drivers/usb/dwc3/debug.h
>> @@ -545,21 +545,25 @@ static inline const char *dwc3_ep_event_string(char *str, size_t size,
>>  				status & DEPEVT_STATUS_TRANSFER_ACTIVE ?
>>  				" (Active)" : " (Not Active)");
>>  
>> +		len = strlen(str);
>> +
>
> I don't see 'len' used after this. Did you mean to s/ret/len/ in the
> snprintf() calls below?
>
> Alternatively couldn't you just use 'ret' as an accumulator each time
> snprintf() is called to keep count of the bytes written to the buffer
> instead of needing to call strlen() [O(n) each time] multiple times?

yeah, this is leftover. Just forgot to remove it.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [2/2] usb: dwc3: debug: purge usage of strcat
@ 2019-02-05 22:42 Jack Pham
  0 siblings, 0 replies; 4+ messages in thread
From: Jack Pham @ 2019-02-05 22:42 UTC (permalink / raw)
  To: Felipe Balbi; +Cc: Linux USB

Hi Felipe,

On Tue, Feb 05, 2019 at 01:11:18PM +0200, Felipe Balbi wrote:
> Now that buffer size is always passed around, we don't need to rely on
> strcat anymore.
> 
> Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
> ---
>  drivers/usb/dwc3/debug.h | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/debug.h b/drivers/usb/dwc3/debug.h
> index e925a6b73005..6759a7efd8d5 100644
> --- a/drivers/usb/dwc3/debug.h
> +++ b/drivers/usb/dwc3/debug.h
> @@ -545,21 +545,25 @@ static inline const char *dwc3_ep_event_string(char *str, size_t size,
>  				status & DEPEVT_STATUS_TRANSFER_ACTIVE ?
>  				" (Active)" : " (Not Active)");
>  
> +		len = strlen(str);
> +

I don't see 'len' used after this. Did you mean to s/ret/len/ in the
snprintf() calls below?

Alternatively couldn't you just use 'ret' as an accumulator each time
snprintf() is called to keep count of the bytes written to the buffer
instead of needing to call strlen() [O(n) each time] multiple times?

Thanks,
Jack

>  		/* Control Endpoints */
>  		if (epnum <= 1) {
>  			int phase = DEPEVT_STATUS_CONTROL_PHASE(event->status);
>  
>  			switch (phase) {
>  			case DEPEVT_STATUS_CONTROL_DATA:
> -				strcat(str, " [Data Phase]");
> +				snprintf(str + ret, size - ret,
> +						" [Data Phase]");
>  				break;
>  			case DEPEVT_STATUS_CONTROL_STATUS:
> -				strcat(str, " [Status Phase]");
> +				snprintf(str + ret, size - ret,
> +						" [Status Phase]");
>  			}
>  		}
>  		break;
>  	case DWC3_DEPEVT_RXTXFIFOEVT:
> -		strcat(str, "FIFO");
> +		snprintf(str + ret, size - ret, "FIFO");
>  		break;
>  	case DWC3_DEPEVT_STREAMEVT:
>  		status = event->status;
> @@ -571,13 +575,13 @@ static inline const char *dwc3_ep_event_string(char *str, size_t size,
>  			break;
>  		case DEPEVT_STREAMEVT_NOTFOUND:
>  		default:
> -			strcat(str, " Stream Not Found");
> +			snprintf(str + ret, size - ret, " Stream Not Found");
>  			break;
>  		}
>  
>  		break;
>  	case DWC3_DEPEVT_EPCMDCMPLT:
> -		strcat(str, "Endpoint Command Complete");
> +		snprintf(str + ret, size - ret, "Endpoint Command Complete");
>  		break;
>  	default:
>  		snprintf(str, size, "UNKNOWN");

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [2/2] usb: dwc3: debug: purge usage of strcat
@ 2019-02-05 11:11 Felipe Balbi
  0 siblings, 0 replies; 4+ messages in thread
From: Felipe Balbi @ 2019-02-05 11:11 UTC (permalink / raw)
  To: Linux USB; +Cc: Felipe Balbi

Now that buffer size is always passed around, we don't need to rely on
strcat anymore.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
---
 drivers/usb/dwc3/debug.h | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/dwc3/debug.h b/drivers/usb/dwc3/debug.h
index e925a6b73005..6759a7efd8d5 100644
--- a/drivers/usb/dwc3/debug.h
+++ b/drivers/usb/dwc3/debug.h
@@ -545,21 +545,25 @@ static inline const char *dwc3_ep_event_string(char *str, size_t size,
 				status & DEPEVT_STATUS_TRANSFER_ACTIVE ?
 				" (Active)" : " (Not Active)");
 
+		len = strlen(str);
+
 		/* Control Endpoints */
 		if (epnum <= 1) {
 			int phase = DEPEVT_STATUS_CONTROL_PHASE(event->status);
 
 			switch (phase) {
 			case DEPEVT_STATUS_CONTROL_DATA:
-				strcat(str, " [Data Phase]");
+				snprintf(str + ret, size - ret,
+						" [Data Phase]");
 				break;
 			case DEPEVT_STATUS_CONTROL_STATUS:
-				strcat(str, " [Status Phase]");
+				snprintf(str + ret, size - ret,
+						" [Status Phase]");
 			}
 		}
 		break;
 	case DWC3_DEPEVT_RXTXFIFOEVT:
-		strcat(str, "FIFO");
+		snprintf(str + ret, size - ret, "FIFO");
 		break;
 	case DWC3_DEPEVT_STREAMEVT:
 		status = event->status;
@@ -571,13 +575,13 @@ static inline const char *dwc3_ep_event_string(char *str, size_t size,
 			break;
 		case DEPEVT_STREAMEVT_NOTFOUND:
 		default:
-			strcat(str, " Stream Not Found");
+			snprintf(str + ret, size - ret, " Stream Not Found");
 			break;
 		}
 
 		break;
 	case DWC3_DEPEVT_EPCMDCMPLT:
-		strcat(str, "Endpoint Command Complete");
+		snprintf(str + ret, size - ret, "Endpoint Command Complete");
 		break;
 	default:
 		snprintf(str, size, "UNKNOWN");

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-02-06  6:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-06  6:31 [2/2] usb: dwc3: debug: purge usage of strcat Felipe Balbi
  -- strict thread matches above, loose matches on Subject: below --
2019-02-06  6:29 Felipe Balbi
2019-02-05 22:42 Jack Pham
2019-02-05 11:11 Felipe Balbi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.