Commit a4cda04107 for qemu.org
commit a4cda041072e7c6241878260644082781cd1e733
Author: Markus Armbruster <armbru@redhat.com>
Date: Wed Nov 19 14:08:54 2025 +0100
error: error_free(NULL) is safe, drop unnecessary conditionals
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-ID: <20251119130855.105479-5-armbru@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c
index 4922bbc778..87162ff2c0 100644
--- a/hw/acpi/pcihp.c
+++ b/hw/acpi/pcihp.c
@@ -62,9 +62,7 @@ static int acpi_pcihp_get_bsel(PCIBus *bus)
&local_err);
if (local_err || bsel >= ACPI_PCIHP_MAX_HOTPLUG_BUS) {
- if (local_err) {
- error_free(local_err);
- }
+ error_free(local_err);
return -1;
} else {
return bsel;
diff --git a/io/channel-websock.c b/io/channel-websock.c
index cb4dafdebb..d0929ba232 100644
--- a/io/channel-websock.c
+++ b/io/channel-websock.c
@@ -932,9 +932,7 @@ static void qio_channel_websock_finalize(Object *obj)
if (ioc->io_tag) {
g_source_remove(ioc->io_tag);
}
- if (ioc->io_err) {
- error_free(ioc->io_err);
- }
+ error_free(ioc->io_err);
object_unref(OBJECT(ioc->master));
}
diff --git a/io/task.c b/io/task.c
index 451f26f8b4..da79d31782 100644
--- a/io/task.c
+++ b/io/task.c
@@ -91,9 +91,7 @@ static void qio_task_free(QIOTask *task)
if (task->destroyResult) {
task->destroyResult(task->result);
}
- if (task->err) {
- error_free(task->err);
- }
+ error_free(task->err);
object_unref(task->source);
qemu_mutex_unlock(&task->thread_lock);
diff --git a/migration/migration.c b/migration/migration.c
index 9d1bf5d276..1c34d8d432 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -1568,10 +1568,8 @@ bool migrate_has_error(MigrationState *s)
static void migrate_error_free(MigrationState *s)
{
QEMU_LOCK_GUARD(&s->error_mutex);
- if (s->error) {
- error_free(s->error);
- s->error = NULL;
- }
+ error_free(s->error);
+ s->error = NULL;
}
static void migration_connect_error_propagate(MigrationState *s, Error *error)
diff --git a/tests/unit/test-smp-parse.c b/tests/unit/test-smp-parse.c
index 28ea9158e7..1b6450e7d8 100644
--- a/tests/unit/test-smp-parse.c
+++ b/tests/unit/test-smp-parse.c
@@ -875,10 +875,7 @@ static void check_parse(MachineState *ms, const SMPConfiguration *config,
config_str, expect_err, output_topo_str);
end:
- if (err != NULL) {
- error_free(err);
- }
-
+ error_free(err);
abort();
}