Skip to content

Commit c03a14e

Browse files
jpirkodavem330
authored andcommitted
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 <[email protected]> Reviewed-by: Ben Hutchings <[email protected]> Reviewed-by: Flavio Leitner <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6411280 commit c03a14e

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

net/core/ethtool.c

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ static int __ethtool_get_sset_count(struct net_device *dev, int sset)
175175
if (sset == ETH_SS_FEATURES)
176176
return ARRAY_SIZE(netdev_features_strings);
177177

178-
if (ops && ops->get_sset_count && ops->get_strings)
178+
if (ops->get_sset_count && ops->get_strings)
179179
return ops->get_sset_count(dev, sset);
180180
else
181181
return -EOPNOTSUPP;
@@ -311,7 +311,7 @@ int __ethtool_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
311311
{
312312
ASSERT_RTNL();
313313

314-
if (!dev->ethtool_ops || !dev->ethtool_ops->get_settings)
314+
if (!dev->ethtool_ops->get_settings)
315315
return -EOPNOTSUPP;
316316

317317
memset(cmd, 0, sizeof(struct ethtool_cmd));
@@ -355,7 +355,7 @@ static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,
355355

356356
memset(&info, 0, sizeof(info));
357357
info.cmd = ETHTOOL_GDRVINFO;
358-
if (ops && ops->get_drvinfo) {
358+
if (ops->get_drvinfo) {
359359
ops->get_drvinfo(dev, &info);
360360
} else if (dev->dev.parent && dev->dev.parent->driver) {
361361
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,
370370
* this method of obtaining string set info is deprecated;
371371
* Use ETHTOOL_GSSET_INFO instead.
372372
*/
373-
if (ops && ops->get_sset_count) {
373+
if (ops->get_sset_count) {
374374
int rc;
375375

376376
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,
383383
if (rc >= 0)
384384
info.n_priv_flags = rc;
385385
}
386-
if (ops && ops->get_regs_len)
386+
if (ops->get_regs_len)
387387
info.regdump_len = ops->get_regs_len(dev);
388-
if (ops && ops->get_eeprom_len)
388+
if (ops->get_eeprom_len)
389389
info.eedump_len = ops->get_eeprom_len(dev);
390390

391391
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,
590590
struct ethtool_rxnfc rx_rings;
591591
u32 user_size, dev_size, i;
592592
u32 *indir;
593+
const struct ethtool_ops *ops = dev->ethtool_ops;
593594
int ret;
594595

595-
if (!dev->ethtool_ops->get_rxfh_indir_size ||
596-
!dev->ethtool_ops->set_rxfh_indir ||
597-
!dev->ethtool_ops->get_rxnfc)
596+
if (!ops->get_rxfh_indir_size || !ops->set_rxfh_indir ||
597+
!ops->get_rxnfc)
598598
return -EOPNOTSUPP;
599-
dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev);
599+
600+
dev_size = ops->get_rxfh_indir_size(dev);
600601
if (dev_size == 0)
601602
return -EOPNOTSUPP;
602603

@@ -613,7 +614,7 @@ static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev,
613614
return -ENOMEM;
614615

615616
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);
617618
if (ret)
618619
goto out;
619620

@@ -639,7 +640,7 @@ static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev,
639640
}
640641
}
641642

642-
ret = dev->ethtool_ops->set_rxfh_indir(dev, indir);
643+
ret = ops->set_rxfh_indir(dev, indir);
643644

644645
out:
645646
kfree(indir);
@@ -1082,9 +1083,10 @@ static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
10821083
{
10831084
struct ethtool_value id;
10841085
static bool busy;
1086+
const struct ethtool_ops *ops = dev->ethtool_ops;
10851087
int rc;
10861088

1087-
if (!dev->ethtool_ops->set_phys_id)
1089+
if (!ops->set_phys_id)
10881090
return -EOPNOTSUPP;
10891091

10901092
if (busy)
@@ -1093,7 +1095,7 @@ static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
10931095
if (copy_from_user(&id, useraddr, sizeof(id)))
10941096
return -EFAULT;
10951097

1096-
rc = dev->ethtool_ops->set_phys_id(dev, ETHTOOL_ID_ACTIVE);
1098+
rc = ops->set_phys_id(dev, ETHTOOL_ID_ACTIVE);
10971099
if (rc < 0)
10981100
return rc;
10991101

@@ -1118,7 +1120,7 @@ static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
11181120
i = n;
11191121
do {
11201122
rtnl_lock();
1121-
rc = dev->ethtool_ops->set_phys_id(dev,
1123+
rc = ops->set_phys_id(dev,
11221124
(i & 1) ? ETHTOOL_ID_OFF : ETHTOOL_ID_ON);
11231125
rtnl_unlock();
11241126
if (rc)
@@ -1133,7 +1135,7 @@ static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
11331135
dev_put(dev);
11341136
busy = false;
11351137

1136-
(void)dev->ethtool_ops->set_phys_id(dev, ETHTOOL_ID_INACTIVE);
1138+
(void) ops->set_phys_id(dev, ETHTOOL_ID_INACTIVE);
11371139
return rc;
11381140
}
11391141

@@ -1275,7 +1277,7 @@ static int ethtool_get_dump_flag(struct net_device *dev,
12751277
struct ethtool_dump dump;
12761278
const struct ethtool_ops *ops = dev->ethtool_ops;
12771279

1278-
if (!dev->ethtool_ops->get_dump_flag)
1280+
if (!ops->get_dump_flag)
12791281
return -EOPNOTSUPP;
12801282

12811283
if (copy_from_user(&dump, useraddr, sizeof(dump)))
@@ -1299,8 +1301,7 @@ static int ethtool_get_dump_data(struct net_device *dev,
12991301
const struct ethtool_ops *ops = dev->ethtool_ops;
13001302
void *data = NULL;
13011303

1302-
if (!dev->ethtool_ops->get_dump_data ||
1303-
!dev->ethtool_ops->get_dump_flag)
1304+
if (!ops->get_dump_data || !ops->get_dump_flag)
13041305
return -EOPNOTSUPP;
13051306

13061307
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)
13461347
info.cmd = ETHTOOL_GET_TS_INFO;
13471348

13481349
if (phydev && phydev->drv && phydev->drv->ts_info) {
1349-
13501350
err = phydev->drv->ts_info(phydev, &info);
1351-
1352-
} else if (dev->ethtool_ops && dev->ethtool_ops->get_ts_info) {
1353-
1351+
} else if (ops->get_ts_info) {
13541352
err = ops->get_ts_info(dev, &info);
1355-
13561353
} else {
13571354
info.so_timestamping =
13581355
SOF_TIMESTAMPING_RX_SOFTWARE |

0 commit comments

Comments
 (0)