Skip to contentSkip to conversation

Tools: hv: fix compiler warnings and do minor cleanup

PATCH RESEND In review K. Y. Srinivasan 3 participants 8 messages Jan 10, 2015 – Jan 26, 2015 Hyper-V/Azure core and drivers

lore
Share & tools
lore
#0 lore raw

cover Tools: hv: fix compiler warnings and do minor cleanup

When someone does 'make' in tools/hv/ issues appear:
- hv_fcopy_daemon is not being built;
- lots of compiler warnings.

This is just a cleanup. Compile-tested by myself on top of linux-next/master.

Piggyback this series and send "[PATCH 5/5] Tools: hv: do not add redundant '/' in hv_start_fcopy()"

Vitaly Kuznetsov (5):
Tools: hv: add mising fcopyd to the Makefile
Tools: hv: remove unused bytes_written from kvp_update_file()
Tools: hv: address compiler warnings for hv_kvp_daemon.c
Tools: hv: address compiler warnings for hv_fcopy_daemon.c
Tools: hv: do not add redundant '/' in hv_start_fcopy()

 tools/hv/Makefile          |    4 ++--
 tools/hv/hv_fcopy_daemon.c |   10 ++--------
 tools/hv/hv_kvp_daemon.c   |   29 +++++++++++++----------------
 3 files changed, 17 insertions(+), 26 deletions(-)
Signature · 1 line
1.7.4.1
#1 lore raw

PATCH RESEND 1/5 Tools: hv: add mising fcopyd to the Makefile

From: Vitaly Kuznetsov <[email protected]>

fcopyd in missing in the Makefile, add it there.

---
 tools/hv/Makefile |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
tools/hv/Makefile +2 -2
index bd22f78..99ffe61 100644
@@ -5,9 +5,9 @@ PTHREAD_LIBS = -lpthread
 WARNINGS = -Wall -Wextra
 CFLAGS = $(WARNINGS) -g $(PTHREAD_LIBS)
 
-all: hv_kvp_daemon hv_vss_daemon
+all: hv_kvp_daemon hv_vss_daemon hv_fcopy_daemon
 %: %.c
 	$(CC) $(CFLAGS) -o $@ $^
 
 clean:
-	$(RM) hv_kvp_daemon hv_vss_daemon
+	$(RM) hv_kvp_daemon hv_vss_daemon hv_fcopy_daemon
Signature · 1 line
1.7.4.1
#2 lore raw

PATCH RESEND 2/5 Tools: hv: remove unused bytes_written from kvp_update_file()

From: Vitaly Kuznetsov <[email protected]>

fwrite() does not actually return the number of bytes written and
this value is being ignored anyway and ferror() is being called to
check for an error. As we assign to this variable and never use it
we get the following compile-time warning:
hv_kvp_daemon.c:149:9: warning: variable .bytes_written. set but not used [-Wunused-but-set-variable] Remove bytes_written completely.

---
 tools/hv/hv_kvp_daemon.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
tools/hv/hv_kvp_daemon.c +1 -3
index 6a6432a..5a274ca 100644
@@ -147,7 +147,6 @@ static void kvp_release_lock(int pool)
 static void kvp_update_file(int pool)
 {
 	FILE *filep;
-	size_t bytes_written;
 
 	/*
 	 * We are going to write our in-memory registry out to
@@ -163,8 +162,7 @@ static void kvp_update_file(int pool)
 		exit(EXIT_FAILURE);
 	}
 
-	bytes_written = fwrite(kvp_file_info[pool].records,
-				sizeof(struct kvp_record),
+	fwrite(kvp_file_info[pool].records, sizeof(struct kvp_record),
 				kvp_file_info[pool].num_records, filep);
 
 	if (ferror(filep) || fclose(filep)) {
Signature · 1 line
1.7.4.1
#3 lore raw

PATCH RESEND 3/5 Tools: hv: address compiler warnings for hv_kvp_daemon.c

In reply to K. Y. Srinivasan

From: Vitaly Kuznetsov <[email protected]>

This patch addresses two types of compiler warnings:
... warning: comparison between signed and unsigned integer expressions [-Wsign-compare] and
... warning: pointer targets in passing argument N of .kvp_.... differ in signedness [-Wpointer-sign]

---
 tools/hv/hv_kvp_daemon.c |   25 ++++++++++++-------------
 1 files changed, 12 insertions(+), 13 deletions(-)
tools/hv/hv_kvp_daemon.c +12 -13
index 5a274ca..48a95f9 100644
@@ -308,7 +308,7 @@ static int kvp_file_init(void)
 	return 0;
 }
 
-static int kvp_key_delete(int pool, const char *key, int key_size)
+static int kvp_key_delete(int pool, const __u8 *key, int key_size)
 {
 	int i;
 	int j, k;
@@ -351,8 +351,8 @@ static int kvp_key_delete(int pool, const char *key, int key_size)
 	return 1;
 }
 
-static int kvp_key_add_or_modify(int pool, const char *key, int key_size, const char *value,
-			int value_size)
+static int kvp_key_add_or_modify(int pool, const __u8 *key, int key_size,
+				 const __u8 *value, int value_size)
 {
 	int i;
 	int num_records;
@@ -405,7 +405,7 @@ static int kvp_key_add_or_modify(int pool, const char *key, int key_size, const
 	return 0;
 }
 
-static int kvp_get_value(int pool, const char *key, int key_size, char *value,
+static int kvp_get_value(int pool, const __u8 *key, int key_size, __u8 *value,
 			int value_size)
 {
 	int i;
@@ -437,8 +437,8 @@ static int kvp_get_value(int pool, const char *key, int key_size, char *value,
 	return 1;
 }
 
-static int kvp_pool_enumerate(int pool, int index, char *key, int key_size,
-				char *value, int value_size)
+static int kvp_pool_enumerate(int pool, int index, __u8 *key, int key_size,
+				__u8 *value, int value_size)
 {
 	struct kvp_record *record;
 
@@ -659,7 +659,7 @@ static char *kvp_if_name_to_mac(char *if_name)
 	char    *p, *x;
 	char    buf[256];
 	char addr_file[256];
-	int i;
+	unsigned int i;
 	char *mac_addr = NULL;
 
 	snprintf(addr_file, sizeof(addr_file), "%s%s%s", "/sys/class/net/",
@@ -698,7 +698,7 @@ static char *kvp_mac_to_if_name(char *mac)
 	char    buf[256];
 	char *kvp_net_dir = "/sys/class/net/";
 	char dev_id[256];
-	int i;
+	unsigned int i;
 
 	dir = opendir(kvp_net_dir);
 	if (dir == NULL)
@@ -748,7 +748,7 @@ static char *kvp_mac_to_if_name(char *mac)
 
 
 static void kvp_process_ipconfig_file(char *cmd,
-					char *config_buf, int len,
+					char *config_buf, unsigned int len,
 					int element_size, int offset)
 {
 	char buf[256];
@@ -766,7 +766,7 @@ static void kvp_process_ipconfig_file(char *cmd,
 	if (offset == 0)
 		memset(config_buf, 0, len);
 	while ((p = fgets(buf, sizeof(buf), file)) != NULL) {
-		if ((len - strlen(config_buf)) < (element_size + 1))
+		if (len < strlen(config_buf) + element_size + 1)
 			break;
 
 		x = strchr(p, '\n');
@@ -914,7 +914,7 @@ static int kvp_process_ip_address(void *addrp,
 
 static int
 kvp_get_ip_info(int family, char *if_name, int op,
-		 void  *out_buffer, int length)
+		 void  *out_buffer, unsigned int length)
 {
 	struct ifaddrs *ifap;
 	struct ifaddrs *curp;
@@ -1017,8 +1017,7 @@ kvp_get_ip_info(int family, char *if_name, int op,
 					weight += hweight32(&w[i]);
 
 				sprintf(cidr_mask, "/%d", weight);
-				if ((length - sn_offset) <
-					(strlen(cidr_mask) + 1))
+				if (length < sn_offset + strlen(cidr_mask) + 1)
 					goto gather_ipaddr;
 
 				if (sn_offset == 0)
Signature · 1 line
1.7.4.1
#4 lore raw

PATCH RESEND 4/5 Tools: hv: address compiler warnings for hv_fcopy_daemon.c

In reply to K. Y. Srinivasan

From: Vitaly Kuznetsov <[email protected]>

This patch addresses two types of compiler warnings:
... warning: unused variable .fd. [-Wunused-variable]
and
... warning: format .%s. expects argument of type .char *., but argument 5 has type .__u16 *. [-Wformat=]

---
 tools/hv/hv_fcopy_daemon.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
tools/hv/hv_fcopy_daemon.c +2 -2
index f437d73..1a23872 100644
@@ -51,7 +51,7 @@ static int hv_start_fcopy(struct hv_start_fcopy *smsg)
 
 	p = (char *)smsg->path_name;
 	snprintf(target_fname, sizeof(target_fname), "%s/%s",
-		(char *)smsg->path_name, smsg->file_name);
+		 (char *)smsg->path_name, (char *)smsg->file_name);
 
 	syslog(LOG_INFO, "Target file name: %s", target_fname);
 	/*
@@ -137,7 +137,7 @@ void print_usage(char *argv[])
 
 int main(int argc, char *argv[])
 {
-	int fd, fcopy_fd, len;
+	int fcopy_fd, len;
 	int error;
 	int daemonize = 1, long_index = 0, opt;
 	int version = FCOPY_CURRENT_VERSION;
Signature · 1 line
1.7.4.1
#5 lore raw

PATCH RESEND 5/5 Tools: hv: do not add redundant '/' in hv_start_fcopy()

In reply to K. Y. Srinivasan

From: Vitaly Kuznetsov <[email protected]>

We don't need to add additional '/' to smsg->path_name as snprintf("%s/%s") does the right thing. Without the patch we get doubled '//' in the log message.

---
 tools/hv/hv_fcopy_daemon.c |    6 ------
 1 files changed, 0 insertions(+), 6 deletions(-)
tools/hv/hv_fcopy_daemon.c +0 -6
index 1a23872..9445d8f 100644
@@ -43,12 +43,6 @@ static int hv_start_fcopy(struct hv_start_fcopy *smsg)
 	int error = HV_E_FAIL;
 	char *q, *p;
 
-	/*
-	 * If possile append a path seperator to the path.
-	 */
-	if (strlen((char *)smsg->path_name) < (W_MAX_PATH - 2))
-		strcat((char *)smsg->path_name, "/");
-
 	p = (char *)smsg->path_name;
 	snprintf(target_fname, sizeof(target_fname), "%s/%s",
 		 (char *)smsg->path_name, (char *)smsg->file_name);
Signature · 1 line
1.7.4.1
#7 lore raw

Re: [PATCH RESEND 1/5] Tools: hv: add mising fcopyd to the Makefile

Quoted 5 lines · Greg KH
Quoted 4 lines · K. Y. Srinivasan

From: Vitaly Kuznetsov <[email protected]>

fcopyd in missing in the Makefile, add it there.

Quoted 7 lines
Quoted 5 lines
---
 tools/hv/Makefile |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

This patch fails to apply :(

The was a mid-air collision with Matej's 'tools: hv: Makefile: Add hv_fcopy_daemon to Makefile' patch, feel free to drop this one.

Sorry for the inconvenience,

Signature · 1 line
  Vitaly