diff options
author | Jiri Pirko <jiri@resnulli.us> | 2013-01-07 04:02:08 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2013-01-07 22:54:19 -0500 |
commit | c03a14e8db06d6687f470f9769f47aa5764b1fe3 (patch) | |
tree | ef31d964177270e7e2b9c5201421425d458b16f1 /net/core/ethtool.c | |
parent | 6411280ac94db94a09770807d3871d2661803604 (diff) |
ethtool: consolidate work with ethtool_ops
No need to check if ethtool_ops == NULL since it can't be.
Use local variable "ops" in functions where it is present
instead of dev->ethtool_ops
Introduce local variable "ops" in functions where dev->ethtool_ops is used
many times.
Signed-off-by: Jiri Pirko <jiri@resnulli.us>
Reviewed-by: Ben Hutchings <bhutchings@solarflare.com>
Reviewed-by: Flavio Leitner <fbl@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core/ethtool.c')
-rw-r--r-- | net/core/ethtool.c | 45 |
1 files changed, 21 insertions, 24 deletions
diff --git a/net/core/ethtool.c b/net/core/ethtool.c index a8705432e4b1..d9d55209db67 100644 --- a/net/core/ethtool.c +++ b/net/core/ethtool.c | |||
@@ -175,7 +175,7 @@ static int __ethtool_get_sset_count(struct net_device *dev, int sset) | |||
175 | if (sset == ETH_SS_FEATURES) | 175 | if (sset == ETH_SS_FEATURES) |
176 | return ARRAY_SIZE(netdev_features_strings); | 176 | return ARRAY_SIZE(netdev_features_strings); |
177 | 177 | ||
178 | if (ops && ops->get_sset_count && ops->get_strings) | 178 | if (ops->get_sset_count && ops->get_strings) |
179 | return ops->get_sset_count(dev, sset); | 179 | return ops->get_sset_count(dev, sset); |
180 | else | 180 | else |
181 | return -EOPNOTSUPP; | 181 | return -EOPNOTSUPP; |
@@ -311,7 +311,7 @@ int __ethtool_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) | |||
311 | { | 311 | { |
312 | ASSERT_RTNL(); | 312 | ASSERT_RTNL(); |
313 | 313 | ||
314 | if (!dev->ethtool_ops || !dev->ethtool_ops->get_settings) | 314 | if (!dev->ethtool_ops->get_settings) |
315 | return -EOPNOTSUPP; | 315 | return -EOPNOTSUPP; |
316 | 316 | ||
317 | memset(cmd, 0, sizeof(struct ethtool_cmd)); | 317 | memset(cmd, 0, sizeof(struct ethtool_cmd)); |
@@ -355,7 +355,7 @@ static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev, | |||
355 | 355 | ||
356 | memset(&info, 0, sizeof(info)); | 356 | memset(&info, 0, sizeof(info)); |
357 | info.cmd = ETHTOOL_GDRVINFO; | 357 | info.cmd = ETHTOOL_GDRVINFO; |
358 | if (ops && ops->get_drvinfo) { | 358 | if (ops->get_drvinfo) { |
359 | ops->get_drvinfo(dev, &info); | 359 | ops->get_drvinfo(dev, &info); |
360 | } else if (dev->dev.parent && dev->dev.parent->driver) { | 360 | } else if (dev->dev.parent && dev->dev.parent->driver) { |
361 | strlcpy(info.bus_info, dev_name(dev->dev.parent), | 361 | strlcpy(info.bus_info, dev_name(dev->dev.parent), |
@@ -370,7 +370,7 @@ static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev, | |||
370 | * this method of obtaining string set info is deprecated; | 370 | * this method of obtaining string set info is deprecated; |
371 | * Use ETHTOOL_GSSET_INFO instead. | 371 | * Use ETHTOOL_GSSET_INFO instead. |
372 | */ | 372 | */ |
373 | if (ops && ops->get_sset_count) { | 373 | if (ops->get_sset_count) { |
374 | int rc; | 374 | int rc; |
375 | 375 | ||
376 | rc = ops->get_sset_count(dev, ETH_SS_TEST); | 376 | rc = ops->get_sset_count(dev, ETH_SS_TEST); |
@@ -383,9 +383,9 @@ static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev, | |||
383 | if (rc >= 0) | 383 | if (rc >= 0) |
384 | info.n_priv_flags = rc; | 384 | info.n_priv_flags = rc; |
385 | } | 385 | } |
386 | if (ops && ops->get_regs_len) | 386 | if (ops->get_regs_len) |
387 | info.regdump_len = ops->get_regs_len(dev); | 387 | info.regdump_len = ops->get_regs_len(dev); |
388 | if (ops && ops->get_eeprom_len) | 388 | if (ops->get_eeprom_len) |
389 | info.eedump_len = ops->get_eeprom_len(dev); | 389 | info.eedump_len = ops->get_eeprom_len(dev); |
390 | 390 | ||
391 | if (copy_to_user(useraddr, &info, sizeof(info))) | 391 | if (copy_to_user(useraddr, &info, sizeof(info))) |
@@ -590,13 +590,14 @@ static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev, | |||
590 | struct ethtool_rxnfc rx_rings; | 590 | struct ethtool_rxnfc rx_rings; |
591 | u32 user_size, dev_size, i; | 591 | u32 user_size, dev_size, i; |
592 | u32 *indir; | 592 | u32 *indir; |
593 | const struct ethtool_ops *ops = dev->ethtool_ops; | ||
593 | int ret; | 594 | int ret; |
594 | 595 | ||
595 | if (!dev->ethtool_ops->get_rxfh_indir_size || | 596 | if (!ops->get_rxfh_indir_size || !ops->set_rxfh_indir || |
596 | !dev->ethtool_ops->set_rxfh_indir || | 597 | !ops->get_rxnfc) |
597 | !dev->ethtool_ops->get_rxnfc) | ||
598 | return -EOPNOTSUPP; | 598 | return -EOPNOTSUPP; |
599 | dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev); | 599 | |
600 | dev_size = ops->get_rxfh_indir_size(dev); | ||
600 | if (dev_size == 0) | 601 | if (dev_size == 0) |
601 | return -EOPNOTSUPP; | 602 | return -EOPNOTSUPP; |
602 | 603 | ||
@@ -613,7 +614,7 @@ static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev, | |||
613 | return -ENOMEM; | 614 | return -ENOMEM; |
614 | 615 | ||
615 | rx_rings.cmd = ETHTOOL_GRXRINGS; | 616 | rx_rings.cmd = ETHTOOL_GRXRINGS; |
616 | ret = dev->ethtool_ops->get_rxnfc(dev, &rx_rings, NULL); | 617 | ret = ops->get_rxnfc(dev, &rx_rings, NULL); |
617 | if (ret) | 618 | if (ret) |
618 | goto out; | 619 | goto out; |
619 | 620 | ||
@@ -639,7 +640,7 @@ static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev, | |||
639 | } | 640 | } |
640 | } | 641 | } |
641 | 642 | ||
642 | ret = dev->ethtool_ops->set_rxfh_indir(dev, indir); | 643 | ret = ops->set_rxfh_indir(dev, indir); |
643 | 644 | ||
644 | out: | 645 | out: |
645 | kfree(indir); | 646 | kfree(indir); |
@@ -1082,9 +1083,10 @@ static int ethtool_phys_id(struct net_device *dev, void __user *useraddr) | |||
1082 | { | 1083 | { |
1083 | struct ethtool_value id; | 1084 | struct ethtool_value id; |
1084 | static bool busy; | 1085 | static bool busy; |
1086 | const struct ethtool_ops *ops = dev->ethtool_ops; | ||
1085 | int rc; | 1087 | int rc; |
1086 | 1088 | ||
1087 | if (!dev->ethtool_ops->set_phys_id) | 1089 | if (!ops->set_phys_id) |
1088 | return -EOPNOTSUPP; | 1090 | return -EOPNOTSUPP; |
1089 | 1091 | ||
1090 | if (busy) | 1092 | if (busy) |
@@ -1093,7 +1095,7 @@ static int ethtool_phys_id(struct net_device *dev, void __user *useraddr) | |||
1093 | if (copy_from_user(&id, useraddr, sizeof(id))) | 1095 | if (copy_from_user(&id, useraddr, sizeof(id))) |
1094 | return -EFAULT; | 1096 | return -EFAULT; |
1095 | 1097 | ||
1096 | rc = dev->ethtool_ops->set_phys_id(dev, ETHTOOL_ID_ACTIVE); | 1098 | rc = ops->set_phys_id(dev, ETHTOOL_ID_ACTIVE); |
1097 | if (rc < 0) | 1099 | if (rc < 0) |
1098 | return rc; | 1100 | return rc; |
1099 | 1101 | ||
@@ -1118,7 +1120,7 @@ static int ethtool_phys_id(struct net_device *dev, void __user *useraddr) | |||
1118 | i = n; | 1120 | i = n; |
1119 | do { | 1121 | do { |
1120 | rtnl_lock(); | 1122 | rtnl_lock(); |
1121 | rc = dev->ethtool_ops->set_phys_id(dev, | 1123 | rc = ops->set_phys_id(dev, |
1122 | (i & 1) ? ETHTOOL_ID_OFF : ETHTOOL_ID_ON); | 1124 | (i & 1) ? ETHTOOL_ID_OFF : ETHTOOL_ID_ON); |
1123 | rtnl_unlock(); | 1125 | rtnl_unlock(); |
1124 | if (rc) | 1126 | if (rc) |
@@ -1133,7 +1135,7 @@ static int ethtool_phys_id(struct net_device *dev, void __user *useraddr) | |||
1133 | dev_put(dev); | 1135 | dev_put(dev); |
1134 | busy = false; | 1136 | busy = false; |
1135 | 1137 | ||
1136 | (void)dev->ethtool_ops->set_phys_id(dev, ETHTOOL_ID_INACTIVE); | 1138 | (void) ops->set_phys_id(dev, ETHTOOL_ID_INACTIVE); |
1137 | return rc; | 1139 | return rc; |
1138 | } | 1140 | } |
1139 | 1141 | ||
@@ -1275,7 +1277,7 @@ static int ethtool_get_dump_flag(struct net_device *dev, | |||
1275 | struct ethtool_dump dump; | 1277 | struct ethtool_dump dump; |
1276 | const struct ethtool_ops *ops = dev->ethtool_ops; | 1278 | const struct ethtool_ops *ops = dev->ethtool_ops; |
1277 | 1279 | ||
1278 | if (!dev->ethtool_ops->get_dump_flag) | 1280 | if (!ops->get_dump_flag) |
1279 | return -EOPNOTSUPP; | 1281 | return -EOPNOTSUPP; |
1280 | 1282 | ||
1281 | if (copy_from_user(&dump, useraddr, sizeof(dump))) | 1283 | if (copy_from_user(&dump, useraddr, sizeof(dump))) |
@@ -1299,8 +1301,7 @@ static int ethtool_get_dump_data(struct net_device *dev, | |||
1299 | const struct ethtool_ops *ops = dev->ethtool_ops; | 1301 | const struct ethtool_ops *ops = dev->ethtool_ops; |
1300 | void *data = NULL; | 1302 | void *data = NULL; |
1301 | 1303 | ||
1302 | if (!dev->ethtool_ops->get_dump_data || | 1304 | if (!ops->get_dump_data || !ops->get_dump_flag) |
1303 | !dev->ethtool_ops->get_dump_flag) | ||
1304 | return -EOPNOTSUPP; | 1305 | return -EOPNOTSUPP; |
1305 | 1306 | ||
1306 | if (copy_from_user(&dump, useraddr, sizeof(dump))) | 1307 | if (copy_from_user(&dump, useraddr, sizeof(dump))) |
@@ -1346,13 +1347,9 @@ static int ethtool_get_ts_info(struct net_device *dev, void __user *useraddr) | |||
1346 | info.cmd = ETHTOOL_GET_TS_INFO; | 1347 | info.cmd = ETHTOOL_GET_TS_INFO; |
1347 | 1348 | ||
1348 | if (phydev && phydev->drv && phydev->drv->ts_info) { | 1349 | if (phydev && phydev->drv && phydev->drv->ts_info) { |
1349 | |||
1350 | err = phydev->drv->ts_info(phydev, &info); | 1350 | err = phydev->drv->ts_info(phydev, &info); |
1351 | 1351 | } else if (ops->get_ts_info) { | |
1352 | } else if (dev->ethtool_ops && dev->ethtool_ops->get_ts_info) { | ||
1353 | |||
1354 | err = ops->get_ts_info(dev, &info); | 1352 | err = ops->get_ts_info(dev, &info); |
1355 | |||
1356 | } else { | 1353 | } else { |
1357 | info.so_timestamping = | 1354 | info.so_timestamping = |
1358 | SOF_TIMESTAMPING_RX_SOFTWARE | | 1355 | SOF_TIMESTAMPING_RX_SOFTWARE | |