core: fail early if we cannot get current FEC value

If we cannot get current FEC value probably we won't be able to set it a
few lines later. Also, if it fails to set, we try to use the value of
the old one that we tried to retrieve without success. In that case, the
variable old_fec_mode would be uninitialized. Fix it by returning early
if we cannot get the current value.

Fixes: 19bed3121f ('ethtool: support Forward Error Correction(fec)')
This commit is contained in:
Íñigo Huguet
2025-04-03 09:20:58 +02:00
parent 355edef8b5
commit cbdd0d9cca

View File

@@ -2797,13 +2797,16 @@ _ethtool_fec_set(NMDevice *self,
fec_mode = g_variant_get_uint32(variant); fec_mode = g_variant_get_uint32(variant);
} }
nm_platform_ethtool_get_fec_mode(platform, ethtool_state->ifindex, &old_fec_mode);
/* The NM_SETTING_ETHTOOL_FEC_MODE_NONE is query only value, hence do nothing. */ /* The NM_SETTING_ETHTOOL_FEC_MODE_NONE is query only value, hence do nothing. */
if (!fec_mode || fec_mode == NM_SETTING_ETHTOOL_FEC_MODE_NONE) { if (!fec_mode || fec_mode == NM_SETTING_ETHTOOL_FEC_MODE_NONE) {
return; return;
} }
if (!nm_platform_ethtool_get_fec_mode(platform, ethtool_state->ifindex, &old_fec_mode)) {
_LOGW(LOGD_DEVICE, "ethtool: failure setting FEC %d: cannot get current value", fec_mode);
return;
}
if (!nm_platform_ethtool_set_fec_mode(platform, ethtool_state->ifindex, fec_mode)) if (!nm_platform_ethtool_set_fec_mode(platform, ethtool_state->ifindex, fec_mode))
_LOGW(LOGD_DEVICE, "ethtool: failure setting FEC %d", fec_mode); _LOGW(LOGD_DEVICE, "ethtool: failure setting FEC %d", fec_mode);
else { else {