[PATCH] qemu-timer: allow freeing a NULL timer

Paolo Bonzini posted 1 patch 3 years, 1 month ago
Test checkpatch passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20210310154526.463850-1-pbonzini@redhat.com
include/qemu/timer.h | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
[PATCH] qemu-timer: allow freeing a NULL timer
Posted by Paolo Bonzini 3 years, 1 month ago
Since 5f8e93c3e2 ("util/qemu-timer: Make timer_free() imply timer_del()", 2021-01-08)
it is not possible anymore to pass a NULL pointer to timer_free().  Previously
it would do nothing as it would simply pass NULL down to g_free().

Rectify this, which also fixes "-chardev braille" when there is no device.

Reported-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 include/qemu/timer.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/include/qemu/timer.h b/include/qemu/timer.h
index 1678238384..88ef114689 100644
--- a/include/qemu/timer.h
+++ b/include/qemu/timer.h
@@ -629,8 +629,10 @@ void timer_del(QEMUTimer *ts);
  */
 static inline void timer_free(QEMUTimer *ts)
 {
-    timer_del(ts);
-    g_free(ts);
+    if (ts) {
+        timer_del(ts);
+        g_free(ts);
+    }
 }
 
 /**
-- 
2.26.2


Re: [PATCH] qemu-timer: allow freeing a NULL timer
Posted by Stefano Garzarella 3 years, 1 month ago
On Wed, Mar 10, 2021 at 10:45:26AM -0500, Paolo Bonzini wrote:
>Since 5f8e93c3e2 ("util/qemu-timer: Make timer_free() imply timer_del()", 2021-01-08)
>it is not possible anymore to pass a NULL pointer to timer_free().  Previously
>it would do nothing as it would simply pass NULL down to g_free().
>
>Rectify this, which also fixes "-chardev braille" when there is no device.
>
>Reported-by: Markus Armbruster <armbru@redhat.com>
>Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>---
> include/qemu/timer.h | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)

Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>


Re: [PATCH] qemu-timer: allow freeing a NULL timer
Posted by Philippe Mathieu-Daudé 3 years, 1 month ago
On 3/10/21 4:45 PM, Paolo Bonzini wrote:
> Since 5f8e93c3e2 ("util/qemu-timer: Make timer_free() imply timer_del()", 2021-01-08)
> it is not possible anymore to pass a NULL pointer to timer_free().  Previously
> it would do nothing as it would simply pass NULL down to g_free().
> 
> Rectify this, which also fixes "-chardev braille" when there is no device.
> 
> Reported-by: Markus Armbruster <armbru@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  include/qemu/timer.h | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>