diff mbox

[2/2] usb: trivial cleanup for usb_mtp_add_str

Message ID 1457503813-31631-3-git-send-email-peterx@redhat.com
State New
Headers show

Commit Message

Peter Xu March 9, 2016, 6:10 a.m. UTC
Remove useless var "ret".

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 hw/usb/dev-mtp.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Comments

Fam Zheng March 10, 2016, 1:56 a.m. UTC | #1
On Wed, 03/09 14:10, Peter Xu wrote:
> Remove useless var "ret".
> 
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
>  hw/usb/dev-mtp.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
> index cf63fd0..38cc4fc 100644
> --- a/hw/usb/dev-mtp.c
> +++ b/hw/usb/dev-mtp.c
> @@ -719,10 +719,8 @@ static void usb_mtp_add_str(MTPData *data, const char *str)
>  {
>      uint32_t len = strlen(str)+1;
>      wchar_t *wstr = g_malloc(sizeof(wchar_t) * len);
> -    size_t ret;
>  
> -    ret = mbstowcs(wstr, str, len);
> -    if (ret == -1) {
> +    if (mbstowcs(wstr, str, len) == -1) {
>          usb_mtp_add_wstr(data, L"Oops");
>      } else {
>          usb_mtp_add_wstr(data, wstr);
> -- 
> 2.4.3
> 
> 

The old way has no problem, no need to clean up, IMO.

Fam
Markus Armbruster March 10, 2016, 6:51 a.m. UTC | #2
Fam Zheng <famz@redhat.com> writes:

> On Wed, 03/09 14:10, Peter Xu wrote:
>> Remove useless var "ret".
>> 
>> Signed-off-by: Peter Xu <peterx@redhat.com>
>> ---
>>  hw/usb/dev-mtp.c | 4 +---
>>  1 file changed, 1 insertion(+), 3 deletions(-)
>> 
>> diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
>> index cf63fd0..38cc4fc 100644
>> --- a/hw/usb/dev-mtp.c
>> +++ b/hw/usb/dev-mtp.c
>> @@ -719,10 +719,8 @@ static void usb_mtp_add_str(MTPData *data, const char *str)
>>  {
>>      uint32_t len = strlen(str)+1;
>>      wchar_t *wstr = g_malloc(sizeof(wchar_t) * len);
>> -    size_t ret;
>>  
>> -    ret = mbstowcs(wstr, str, len);
>> -    if (ret == -1) {
>> +    if (mbstowcs(wstr, str, len) == -1) {
>>          usb_mtp_add_wstr(data, L"Oops");
>>      } else {
>>          usb_mtp_add_wstr(data, wstr);
>> -- 
>> 2.4.3
>> 
>> 
>
> The old way has no problem, no need to clean up, IMO.

It's a very small readability improvement, but it's an improvement.  If
I was the maintainer, I'd take it.
Gerd Hoffmann March 10, 2016, 7:42 a.m. UTC | #3
On Do, 2016-03-10 at 07:51 +0100, Markus Armbruster wrote:
> Fam Zheng <famz@redhat.com> writes:
> 
> > On Wed, 03/09 14:10, Peter Xu wrote:
> >> Remove useless var "ret".
> >> 
> >> Signed-off-by: Peter Xu <peterx@redhat.com>
> >> ---
> >>  hw/usb/dev-mtp.c | 4 +---
> >>  1 file changed, 1 insertion(+), 3 deletions(-)
> >> 
> >> diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
> >> index cf63fd0..38cc4fc 100644
> >> --- a/hw/usb/dev-mtp.c
> >> +++ b/hw/usb/dev-mtp.c
> >> @@ -719,10 +719,8 @@ static void usb_mtp_add_str(MTPData *data, const char *str)
> >>  {
> >>      uint32_t len = strlen(str)+1;
> >>      wchar_t *wstr = g_malloc(sizeof(wchar_t) * len);
> >> -    size_t ret;
> >>  
> >> -    ret = mbstowcs(wstr, str, len);
> >> -    if (ret == -1) {
> >> +    if (mbstowcs(wstr, str, len) == -1) {
> >>          usb_mtp_add_wstr(data, L"Oops");
> >>      } else {
> >>          usb_mtp_add_wstr(data, wstr);
> >> -- 
> >> 2.4.3
> >> 
> >> 
> >
> > The old way has no problem, no need to clean up, IMO.
> 
> It's a very small readability improvement, but it's an improvement.  If
> I was the maintainer, I'd take it.

Matter of taste, I find the version with ret more readable (not
surprising given I wrote that code ;)

It's easier to see what the "if (...)" condition is because the line is
shorter.

cheers,
  Gerd
diff mbox

Patch

diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
index cf63fd0..38cc4fc 100644
--- a/hw/usb/dev-mtp.c
+++ b/hw/usb/dev-mtp.c
@@ -719,10 +719,8 @@  static void usb_mtp_add_str(MTPData *data, const char *str)
 {
     uint32_t len = strlen(str)+1;
     wchar_t *wstr = g_malloc(sizeof(wchar_t) * len);
-    size_t ret;
 
-    ret = mbstowcs(wstr, str, len);
-    if (ret == -1) {
+    if (mbstowcs(wstr, str, len) == -1) {
         usb_mtp_add_wstr(data, L"Oops");
     } else {
         usb_mtp_add_wstr(data, wstr);