diff options
author | Michał Mirosław <mirq-linux@rere.qmqm.pl> | 2011-02-15 11:59:16 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2011-02-17 17:16:32 -0500 |
commit | 340ae1654c0667e0cdd2a6d4dc16f7946e018881 (patch) | |
tree | 9c35472dffcf4051eb70163c4b5555a521813709 /net/core/ethtool.c | |
parent | 212b573f5552c60265da721ff9ce32e3462a2cdd (diff) |
ethtool: factorize ethtool_get_strings() and ethtool_get_sset_count()
This is needed for unified offloads patch.
Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core/ethtool.c')
-rw-r--r-- | net/core/ethtool.c | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/net/core/ethtool.c b/net/core/ethtool.c index 9eb82775a556..85aaeab862a8 100644 --- a/net/core/ethtool.c +++ b/net/core/ethtool.c | |||
@@ -172,6 +172,25 @@ EXPORT_SYMBOL(ethtool_ntuple_flush); | |||
172 | 172 | ||
173 | /* Handlers for each ethtool command */ | 173 | /* Handlers for each ethtool command */ |
174 | 174 | ||
175 | static int __ethtool_get_sset_count(struct net_device *dev, int sset) | ||
176 | { | ||
177 | const struct ethtool_ops *ops = dev->ethtool_ops; | ||
178 | |||
179 | if (ops && ops->get_sset_count && ops->get_strings) | ||
180 | return ops->get_sset_count(dev, sset); | ||
181 | else | ||
182 | return -EOPNOTSUPP; | ||
183 | } | ||
184 | |||
185 | static void __ethtool_get_strings(struct net_device *dev, | ||
186 | u32 stringset, u8 *data) | ||
187 | { | ||
188 | const struct ethtool_ops *ops = dev->ethtool_ops; | ||
189 | |||
190 | /* ops->get_strings is valid because checked earlier */ | ||
191 | ops->get_strings(dev, stringset, data); | ||
192 | } | ||
193 | |||
175 | static int ethtool_get_settings(struct net_device *dev, void __user *useraddr) | 194 | static int ethtool_get_settings(struct net_device *dev, void __user *useraddr) |
176 | { | 195 | { |
177 | struct ethtool_cmd cmd = { .cmd = ETHTOOL_GSET }; | 196 | struct ethtool_cmd cmd = { .cmd = ETHTOOL_GSET }; |
@@ -252,14 +271,10 @@ static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev, | |||
252 | void __user *useraddr) | 271 | void __user *useraddr) |
253 | { | 272 | { |
254 | struct ethtool_sset_info info; | 273 | struct ethtool_sset_info info; |
255 | const struct ethtool_ops *ops = dev->ethtool_ops; | ||
256 | u64 sset_mask; | 274 | u64 sset_mask; |
257 | int i, idx = 0, n_bits = 0, ret, rc; | 275 | int i, idx = 0, n_bits = 0, ret, rc; |
258 | u32 *info_buf = NULL; | 276 | u32 *info_buf = NULL; |
259 | 277 | ||
260 | if (!ops->get_sset_count) | ||
261 | return -EOPNOTSUPP; | ||
262 | |||
263 | if (copy_from_user(&info, useraddr, sizeof(info))) | 278 | if (copy_from_user(&info, useraddr, sizeof(info))) |
264 | return -EFAULT; | 279 | return -EFAULT; |
265 | 280 | ||
@@ -286,7 +301,7 @@ static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev, | |||
286 | if (!(sset_mask & (1ULL << i))) | 301 | if (!(sset_mask & (1ULL << i))) |
287 | continue; | 302 | continue; |
288 | 303 | ||
289 | rc = ops->get_sset_count(dev, i); | 304 | rc = __ethtool_get_sset_count(dev, i); |
290 | if (rc >= 0) { | 305 | if (rc >= 0) { |
291 | info.sset_mask |= (1ULL << i); | 306 | info.sset_mask |= (1ULL << i); |
292 | info_buf[idx++] = rc; | 307 | info_buf[idx++] = rc; |
@@ -1287,17 +1302,13 @@ static int ethtool_self_test(struct net_device *dev, char __user *useraddr) | |||
1287 | static int ethtool_get_strings(struct net_device *dev, void __user *useraddr) | 1302 | static int ethtool_get_strings(struct net_device *dev, void __user *useraddr) |
1288 | { | 1303 | { |
1289 | struct ethtool_gstrings gstrings; | 1304 | struct ethtool_gstrings gstrings; |
1290 | const struct ethtool_ops *ops = dev->ethtool_ops; | ||
1291 | u8 *data; | 1305 | u8 *data; |
1292 | int ret; | 1306 | int ret; |
1293 | 1307 | ||
1294 | if (!ops->get_strings || !ops->get_sset_count) | ||
1295 | return -EOPNOTSUPP; | ||
1296 | |||
1297 | if (copy_from_user(&gstrings, useraddr, sizeof(gstrings))) | 1308 | if (copy_from_user(&gstrings, useraddr, sizeof(gstrings))) |
1298 | return -EFAULT; | 1309 | return -EFAULT; |
1299 | 1310 | ||
1300 | ret = ops->get_sset_count(dev, gstrings.string_set); | 1311 | ret = __ethtool_get_sset_count(dev, gstrings.string_set); |
1301 | if (ret < 0) | 1312 | if (ret < 0) |
1302 | return ret; | 1313 | return ret; |
1303 | 1314 | ||
@@ -1307,7 +1318,7 @@ static int ethtool_get_strings(struct net_device *dev, void __user *useraddr) | |||
1307 | if (!data) | 1318 | if (!data) |
1308 | return -ENOMEM; | 1319 | return -ENOMEM; |
1309 | 1320 | ||
1310 | ops->get_strings(dev, gstrings.string_set, data); | 1321 | __ethtool_get_strings(dev, gstrings.string_set, data); |
1311 | 1322 | ||
1312 | ret = -EFAULT; | 1323 | ret = -EFAULT; |
1313 | if (copy_to_user(useraddr, &gstrings, sizeof(gstrings))) | 1324 | if (copy_to_user(useraddr, &gstrings, sizeof(gstrings))) |
@@ -1317,7 +1328,7 @@ static int ethtool_get_strings(struct net_device *dev, void __user *useraddr) | |||
1317 | goto out; | 1328 | goto out; |
1318 | ret = 0; | 1329 | ret = 0; |
1319 | 1330 | ||
1320 | out: | 1331 | out: |
1321 | kfree(data); | 1332 | kfree(data); |
1322 | return ret; | 1333 | return ret; |
1323 | } | 1334 | } |