hw/char: use g_clear_handle_id() for GSource cleanup
PATCH 1/8 hw/char: use g_clear_handle_id() for GSource cleanup
Use g_clear_handle_id() instead of g_source_remove() with manual ID checking and zeroing.
This simplifies the code and ensures consistent handling of GSource IDs, since g_clear_handle_id() checks for a non-zero ID before calling the cleanup function and zeros it afterwards.
No functional change intended.
Signed-off-by Matthew Penney <[email protected]>
--- hw/char/cmsdk-apb-uart.c | 5 +---- hw/char/nrf51_uart.c | 5 +---- hw/char/serial.c | 7 ++----- hw/char/stm32l4x5_usart.c | 5 +---- hw/char/terminal3270.c | 5 +---- hw/char/virtio-console.c | 11 +++-------- 6 files changed, 9 insertions(+), 29 deletions(-)
hw/char/cmsdk-apb-uart.c +1 -4
@@ -236,10 +236,7 @@ buffer_drained:static void uart_cancel_transmit (CMSDKAPBUART *s) { -if (s->watch_tag) { -g_source_remove (s->watch_tag); - s->watch_tag =0 ; - } +g_clear_handle_id (&s->watch_tag, g_source_remove); } static void uart_write(void *opaque, hwaddr offset, uint64_t value,
hw/char/nrf51_uart.c +1 -4
@@ -104,10 +104,7 @@ buffer_drained:static void uart_cancel_transmit (NRF51UARTState *s) { -if (s->watch_tag) { -g_source_remove (s->watch_tag); - s->watch_tag =0 ; - } +g_clear_handle_id (&s->watch_tag, g_source_remove); } static void uart_write(void *opaque, hwaddr addr,
hw/char/serial.c +2 -5
@@ -857,10 +857,7 @@ static void serial_reset(void *opaque) {SerialState *s = opaque; -if (s->watch_tag >0 ) { -g_source_remove (s->watch_tag); - s->watch_tag =0 ; - } +g_clear_handle_id (&s->watch_tag, g_source_remove); s->rbr =0 ; s->ier =0 ;
@@ -913,7 +910,7 @@ static int serial_be_change(void *opaque) }if (s->watch_tag >0 ) { -g_source_remove (s->watch_tag); +g_clear_handle_id (&s->watch_tag, g_source_remove); s->watch_tag =qemu_chr_fe_add_watch (&s->chr,G_IO_OUT |G_IO_HUP , serial_watch_cb, s); }
hw/char/stm32l4x5_usart.c +1 -4
@@ -280,10 +280,7 @@ buffer_drained:static void usart_cancel_transmit (Stm32l4x5UsartBaseState *s) { -if (s->watch_tag) { -g_source_remove (s->watch_tag); - s->watch_tag =0 ; - } +g_clear_handle_id (&s->watch_tag, g_source_remove); }static void stm32l4x5_update_params (Stm32l4x5UsartBaseState *s)
hw/char/terminal3270.c +1 -4
@@ -52,10 +52,7 @@ static int terminal_can_read(void *opaque)static void terminal_timer_cancel (Terminal3270 *t) { -if (t->timer_tag) { -g_source_remove (t->timer_tag); - t->timer_tag =0 ; - } +g_clear_handle_id (&t->timer_tag, g_source_remove); }/*
hw/char/virtio-console.c +3 -8
@@ -159,10 +159,7 @@ static void chr_event(void *opaque, QEMUChrEvent event)virtio_serial_open (port);break ;case CHR_EVENT_CLOSED : -if (vcon->watch) { -g_source_remove (vcon->watch); - vcon->watch =0 ; - } +g_clear_handle_id (&vcon->watch, g_source_remove);virtio_serial_close (port);break ;case CHR_EVENT_BREAK :
@@ -188,7 +185,7 @@ static int chr_be_change(void *opaque) }if (vcon->watch) { -g_source_remove (vcon->watch); +g_clear_handle_id (&vcon->watch, g_source_remove); vcon->watch =qemu_chr_fe_add_watch (&vcon->chr,G_IO_OUT |G_IO_HUP , chr_write_unblocked, vcon);
@@ -256,9 +253,7 @@ static void virtconsole_unrealize(DeviceState *dev) {VirtConsole *vcon =VIRTIO_CONSOLE (dev); -if (vcon->watch) { -g_clear_handle_id (&vcon->watch, g_source_remove); - } +g_clear_handle_id (&vcon->watch, g_source_remove); }static void virtconsole_class_init (ObjectClass *klass,const void *data)
Signature · 1 line
2.53.0