linux: up-device-supply-battery: Fix assigning an error to a non-NULL GError pointer

As some systems only allow for one charge threshold setting, the overall
process is treated as a success as long as one of the values is set
correctly. We only treat it as an error (and return FALSE) if both the
start and end threshold settings fail. For this reason, we don't need
to track specific errors for every write, so the GError parameter in
g_file_set_contents_full() is set to NULL.

Fedora upowerd[1326]: g_file_set_contents_full: assertion 'error == NULL || *error == NULL' failed
Fedora upowerd[1326]: GError set over the top of a previous GError or uninitialized memory.
                      This indicates a bug in someone's code. You must ensure an error is NULL before it's set.
                      The overwriting error message was: Failed to set charge control thresholds

Resolves: #331
This commit is contained in:
Kate Hsuan 2025-12-11 15:56:29 +08:00
parent c5df437cc1
commit 1ba5f3a55e

View file

@ -711,9 +711,8 @@ up_device_supply_battery_set_battery_charge_thresholds(UpDevice *device, guint s
if (start != G_MAXUINT) {
g_string_printf (start_str, "%d", CLAMP (start, 0, 100));
if (!g_file_set_contents_full (start_filename, start_str->str, start_str->len,
G_FILE_SET_CONTENTS_ONLY_EXISTING, 0644, error)) {
G_FILE_SET_CONTENTS_ONLY_EXISTING, 0644, NULL))
err_count++;
}
} else {
g_debug ("Ignore charge_control_start_threshold setting");
}
@ -721,9 +720,8 @@ up_device_supply_battery_set_battery_charge_thresholds(UpDevice *device, guint s
if (end != G_MAXUINT) {
g_string_printf (end_str, "%d", CLAMP (end, 0, 100));
if (!g_file_set_contents_full (end_filename, end_str->str, end_str->len,
G_FILE_SET_CONTENTS_ONLY_EXISTING, 0644, error)) {
G_FILE_SET_CONTENTS_ONLY_EXISTING, 0644, NULL))
err_count++;
}
} else {
g_debug ("Ignore charge_control_end_threshold setting");
}