nm-cloud-setup: simplify clearing variables in retry loop

The label "try_again" is only reached by one goto. So it was correct
and sufficient to reset the state only there.

It is still error prone. The slighlty clearer approach is to clear
the state at each begin of the "try_again" step.

There should be no change in behavior.

I didn't confirm, but an optimizing compiler should (could) be able
to see that the cleanup is only necessary on retry, and generate the
same code as before. In any case, we should write code that is easier
to read, not optimize for something that a compiler should be able to
optimize itself.

(cherry picked from commit 911b550140)
This commit is contained in:
Thomas Haller 2022-12-06 14:17:29 +01:00
parent 467c028ac1
commit 5608070764
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -494,6 +494,8 @@ _config_one(GCancellable *sigterm_cancellable,
try_count = 0;
try_again:
g_clear_object(&applied_connection);
g_clear_error(&error);
applied_connection = nmcs_device_get_applied_connection(device,
sigterm_cancellable,
@ -567,8 +569,6 @@ try_again:
&error)) {
if (version_id_changed && try_count < 5) {
_LOGD("config device %s: applied connection changed in the meantime. Retry...", hwaddr);
g_clear_object(&applied_connection);
g_clear_error(&error);
try_count++;
goto try_again;
}