]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
ethtool: make ethtool_set_features() return earlier when nothing is requested 20450/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 16 Aug 2021 15:44:00 +0000 (00:44 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 16 Aug 2021 15:49:01 +0000 (00:49 +0900)
src/shared/ethtool-util.c

index 699c7a97ab97ceb11d3726748ea87a8f04e7c189..4ca90615f3c148f7a0b2a49f39179f72ef3abc1a 100644 (file)
@@ -505,12 +505,22 @@ int ethtool_set_features(int *ethtool_fd, const char *ifname, const int features
         _cleanup_free_ struct ethtool_gstrings *strings = NULL;
         struct ethtool_sfeatures *sfeatures;
         struct ifreq ifr = {};
-        int i, r;
+        bool have = false;
+        int r;
 
         assert(ethtool_fd);
         assert(ifname);
         assert(features);
 
+        for (size_t i = 0; i < _NET_DEV_FEAT_MAX; i++)
+                if (features[i] >= 0) {
+                        have = true;
+                        break;
+                }
+
+        if (!have)
+                return 0;
+
         r = ethtool_connect(ethtool_fd);
         if (r < 0)
                 return r;
@@ -525,8 +535,8 @@ int ethtool_set_features(int *ethtool_fd, const char *ifname, const int features
         sfeatures->cmd = ETHTOOL_SFEATURES;
         sfeatures->size = DIV_ROUND_UP(strings->len, 32U);
 
-        for (i = 0; i < _NET_DEV_FEAT_MAX; i++)
-                if (features[i] != -1) {
+        for (size_t i = 0; i < _NET_DEV_FEAT_MAX; i++)
+                if (features[i] >= 0) {
                         r = set_features_bit(strings, netdev_feature_table[i], features[i], sfeatures);
                         if (r < 0) {
                                 log_debug_errno(r, "ethtool: could not find feature, ignoring: %s", netdev_feature_table[i]);