io: 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.
Mechanical change using the following Coccinelle spatch script:
@@
expression TAG;
@@
- if (TAG > 0) {
+ if (TAG) {
g_source_remove(TAG);
<... when != TAG
TAG = 0;
...>
}
@@
expression TAG;
@@
- g_source_remove(TAG);
- TAG = 0;
+ g_clear_handle_id(&TAG, g_source_remove);
@@
expression TAG;
@@
- if (TAG) {
g_clear_handle_id(&TAG, g_source_remove);
- }
Inspired-by: Matthew Penney <matt@matthewpenney.net>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Matthew Penney <matt@matthewpenney.net>
Message-Id: <20260408100605.66795-3-philmd@linaro.org>
This commit is contained in:
@@ -90,10 +90,7 @@ static void net_passt_cleanup(NetClientState *nc)
|
||||
g_free(s->vhost_net);
|
||||
s->vhost_net = NULL;
|
||||
}
|
||||
if (s->vhost_watch) {
|
||||
g_source_remove(s->vhost_watch);
|
||||
s->vhost_watch = 0;
|
||||
}
|
||||
g_clear_handle_id(&s->vhost_watch, g_source_remove);
|
||||
qemu_chr_fe_deinit(&s->vhost_chr, true);
|
||||
if (s->vhost_user) {
|
||||
vhost_user_cleanup(s->vhost_user);
|
||||
@@ -421,8 +418,7 @@ static void passt_vhost_user_event(void *opaque, QEMUChrEvent event)
|
||||
if (s->vhost_watch) {
|
||||
AioContext *ctx = qemu_get_current_aio_context();
|
||||
|
||||
g_source_remove(s->vhost_watch);
|
||||
s->vhost_watch = 0;
|
||||
g_clear_handle_id(&s->vhost_watch, g_source_remove);
|
||||
qemu_chr_fe_set_handlers(&s->vhost_chr, NULL, NULL, NULL, NULL,
|
||||
NULL, NULL, false);
|
||||
|
||||
|
||||
15
net/stream.c
15
net/stream.c
@@ -71,24 +71,15 @@ static gboolean net_stream_send(QIOChannel *ioc,
|
||||
static void net_stream_cleanup(NetClientState *nc)
|
||||
{
|
||||
NetStreamState *s = DO_UPCAST(NetStreamState, data.nc, nc);
|
||||
if (s->timer_tag) {
|
||||
g_source_remove(s->timer_tag);
|
||||
s->timer_tag = 0;
|
||||
}
|
||||
g_clear_handle_id(&s->timer_tag, g_source_remove);
|
||||
if (s->addr) {
|
||||
qapi_free_SocketAddress(s->addr);
|
||||
s->addr = NULL;
|
||||
}
|
||||
if (s->data.ioc) {
|
||||
if (QIO_CHANNEL_SOCKET(s->data.ioc)->fd != -1) {
|
||||
if (s->data.ioc_read_tag) {
|
||||
g_source_remove(s->data.ioc_read_tag);
|
||||
s->data.ioc_read_tag = 0;
|
||||
}
|
||||
if (s->data.ioc_write_tag) {
|
||||
g_source_remove(s->data.ioc_write_tag);
|
||||
s->data.ioc_write_tag = 0;
|
||||
}
|
||||
g_clear_handle_id(&s->data.ioc_read_tag, g_source_remove);
|
||||
g_clear_handle_id(&s->data.ioc_write_tag, g_source_remove);
|
||||
}
|
||||
object_unref(OBJECT(s->data.ioc));
|
||||
s->data.ioc = NULL;
|
||||
|
||||
@@ -84,10 +84,7 @@ void net_stream_data_rs_finalize(SocketReadState *rs)
|
||||
if (qemu_send_packet_async(&d->nc, rs->buf,
|
||||
rs->packet_len,
|
||||
net_stream_data_send_completed) == 0) {
|
||||
if (d->ioc_read_tag) {
|
||||
g_source_remove(d->ioc_read_tag);
|
||||
d->ioc_read_tag = 0;
|
||||
}
|
||||
g_clear_handle_id(&d->ioc_read_tag, g_source_remove);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -215,10 +215,7 @@ static void net_vhost_user_cleanup(NetClientState *nc)
|
||||
s->vhost_net = NULL;
|
||||
}
|
||||
if (nc->queue_index == 0) {
|
||||
if (s->watch) {
|
||||
g_source_remove(s->watch);
|
||||
s->watch = 0;
|
||||
}
|
||||
g_clear_handle_id(&s->watch, g_source_remove);
|
||||
qemu_chr_fe_deinit(&s->chr, true);
|
||||
if (s->vhost_user) {
|
||||
vhost_user_cleanup(s->vhost_user);
|
||||
@@ -356,8 +353,7 @@ static void net_vhost_user_event(void *opaque, QEMUChrEvent event)
|
||||
if (s->watch) {
|
||||
AioContext *ctx = qemu_get_current_aio_context();
|
||||
|
||||
g_source_remove(s->watch);
|
||||
s->watch = 0;
|
||||
g_clear_handle_id(&s->watch, g_source_remove);
|
||||
qemu_chr_fe_set_handlers(&s->chr, NULL, NULL, NULL, NULL,
|
||||
NULL, NULL, false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user