summaryrefslogtreecommitdiff
path: root/system-linux.c
diff options
context:
space:
mode:
authorHauke Mehrtens <hauke@hauke-m.de>2023-02-12 21:07:31 +0100
committerHauke Mehrtens <hauke@hauke-m.de>2023-02-19 16:08:28 +0100
commit19372d8528d25d9774c1c6ede2642bdf57ce3cc3 (patch)
treed7bdc939ff703af66c9b884d9f28dab1ce0bc2df /system-linux.c
parented65a00adc751d102c2041a4a9a32df9dad52b9e (diff)
downloadnetifd-19372d8528d25d9774c1c6ede2642bdf57ce3cc3.tar.gz
netifd: Fix multiple -Wsign-compare warnings
This fixes warnings like this: warning: comparison of integer expressions of different signedness: 'int' and 'long unsigned int' [-Wsign-compare] Mostly this was an int compared to a size_t returned by ARRAY_SIZE(). The easiest fix is to count on the size_t type. The ifindex is sometimes an unsigned int and sometimes a signed int in the kernel interfaces. I think it normally fits into an unsigned 16 bit value, so this should be fine. Do the one comparison where the compiler complains as a long. Casting the result of sizeof() to int should be safe. These values are never out of range of int. Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
Diffstat (limited to 'system-linux.c')
-rw-r--r--system-linux.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/system-linux.c b/system-linux.c
index 45a9efb..d13a561 100644
--- a/system-linux.c
+++ b/system-linux.c
@@ -1154,7 +1154,7 @@ static bool check_ifaddr(struct nlmsghdr *hdr, int ifindex)
{
struct ifaddrmsg *ifa = NLMSG_DATA(hdr);
- return ifa->ifa_index == ifindex;
+ return (long)ifa->ifa_index == ifindex;
}
static bool check_route(struct nlmsghdr *hdr, int ifindex)
@@ -1438,7 +1438,8 @@ int system_macvlan_add(struct device *macvlan, struct device *dev, struct macvla
{
struct nl_msg *msg;
struct nlattr *linkinfo, *data;
- int i, rv;
+ size_t i;
+ int rv;
static const struct {
const char *name;
enum macvlan_mode val;
@@ -1700,7 +1701,7 @@ system_set_ethtool_settings(struct device *dev, struct device_settings *s)
.ifr_data = (caddr_t)&ecmd,
};
static const struct {
- int speed;
+ unsigned int speed;
uint8_t bit_half;
uint8_t bit_full;
} speed_mask[] = {
@@ -1709,7 +1710,7 @@ system_set_ethtool_settings(struct device *dev, struct device_settings *s)
{ 1000, ETHTOOL_LINK_MODE_1000baseT_Half_BIT, ETHTOOL_LINK_MODE_1000baseT_Full_BIT },
};
uint32_t adv;
- int i;
+ size_t i;
strncpy(ifr.ifr_name, dev->ifname, sizeof(ifr.ifr_name) - 1);
@@ -2355,7 +2356,7 @@ static const struct {
static void system_add_link_modes(struct blob_buf *b, __u32 mask)
{
- int i;
+ size_t i;
for (i = 0; i < ARRAY_SIZE(ethtool_link_modes); i++) {
if (mask & ethtool_link_modes[i].mask)
blobmsg_add_string(b, NULL, ethtool_link_modes[i].name);
@@ -2373,7 +2374,7 @@ system_if_force_external(const char *ifname)
static const char *
system_netdevtype_name(unsigned short dev_type)
{
- unsigned int i;
+ size_t i;
for (i = 0; i < ARRAY_SIZE(netdev_types); i++) {
if (netdev_types[i].id == dev_type)
@@ -2457,7 +2458,8 @@ ethtool_feature_index(const char *ifname, const char *keyname)
{
struct ethtool_gstrings *feature_names;
struct ifreq ifr = { 0 };
- int32_t n_features, i;
+ int32_t n_features;
+ uint32_t i;
n_features = ethtool_feature_count(ifname);
@@ -2592,7 +2594,7 @@ system_if_dump_stats(struct device *dev, struct blob_buf *b)
"rx_fifo_errors", "tx_carrier_errors",
};
int stats_dir;
- int i;
+ size_t i;
uint64_t val = 0;
stats_dir = open(dev_sysfs_path(dev->ifname, "statistics"), O_DIRECTORY);
@@ -2838,7 +2840,8 @@ int system_del_route(struct device *dev, struct device_route *route)
int system_flush_routes(void)
{
const char *names[] = { "ipv4", "ipv6" };
- int fd, i;
+ size_t i;
+ int fd;
for (i = 0; i < ARRAY_SIZE(names); i++) {
snprintf(dev_buf, sizeof(dev_buf), "%s/sys/net/%s/route/flush", proc_path, names[i]);