link: fix type for link-config's "features" array of tristates
authorThomas Haller <thaller@redhat.com>
Tue, 7 Aug 2018 06:55:07 +0000 (08:55 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 7 Aug 2018 13:40:39 +0000 (15:40 +0200)
The "features" fields is parsed as a tristate value. The values
are thus not of type NetDevFeature enum but int. The NetDevFeature
enum is instead the index for the features array.

Adjust the type. In practice, this had no impact because NetDevFeature
enum commonly has size of int.

Also, don't use memset() 0xFF to initilize the int with -1. While
it works correctly in practice, it feels ugly.

src/udev/net/ethtool-util.c
src/udev/net/ethtool-util.h
src/udev/net/link-config.c
src/udev/net/link-config.h

index 4bb4216..2051a99 100644 (file)
@@ -302,7 +302,7 @@ static int find_feature_index(struct ethtool_gstrings *strings, const char *feat
         return -1;
 }
 
-int ethtool_set_features(int *fd, const char *ifname, NetDevFeature *features) {
+int ethtool_set_features(int *fd, const char *ifname, int *features) {
         _cleanup_free_ struct ethtool_gstrings *strings = NULL;
         struct ethtool_sfeatures *sfeatures;
         int block, bit, i, r;
index d57a756..2aa067a 100644 (file)
@@ -83,7 +83,7 @@ int ethtool_connect(int *ret);
 int ethtool_get_driver(int *fd, const char *ifname, char **ret);
 int ethtool_set_speed(int *fd, const char *ifname, unsigned int speed, Duplex duplex);
 int ethtool_set_wol(int *fd, const char *ifname, WakeOnLan wol);
-int ethtool_set_features(int *fd, const char *ifname, NetDevFeature *features);
+int ethtool_set_features(int *fd, const char *ifname, int *features);
 int ethtool_set_glinksettings(int *fd, const char *ifname, struct link_config *link);
 int ethtool_set_channels(int *fd, const char *ifname, netdev_channels *channels);
 
index cec4f4f..1a397ec 100644 (file)
@@ -125,6 +125,7 @@ int link_config_ctx_new(link_config_ctx **ret) {
 static int load_link(link_config_ctx *ctx, const char *filename) {
         _cleanup_(link_config_freep) link_config *link = NULL;
         _cleanup_fclose_ FILE *file = NULL;
+        int i;
         int r;
 
         assert(ctx);
@@ -153,7 +154,8 @@ static int load_link(link_config_ctx *ctx, const char *filename) {
         link->port = _NET_DEV_PORT_INVALID;
         link->autonegotiation = -1;
 
-        memset(&link->features, 0xFF, sizeof(link->features));
+        for (i = 0; i < (int)ELEMENTSOF(link->features); i++)
+                link->features[i] = -1;
 
         r = config_parse(NULL, filename, file,
                          "Match\0Link\0Ethernet\0",
index 713513e..c8f4367 100644 (file)
@@ -56,7 +56,7 @@ struct link_config {
         int autonegotiation;
         WakeOnLan wol;
         NetDevPort port;
-        NetDevFeature features[_NET_DEV_FEAT_MAX];
+        int features[_NET_DEV_FEAT_MAX];
         netdev_channels channels;
 
         LIST_FIELDS(link_config, links);