Re: [PATCH] Drop needless ret variable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 10/23/19 6:47 PM, Daniel Henrique Barboza wrote:
> 
> 
> On 10/23/19 10:39 AM, Michal Privoznik wrote:
>> In few places we have the following code pattern:
>>
>>    int ret;
>>    ... /* @ret is not accessed here */
>>    ret = f(...);
>>    return ret;
>>
>> This pattern can be written less verbose:
>>
>>    ...
>>    return f(...);
>>
>> This patch was generated with following coccinelle spatch:
>>
>>    @@
>>    type T;
>>    constant C;
>>    expression f;
>>    identifier ret;
>>    @@
>>    -T ret = C;
>>     ... when != ret
>>    -ret = f;
>>    -return ret;
>>    +return f;
>>
>> Afterwards I needed to fix a few places, e.g. comment in
>> virDomainNetIPParseXML() was removed too because coccinelle
>> thinks it refers to @ret while in fact it doesn't. Also in few
>> places it replaced @ret declaration with a few spaces instead of
>> removing the line. But nothing terribly wrong.
>>
>> Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
> 
> Good stuff. I wonder if this Coccinelle tool would make my life easier
> in the 'cleanup: return' patch series I sent ...

Probably, I don't know how easy it is to remove labels, but I've found
this script which allows you to detect some:

https://github.com/coccinelle/coccinellery/blob/master/CONTRIB/firehose/ret/ret.cocci


> 
> Reviewed-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx>
> 


Pushed, thanks.

Michal

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux