Skip to content

Commit 4b973f4

Browse files
lunndavem330
authored andcommitted
net: ethtool: Handle missing cable test TDR parameters
A last minute change put the TDR cable test parameters into a nest. The validation is not sufficient, resulting in an oops if the nest is missing. Set default values first, then update them if the nest is provided. Fixes: f2bc8ad ("net: ethtool: Allow PHY cable test TDR data to configured") Signed-off-by: Andrew Lunn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 54cc017 commit 4b973f4

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

net/ethtool/cabletest.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,14 @@ static int ethnl_act_cable_test_tdr_cfg(const struct nlattr *nest,
234234
struct nlattr *tb[ETHTOOL_A_CABLE_TEST_TDR_CFG_MAX + 1];
235235
int ret;
236236

237+
cfg->first = 100;
238+
cfg->step = 100;
239+
cfg->last = MAX_CABLE_LENGTH_CM;
240+
cfg->pair = PHY_PAIR_ALL;
241+
242+
if (!nest)
243+
return 0;
244+
237245
ret = nla_parse_nested(tb, ETHTOOL_A_CABLE_TEST_TDR_CFG_MAX, nest,
238246
cable_test_tdr_act_cfg_policy, info->extack);
239247
if (ret < 0)
@@ -242,17 +250,12 @@ static int ethnl_act_cable_test_tdr_cfg(const struct nlattr *nest,
242250
if (tb[ETHTOOL_A_CABLE_TEST_TDR_CFG_FIRST])
243251
cfg->first = nla_get_u32(
244252
tb[ETHTOOL_A_CABLE_TEST_TDR_CFG_FIRST]);
245-
else
246-
cfg->first = 100;
253+
247254
if (tb[ETHTOOL_A_CABLE_TEST_TDR_CFG_LAST])
248255
cfg->last = nla_get_u32(tb[ETHTOOL_A_CABLE_TEST_TDR_CFG_LAST]);
249-
else
250-
cfg->last = MAX_CABLE_LENGTH_CM;
251256

252257
if (tb[ETHTOOL_A_CABLE_TEST_TDR_CFG_STEP])
253258
cfg->step = nla_get_u32(tb[ETHTOOL_A_CABLE_TEST_TDR_CFG_STEP]);
254-
else
255-
cfg->step = 100;
256259

257260
if (tb[ETHTOOL_A_CABLE_TEST_TDR_CFG_PAIR]) {
258261
cfg->pair = nla_get_u8(tb[ETHTOOL_A_CABLE_TEST_TDR_CFG_PAIR]);
@@ -263,8 +266,6 @@ static int ethnl_act_cable_test_tdr_cfg(const struct nlattr *nest,
263266
"invalid pair parameter");
264267
return -EINVAL;
265268
}
266-
} else {
267-
cfg->pair = PHY_PAIR_ALL;
268269
}
269270

270271
if (cfg->first > MAX_CABLE_LENGTH_CM) {

0 commit comments

Comments
 (0)