d63baa
From 0db68800c756f298ef45584ac01915c2cb2ce359 Mon Sep 17 00:00:00 2001
d63baa
From: Yu Watanabe <watanabe.yu+github@gmail.com>
d63baa
Date: Mon, 16 Aug 2021 23:47:40 +0900
d63baa
Subject: [PATCH 1/2] ethtool: make the size of 'features' array static
d63baa
d63baa
---
d63baa
 src/shared/ethtool-util.c | 2 +-
d63baa
 src/shared/ethtool-util.h | 2 +-
d63baa
 2 files changed, 2 insertions(+), 2 deletions(-)
d63baa
d63baa
diff --git a/src/shared/ethtool-util.c b/src/shared/ethtool-util.c
d63baa
index f77f6943ca4f..699c7a97ab97 100644
d63baa
--- a/src/shared/ethtool-util.c
d63baa
+++ b/src/shared/ethtool-util.c
d63baa
@@ -501,7 +501,7 @@ static int set_features_bit(
d63baa
         return found ? 0 : -ENODATA;
d63baa
 }
d63baa
 
d63baa
-int ethtool_set_features(int *ethtool_fd, const char *ifname, const int *features) {
d63baa
+int ethtool_set_features(int *ethtool_fd, const char *ifname, const int features[static _NET_DEV_FEAT_MAX]) {
d63baa
         _cleanup_free_ struct ethtool_gstrings *strings = NULL;
d63baa
         struct ethtool_sfeatures *sfeatures;
d63baa
         struct ifreq ifr = {};
d63baa
diff --git a/src/shared/ethtool-util.h b/src/shared/ethtool-util.h
d63baa
index 7d287666249a..f0fc40b0595f 100644
d63baa
--- a/src/shared/ethtool-util.h
d63baa
+++ b/src/shared/ethtool-util.h
d63baa
@@ -88,7 +88,7 @@ int ethtool_get_link_info(int *ethtool_fd, const char *ifname,
d63baa
 int ethtool_get_permanent_macaddr(int *ethtool_fd, const char *ifname, struct ether_addr *ret);
d63baa
 int ethtool_set_wol(int *ethtool_fd, const char *ifname, uint32_t wolopts);
d63baa
 int ethtool_set_nic_buffer_size(int *ethtool_fd, const char *ifname, const netdev_ring_param *ring);
d63baa
-int ethtool_set_features(int *ethtool_fd, const char *ifname, const int *features);
d63baa
+int ethtool_set_features(int *ethtool_fd, const char *ifname, const int features[static _NET_DEV_FEAT_MAX]);
d63baa
 int ethtool_set_glinksettings(int *ethtool_fd, const char *ifname,
d63baa
                               int autonegotiation, const uint32_t advertise[static N_ADVERTISE],
d63baa
                               uint64_t speed, Duplex duplex, NetDevPort port);
d63baa
d63baa
From c2f2250e5c52ec3745a462e3f55a94c133786df8 Mon Sep 17 00:00:00 2001
d63baa
From: Yu Watanabe <watanabe.yu+github@gmail.com>
d63baa
Date: Tue, 17 Aug 2021 00:44:00 +0900
d63baa
Subject: [PATCH 2/2] ethtool: make ethtool_set_features() return earlier when
d63baa
 nothing is requested
d63baa
d63baa
---
d63baa
 src/shared/ethtool-util.c | 16 +++++++++++++---
d63baa
 1 file changed, 13 insertions(+), 3 deletions(-)
d63baa
d63baa
diff --git a/src/shared/ethtool-util.c b/src/shared/ethtool-util.c
d63baa
index 699c7a97ab97..4ca90615f3c1 100644
d63baa
--- a/src/shared/ethtool-util.c
d63baa
+++ b/src/shared/ethtool-util.c
d63baa
@@ -505,12 +505,22 @@ int ethtool_set_features(int *ethtool_fd, const char *ifname, const int features
d63baa
         _cleanup_free_ struct ethtool_gstrings *strings = NULL;
d63baa
         struct ethtool_sfeatures *sfeatures;
d63baa
         struct ifreq ifr = {};
d63baa
-        int i, r;
d63baa
+        bool have = false;
d63baa
+        int r;
d63baa
 
d63baa
         assert(ethtool_fd);
d63baa
         assert(ifname);
d63baa
         assert(features);
d63baa
 
d63baa
+        for (size_t i = 0; i < _NET_DEV_FEAT_MAX; i++)
d63baa
+                if (features[i] >= 0) {
d63baa
+                        have = true;
d63baa
+                        break;
d63baa
+                }
d63baa
+
d63baa
+        if (!have)
d63baa
+                return 0;
d63baa
+
d63baa
         r = ethtool_connect(ethtool_fd);
d63baa
         if (r < 0)
d63baa
                 return r;
d63baa
@@ -525,8 +535,8 @@ int ethtool_set_features(int *ethtool_fd, const char *ifname, const int features
d63baa
         sfeatures->cmd = ETHTOOL_SFEATURES;
d63baa
         sfeatures->size = DIV_ROUND_UP(strings->len, 32U);
d63baa
 
d63baa
-        for (i = 0; i < _NET_DEV_FEAT_MAX; i++)
d63baa
-                if (features[i] != -1) {
d63baa
+        for (size_t i = 0; i < _NET_DEV_FEAT_MAX; i++)
d63baa
+                if (features[i] >= 0) {
d63baa
                         r = set_features_bit(strings, netdev_feature_table[i], features[i], sfeatures);
d63baa
                         if (r < 0) {
d63baa
                                 log_debug_errno(r, "ethtool: could not find feature, ignoring: %s", netdev_feature_table[i]);