[PATCH netifd 1/2] treewide: fix multiple compiler warnings

Petr Štetiar ynezz at true.cz
Wed Mar 29 00:53:46 PDT 2023


Fixes bunch of clang-15/gcc-10 compiler warnings, mostly related to
blobmsg_for_each_attr() usage:

 error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare]
 error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
 error: format string is not a string literal [-Werror,-Wformat-nonliteral]

Cc: Hauke Mehrtens <hauke at hauke-m.de>
Signed-off-by: Petr Štetiar <ynezz at true.cz>
---
 bonding.c      |  2 +-
 bridge.c       |  5 +++--
 config.c       |  2 +-
 extdev.c       |  7 ++++---
 interface-ip.c |  4 ++--
 interface.c    |  5 +++--
 main.c         |  1 +
 proto-shell.c  | 10 +++++-----
 proto.c        |  6 +++---
 system-linux.c |  2 +-
 ubus.c         |  2 +-
 vlandev.c      |  3 ++-
 wireless.c     |  6 +++---
 13 files changed, 30 insertions(+), 25 deletions(-)

diff --git a/bonding.c b/bonding.c
index f4005de059b4..402c71cb7a89 100644
--- a/bonding.c
+++ b/bonding.c
@@ -353,7 +353,7 @@ bonding_config_init(struct device *dev)
 {
 	struct bonding_device *bdev;
 	struct blob_attr *cur;
-	int rem;
+	size_t rem;
 
 	bdev = container_of(dev, struct bonding_device, dev);
 
diff --git a/bridge.c b/bridge.c
index f6e3f4b95bdc..cc833298b134 100644
--- a/bridge.c
+++ b/bridge.c
@@ -782,7 +782,7 @@ bridge_hotplug_set_member_vlans(struct bridge_state *bst, struct blob_attr *vlan
 {
 	struct bridge_vlan *vlan;
 	struct blob_attr *cur;
-	int rem;
+	size_t rem;
 
 	if (!vlans)
 		return;
@@ -1030,7 +1030,8 @@ bridge_config_init(struct device *dev)
 	struct bridge_state *bst;
 	struct bridge_vlan *vlan;
 	struct blob_attr *cur;
-	int i, rem;
+	size_t rem;
+	int i;
 
 	bst = container_of(dev, struct bridge_state, dev);
 
diff --git a/config.c b/config.c
index 9bbda39d3fb5..e1c01e12994b 100644
--- a/config.c
+++ b/config.c
@@ -337,7 +337,7 @@ config_parse_vlan(struct device *dev, struct uci_section *s)
 	char *name_buf;
 	int name_len = 0;
 	int n_ports = 0;
-	int rem;
+	size_t rem;
 
 	val = uci_lookup_option_string(uci_ctx, s, "vlan");
 	if (!val)
diff --git a/extdev.c b/extdev.c
index 5c5e76901d81..8d06228170e1 100644
--- a/extdev.c
+++ b/extdev.c
@@ -754,7 +754,7 @@ static void
 __buf_add_all(struct blob_attr *attr)
 {
 	struct blob_attr *cur;
-	int rem;
+	size_t rem;
 
 	blobmsg_for_each_attr(cur, attr, rem)
 		blobmsg_add_field(&b, blobmsg_type(cur), blobmsg_name(cur), blobmsg_data(cur),
@@ -1055,7 +1055,8 @@ error:
 static void
 __bridge_config_init(struct extdev_bridge *ebr)
 {
-	int rem, ret;
+	int ret;
+	size_t rem;
 	struct blob_attr *cur;
 
 	if (ebr->empty) {
@@ -1100,7 +1101,7 @@ extdev_config_init(struct device *dev)
 }
 
 static void
-extdev_buf_add_list(struct blob_attr *attr, int len, const char *name,
+extdev_buf_add_list(struct blob_attr *attr, size_t len, const char *name,
 		     struct blob_buf *buf, bool array)
 {
 	struct blob_attr *cur;
diff --git a/interface-ip.c b/interface-ip.c
index 7359db2696bc..a06a514b6dde 100644
--- a/interface-ip.c
+++ b/interface-ip.c
@@ -1429,7 +1429,7 @@ void
 interface_add_dns_server_list(struct interface_ip_settings *ip, struct blob_attr *list)
 {
 	struct blob_attr *cur;
-	int rem;
+	size_t rem;
 
 	blobmsg_for_each_attr(cur, list, rem) {
 		if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING)
@@ -1461,7 +1461,7 @@ void
 interface_add_dns_search_list(struct interface_ip_settings *ip, struct blob_attr *list)
 {
 	struct blob_attr *cur;
-	int rem;
+	size_t rem;
 
 	blobmsg_for_each_attr(cur, list, rem) {
 		if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING)
diff --git a/interface.c b/interface.c
index 89654f952c15..66e0e80d72ba 100644
--- a/interface.c
+++ b/interface.c
@@ -232,7 +232,8 @@ interface_add_data(struct interface *iface, const struct blob_attr *data)
 int interface_parse_data(struct interface *iface, const struct blob_attr *attr)
 {
 	struct blob_attr *cur;
-	int rem, ret;
+	size_t rem;
+	int ret;
 
 	iface->updated = 0;
 
@@ -517,7 +518,7 @@ static void
 interface_add_assignment_classes(struct interface *iface, struct blob_attr *list)
 {
 	struct blob_attr *cur;
-	int rem;
+	size_t rem;
 
 	blobmsg_for_each_attr(cur, list, rem) {
 		if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING)
diff --git a/main.c b/main.c
index e5260b5eafa9..ec7b1be03633 100644
--- a/main.c
+++ b/main.c
@@ -64,6 +64,7 @@ netifd_delete_process(struct netifd_process *proc)
 }
 
 void
+__attribute__((format(printf, 2, 0)))
 netifd_log_message(int priority, const char *format, ...)
 {
 	va_list vl;
diff --git a/proto-shell.c b/proto-shell.c
index 9cdbc7fde362..bc3c41dcba85 100644
--- a/proto-shell.c
+++ b/proto-shell.c
@@ -401,7 +401,7 @@ proto_shell_parse_route_list(struct interface *iface, struct blob_attr *attr,
 			     bool v6)
 {
 	struct blob_attr *cur;
-	int rem;
+	size_t rem;
 
 	blobmsg_for_each_attr(cur, attr, rem) {
 		if (blobmsg_type(cur) != BLOBMSG_TYPE_TABLE) {
@@ -418,7 +418,7 @@ proto_shell_parse_neighbor_list(struct interface *iface, struct blob_attr *attr,
 				bool v6)
 {
 	struct blob_attr *cur;
-	int rem;
+	size_t rem;
 
 	blobmsg_for_each_attr(cur, attr, rem) {
 		if (blobmsg_type(cur) != BLOBMSG_TYPE_TABLE) {
@@ -434,7 +434,7 @@ static void
 proto_shell_parse_data(struct interface *iface, struct blob_attr *attr)
 {
 	struct blob_attr *cur;
-	int rem;
+	size_t rem;
 
 	blobmsg_for_each_attr(cur, attr, rem)
 		interface_add_data(iface, cur);
@@ -597,7 +597,7 @@ fill_string_list(struct blob_attr *attr, char **argv, int max)
 {
 	struct blob_attr *cur;
 	int argc = 0;
-	int rem;
+	size_t rem;
 
 	if (!attr)
 		goto out;
@@ -671,7 +671,7 @@ proto_shell_notify_error(struct proto_shell_state *state, struct blob_attr **tb)
 	struct blob_attr *cur;
 	char *data[16];
 	int n_data = 0;
-	int rem;
+	size_t rem;
 
 	if (!tb[NOTIFY_ERROR])
 		return UBUS_STATUS_INVALID_ARGUMENT;
diff --git a/proto.c b/proto.c
index 48dd213bb4b7..63f461db255c 100644
--- a/proto.c
+++ b/proto.c
@@ -160,7 +160,7 @@ parse_static_address_option(struct interface *iface, struct blob_attr *attr,
 	struct device_addr *addr;
 	const char *str;
 	int n_addr = 0;
-	int rem;
+	size_t rem;
 
 	blobmsg_for_each_attr(cur, attr, rem) {
 		if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING)
@@ -266,7 +266,7 @@ parse_address_list(struct interface *iface, struct blob_attr *attr, bool v6,
 	struct device_addr *addr;
 	struct blob_attr *cur;
 	int n_addr = 0;
-	int rem;
+	size_t rem;
 
 	blobmsg_for_each_attr(cur, attr, rem) {
 		addr = parse_address_item(cur, v6, ext);
@@ -392,7 +392,7 @@ parse_prefix_list(struct interface *iface, struct blob_attr *attr)
 {
 	struct blob_attr *cur;
 	int n_addr = 0;
-	int rem;
+	size_t rem;
 
 	blobmsg_for_each_attr(cur, attr, rem) {
 		if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING)
diff --git a/system-linux.c b/system-linux.c
index e4041fbd8060..432581eeb8e4 100644
--- a/system-linux.c
+++ b/system-linux.c
@@ -1036,7 +1036,7 @@ int system_bonding_set_device(struct device *dev, struct bonding_config *cfg)
 	struct blob_attr *cur;
 	char op = cfg ? '+' : '-';
 	char buf[64];
-	int rem;
+	size_t rem;
 
 	snprintf(dev_buf, sizeof(dev_buf), "%s/class/net/bonding_masters", sysfs_path);
 	snprintf(buf, sizeof(buf), "%c%s", op, ifname);
diff --git a/ubus.c b/ubus.c
index 4d05786b6929..3504a4976aac 100644
--- a/ubus.c
+++ b/ubus.c
@@ -272,7 +272,7 @@ netifd_handle_alias(struct ubus_context *ctx, struct ubus_object *obj,
 	struct device *dev = NULL;
 	struct blob_attr *tb[__ALIAS_ATTR_MAX];
 	struct blob_attr *cur;
-	int rem;
+	size_t rem;
 
 	blobmsg_parse(alias_attrs, __ALIAS_ATTR_MAX, tb, blob_data(msg), blob_len(msg));
 
diff --git a/vlandev.c b/vlandev.c
index d93d2b3c5aab..ad4c526f40ae 100644
--- a/vlandev.c
+++ b/vlandev.c
@@ -288,7 +288,8 @@ static void vlandev_qos_mapping_list_apply(struct vlist_simple_tree *qos_mapping
 {
 	struct blob_attr *cur;
 	struct vlan_qos_mapping *qos_mapping;
-	int rem, rc;
+	size_t rem;
+	int rc;
 
 	blobmsg_for_each_attr(cur, list, rem) {
 		if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING)
diff --git a/wireless.c b/wireless.c
index 1f54bfb008cf..1b203b6b33f8 100644
--- a/wireless.c
+++ b/wireless.c
@@ -141,7 +141,7 @@ vif_config_add_bridge(struct blob_buf *buf, struct blob_attr *networks, bool pre
 	struct device *dev = NULL, *orig_dev;
 	struct blob_attr *cur;
 	const char *network;
-	int rem;
+	size_t rem;
 
 	if (!networks)
 		return;
@@ -335,7 +335,7 @@ static void wireless_interface_handle_link(struct wireless_interface *vif, const
 	struct interface *iface;
 	struct blob_attr *cur;
 	const char *network;
-	int rem;
+	size_t rem;
 
 	if (!vif->network || !vif->ifname)
 		return;
@@ -372,7 +372,7 @@ static void wireless_vlan_handle_link(struct wireless_vlan *vlan, bool up)
 	struct interface *iface;
 	struct blob_attr *cur;
 	const char *network;
-	int rem;
+	size_t rem;
 
 	if (!vlan->network || !vlan->ifname)
 		return;



More information about the openwrt-devel mailing list