[PATCH v2 2/4] scripts/coccinelle: New script to remove unnecessary timer_del() calls

Peter Maydell posted 4 patches 4 years, 11 months ago
Maintainers: Alberto Garcia <berto@igalia.com>, Max Reitz <mreitz@redhat.com>, David Gibson <david@gibson.dropbear.id.au>, Dmitry Fleytman <dmitry.fleytman@gmail.com>, Peter Maydell <peter.maydell@linaro.org>, "Philippe Mathieu-Daudé" <f4bug@amsat.org>, Keith Busch <kbusch@kernel.org>, Matthew Rosato <mjrosato@linux.ibm.com>, "Dr. David Alan Gilbert" <dgilbert@redhat.com>, Halil Pasic <pasic@linux.ibm.com>, Klaus Jensen <its@irrelevant.dk>, Ronnie Sahlberg <ronniesahlberg@gmail.com>, Thomas Huth <thuth@redhat.com>, Amit Shah <amit@kernel.org>, John Snow <jsnow@redhat.com>, Kevin Wolf <kwolf@redhat.com>, Cornelia Huck <cohuck@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Richard Henderson <richard.henderson@linaro.org>, Jason Wang <jasowang@redhat.com>, Zhang Chen <chen.zhang@intel.com>, Alex Williamson <alex.williamson@redhat.com>, Eric Blake <eblake@redhat.com>, Samuel Thibault <samuel.thibault@ens-lyon.org>, "Michael S. Tsirkin" <mst@redhat.com>, David Hildenbrand <david@redhat.com>, Laurent Vivier <lvivier@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Christian Borntraeger <borntraeger@de.ibm.com>, Juan Quintela <quintela@redhat.com>, Li Zhijian <lizhijian@cn.fujitsu.com>, Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>, Hailiang Zhang <zhang.zhanghailiang@huawei.com>, Corey Minyard <minyard@acm.org>, Greg Kurz <groug@kaod.org>, Peter Lieven <pl@kamp.de>, Gerd Hoffmann <kraxel@redhat.com>
[PATCH v2 2/4] scripts/coccinelle: New script to remove unnecessary timer_del() calls
Posted by Peter Maydell 4 years, 11 months ago
Now that timer_free() implicitly calls timer_del(), sequences
  timer_del(mytimer);
  timer_free(mytimer);

can be simplified to just
  timer_free(mytimer);


Add a Coccinelle script to do this transformation.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
---
 scripts/coccinelle/timer-del-timer-free.cocci | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
 create mode 100644 scripts/coccinelle/timer-del-timer-free.cocci

diff --git a/scripts/coccinelle/timer-del-timer-free.cocci b/scripts/coccinelle/timer-del-timer-free.cocci
new file mode 100644
index 00000000000..c3cfd428039
--- /dev/null
+++ b/scripts/coccinelle/timer-del-timer-free.cocci
@@ -0,0 +1,18 @@
+// Remove superfluous timer_del() calls
+//
+// Copyright Linaro Limited 2020
+// This work is licensed under the terms of the GNU GPLv2 or later.
+//
+// spatch --macro-file scripts/cocci-macro-file.h \
+//        --sp-file scripts/coccinelle/timer-del-timer-free.cocci \
+//        --in-place --dir .
+//
+// The timer_free() function now implicitly calls timer_del()
+// for you, so calls to timer_del() immediately before the
+// timer_free() of the same timer can be deleted.
+
+@@
+expression T;
+@@
+-timer_del(T);
+ timer_free(T);
-- 
2.20.1


Re: [PATCH v2 2/4] scripts/coccinelle: New script to remove unnecessary timer_del() calls
Posted by Richard Henderson 4 years, 11 months ago
On 12/15/20 9:41 AM, Peter Maydell wrote:
> Now that timer_free() implicitly calls timer_del(), sequences
>   timer_del(mytimer);
>   timer_free(mytimer);
> 
> can be simplified to just
>   timer_free(mytimer);
> 
> 
> Add a Coccinelle script to do this transformation.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> Acked-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  scripts/coccinelle/timer-del-timer-free.cocci | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
>  create mode 100644 scripts/coccinelle/timer-del-timer-free.cocci

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~