DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] EAL: add format(printf) attrib. to appropriate fns
@ 2014-06-17 18:42 Bruce Richardson
  2014-06-19  8:37 ` Thomas Monjalon
  0 siblings, 1 reply; 8+ messages in thread
From: Bruce Richardson @ 2014-06-17 18:42 UTC (permalink / raw)
  To: dev

Mark the rte_log, cmdline_printf and rte_snprintf functions as
being printf-style functions. This causes compilation errors
due to mis-matched parameter types, so the parameter types are
fixed where appropriate.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 app/cmdline_test/commands.c                    |  2 +-
 app/test/test_cmdline_etheraddr.c              |  2 +-
 app/test/test_eal_flags.c                      |  3 ++-
 app/test/test_mp_secondary.c                   |  3 ++-
 examples/exception_path/main.c                 |  4 +--
 examples/netmap_compat/lib/compat_netmap.c     |  8 +++---
 examples/qos_sched/args.c                      | 12 ++++++---
 examples/qos_sched/init.c                      | 17 ++++++-------
 examples/qos_sched/main.c                      | 34 ++++++++++++++------------
 lib/librte_cmdline/cmdline.h                   |  3 ++-
 lib/librte_eal/common/include/rte_log.h        |  3 ++-
 lib/librte_eal/common/include/rte_string_fns.h |  3 ++-
 lib/librte_kni/rte_kni.c                       |  8 +++---
 13 files changed, 57 insertions(+), 45 deletions(-)

diff --git a/app/cmdline_test/commands.c b/app/cmdline_test/commands.c
index 66c8fb9..404f51a 100644
--- a/app/cmdline_test/commands.c
+++ b/app/cmdline_test/commands.c
@@ -321,7 +321,7 @@ cmd_get_history_bufsize_parsed(__attribute__((unused)) void *parsed_result,
 		struct cmdline *cl,
 		__attribute__((unused)) void *data)
 {
-	cmdline_printf(cl, "History buffer size: %u\n",
+	cmdline_printf(cl, "History buffer size: %zu\n",
 			sizeof(cl->rdl.history_buf));
 }
 
diff --git a/app/test/test_cmdline_etheraddr.c b/app/test/test_cmdline_etheraddr.c
index c67a0a5..739f249 100644
--- a/app/test/test_cmdline_etheraddr.c
+++ b/app/test/test_cmdline_etheraddr.c
@@ -147,7 +147,7 @@ test_parse_etheraddr_invalid_param(void)
 
 	/* copy string to buffer */
 	rte_snprintf(buf, sizeof(buf), "%s",
-			ether_addr_valid_strs[0]);
+			ether_addr_valid_strs[0].str);
 
 	ret = cmdline_parse_etheraddr(NULL, buf, NULL);
 	if (ret == -1) {
diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c
index ea4a567..2401556 100644
--- a/app/test/test_eal_flags.c
+++ b/app/test/test_eal_flags.c
@@ -268,7 +268,8 @@ get_current_prefix(char * prefix, int size)
 
 	/* copy string all the way from second char up to start of _config */
 	rte_snprintf(prefix, size, "%.*s",
-			strnlen(buf, sizeof(buf)) - sizeof("_config"), &buf[1]);
+			(int)(strnlen(buf, sizeof(buf)) - sizeof("_config")),
+			&buf[1]);
 
 	return prefix;
 }
diff --git a/app/test/test_mp_secondary.c b/app/test/test_mp_secondary.c
index 9d7d28e..5ec99a2 100644
--- a/app/test/test_mp_secondary.c
+++ b/app/test/test_mp_secondary.c
@@ -103,7 +103,8 @@ get_current_prefix(char * prefix, int size)
 
 	/* copy string all the way from second char up to start of _config */
 	rte_snprintf(prefix, size, "%.*s",
-			strnlen(buf, sizeof(buf)) - sizeof("_config"), &buf[1]);
+			(int)(strnlen(buf, sizeof(buf)) - sizeof("_config")),
+			&buf[1]);
 
 	return prefix;
 }
diff --git a/examples/exception_path/main.c b/examples/exception_path/main.c
index 78ed91d..3ece2ac 100644
--- a/examples/exception_path/main.c
+++ b/examples/exception_path/main.c
@@ -229,7 +229,7 @@ static int tap_create(char *name)
 	ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
 
 	if (name && *name)
-		rte_snprintf(ifr.ifr_name, IFNAMSIZ, name);
+		rte_snprintf(ifr.ifr_name, IFNAMSIZ, "%s", name);
 
 	ret = ioctl(fd, TUNSETIFF, (void *) &ifr);
 	if (ret < 0) {
@@ -238,7 +238,7 @@ static int tap_create(char *name)
 	}
 
 	if (name)
-		rte_snprintf(name, IFNAMSIZ, ifr.ifr_name);
+		rte_snprintf(name, IFNAMSIZ, "%s", ifr.ifr_name);
 
 	return fd;
 }
diff --git a/examples/netmap_compat/lib/compat_netmap.c b/examples/netmap_compat/lib/compat_netmap.c
index 946fab4..190151e 100644
--- a/examples/netmap_compat/lib/compat_netmap.c
+++ b/examples/netmap_compat/lib/compat_netmap.c
@@ -717,8 +717,8 @@ rte_netmap_init_port(uint8_t portid, const struct rte_netmap_port_conf *conf)
 
 		if (ret < 0) {
 			RTE_LOG(ERR, USER1,
-				"Couldn't configure TX queue %hhu of "
-				"port %hu\n",
+				"Couldn't configure TX queue %"PRIu16" of "
+				"port %"PRIu8"\n",
 				i, portid);
 			return (ret);
 		}
@@ -728,8 +728,8 @@ rte_netmap_init_port(uint8_t portid, const struct rte_netmap_port_conf *conf)
 
 		if (ret < 0) {
 			RTE_LOG(ERR, USER1,
-				"Couldn't configure RX queue %hu of "
-				"port %hhu\n",
+				"Couldn't configure RX queue %"PRIu16" of "
+				"port %"PRIu8"\n",
 				i, portid);
 			return (ret);
 		}
diff --git a/examples/qos_sched/args.c b/examples/qos_sched/args.c
index 99469fe..42ef5f9 100755
--- a/examples/qos_sched/args.c
+++ b/examples/qos_sched/args.c
@@ -264,17 +264,20 @@ app_parse_flow_conf(const char *conf_str)
 	}
 
 	if (pconf->rx_port >= RTE_MAX_ETHPORTS) {
-		RTE_LOG(ERR, APP, "pfc %u: invalid rx port %hu index\n", nb_pfc, pconf->rx_port);
+		RTE_LOG(ERR, APP, "pfc %u: invalid rx port %"PRIu8" index\n",
+				nb_pfc, pconf->rx_port);
 		return -1;
 	}
 	if (pconf->tx_port >= RTE_MAX_ETHPORTS) {
-		RTE_LOG(ERR, APP, "pfc %u: invalid tx port %hu index\n", nb_pfc, pconf->rx_port);
+		RTE_LOG(ERR, APP, "pfc %u: invalid tx port %"PRIu8" index\n",
+				nb_pfc, pconf->rx_port);
 		return -1;
 	}
 
 	mask = 1lu << pconf->rx_port;
 	if (app_used_rx_port_mask & mask) {
-		RTE_LOG(ERR, APP, "pfc %u: rx port %hu is used already\n", nb_pfc, pconf->rx_port);
+		RTE_LOG(ERR, APP, "pfc %u: rx port %"PRIu8" is used already\n",
+				nb_pfc, pconf->rx_port);
 		return -1;
 	}
 	app_used_rx_port_mask |= mask;
@@ -282,7 +285,8 @@ app_parse_flow_conf(const char *conf_str)
 
 	mask = 1lu << pconf->tx_port;
 	if (app_used_tx_port_mask & mask) {
-		RTE_LOG(ERR, APP, "pfc %u: port %hu is used already\n", nb_pfc, pconf->tx_port);
+		RTE_LOG(ERR, APP, "pfc %u: port %"PRIu8" is used already\n",
+				nb_pfc, pconf->tx_port);
 		return -1;
 	}
 	app_used_tx_port_mask |= mask;
diff --git a/examples/qos_sched/init.c b/examples/qos_sched/init.c
index 9d8c8b0..cc4c2c9 100755
--- a/examples/qos_sched/init.c
+++ b/examples/qos_sched/init.c
@@ -124,20 +124,20 @@ app_init_port(uint8_t portid, struct rte_mempool *mp)
 	tx_conf.txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS | ETH_TXQ_FLAGS_NOOFFLOADS;
 
 	/* init port */
-	RTE_LOG(INFO, APP, "Initializing port %hu... ", portid);
+	RTE_LOG(INFO, APP, "Initializing port %"PRIu8"... ", portid);
 	fflush(stdout);
 	ret = rte_eth_dev_configure(portid, 1, 1, &port_conf);
 	if (ret < 0)
-		rte_exit(EXIT_FAILURE, "Cannot configure device: err=%d, port=%hu\n",
-		ret, portid);
+		rte_exit(EXIT_FAILURE, "Cannot configure device: "
+				"err=%d, port=%"PRIu8"\n", ret, portid);
 
 	/* init one RX queue */
 	fflush(stdout);
 	ret = rte_eth_rx_queue_setup(portid, 0, (uint16_t)ring_conf.rx_size,
 		rte_eth_dev_socket_id(portid), &rx_conf, mp);
 	if (ret < 0)
-		rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup: err=%d, port=%hu\n",
-		ret, portid);
+		rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup: "
+				"err=%d, port=%"PRIu8"\n", ret, portid);
 
 	/* init one TX queue */
 	fflush(stdout);
@@ -145,14 +145,13 @@ app_init_port(uint8_t portid, struct rte_mempool *mp)
 		(uint16_t)ring_conf.tx_size, rte_eth_dev_socket_id(portid), &tx_conf);
 	if (ret < 0)
 		rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup: err=%d, "
-		"port=%hu queue=%d\n",
-		ret, portid, 0);
+				"port=%"PRIu8" queue=%d\n", ret, portid, 0);
 
 	/* Start device */
 	ret = rte_eth_dev_start(portid);
 	if (ret < 0)
-		rte_exit(EXIT_FAILURE, "rte_pmd_port_start: err=%d, port=%hu\n",
-		ret, portid);
+		rte_exit(EXIT_FAILURE, "rte_pmd_port_start: "
+				"err=%d, port=%"PRIu8"\n", ret, portid);
 
 	printf("done: ");
 
diff --git a/examples/qos_sched/main.c b/examples/qos_sched/main.c
index 2d9b077..19a4f85 100755
--- a/examples/qos_sched/main.c
+++ b/examples/qos_sched/main.c
@@ -125,8 +125,9 @@ app_main_loop(__attribute__((unused))void *dummy)
 	/* initialize mbuf memory */
 	if (mode == APP_RX_MODE) {
 		for (i = 0; i < rx_idx; i++) {
-			RTE_LOG(INFO, APP, "flow %u lcoreid %u reading port %hu\n",
-				i, lcore_id, rx_confs[i]->rx_port);
+			RTE_LOG(INFO, APP, "flow %u lcoreid %u "
+					"reading port %"PRIu8"\n",
+					i, lcore_id, rx_confs[i]->rx_port);
 		}
 
 		app_rx_thread(rx_confs);
@@ -139,8 +140,9 @@ app_main_loop(__attribute__((unused))void *dummy)
 			if (wt_confs[i]->m_table == NULL)
 				rte_panic("flow %u unable to allocate memory buffer\n", i);
 
-			RTE_LOG(INFO, APP, "flow %u lcoreid %u sched+write port %hu\n",
-				i, lcore_id, wt_confs[i]->tx_port);
+			RTE_LOG(INFO, APP, "flow %u lcoreid %u sched+write "
+					"port %"PRIu8"\n",
+					i, lcore_id, wt_confs[i]->tx_port);
 		}
 
 		app_mixed_thread(wt_confs);
@@ -153,8 +155,9 @@ app_main_loop(__attribute__((unused))void *dummy)
 			if (tx_confs[i]->m_table == NULL)
 				rte_panic("flow %u unable to allocate memory buffer\n", i);
 
-			RTE_LOG(INFO, APP, "flow %u lcoreid %u writing port %hu\n",
-				i, lcore_id, tx_confs[i]->tx_port);
+			RTE_LOG(INFO, APP, "flow %u lcoreid %u "
+					"writing port %"PRIu8"\n",
+					i, lcore_id, tx_confs[i]->tx_port);
 		}
 
 		app_tx_thread(tx_confs);
@@ -183,18 +186,19 @@ app_stat(void)
 		struct flow_conf *flow = &qos_conf[i];
 
 		rte_eth_stats_get(flow->rx_port, &stats);
-		printf("\nRX port %hu: rx: %"PRIu64 " err: %"PRIu64 " no_mbuf: %"PRIu64 "\n",
-			flow->rx_port,
-			stats.ipackets - rx_stats[i].ipackets,
-			stats.ierrors - rx_stats[i].ierrors,
-			stats.rx_nombuf - rx_stats[i].rx_nombuf);
+		printf("\nRX port %"PRIu8": rx: %"PRIu64 " err: %"PRIu64
+				" no_mbuf: %"PRIu64 "\n",
+				flow->rx_port,
+				stats.ipackets - rx_stats[i].ipackets,
+				stats.ierrors - rx_stats[i].ierrors,
+				stats.rx_nombuf - rx_stats[i].rx_nombuf);
 		memcpy(&rx_stats[i], &stats, sizeof(stats));
 
 		rte_eth_stats_get(flow->tx_port, &stats);
-		printf("TX port %hu: tx: %" PRIu64 " err: %" PRIu64 "\n",
-			flow->tx_port,
-			stats.opackets - tx_stats[i].opackets,
-			stats.oerrors - tx_stats[i].oerrors);
+		printf("TX port %"PRIu8": tx: %" PRIu64 " err: %" PRIu64 "\n",
+				flow->tx_port,
+				stats.opackets - tx_stats[i].opackets,
+				stats.oerrors - tx_stats[i].oerrors);
 		memcpy(&tx_stats[i], &stats, sizeof(stats));
 
 		//printf("MP = %d\n", rte_mempool_count(conf->app_pktmbuf_pool));
diff --git a/lib/librte_cmdline/cmdline.h b/lib/librte_cmdline/cmdline.h
index 535a119..4c28d37 100644
--- a/lib/librte_cmdline/cmdline.h
+++ b/lib/librte_cmdline/cmdline.h
@@ -79,7 +79,8 @@ struct cmdline {
 struct cmdline *cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_in, int s_out);
 void cmdline_set_prompt(struct cmdline *cl, const char *prompt);
 void cmdline_free(struct cmdline *cl);
-void cmdline_printf(const struct cmdline *cl, const char *fmt, ...);
+void cmdline_printf(const struct cmdline *cl, const char *fmt, ...)
+	__attribute__((format(printf,2,3)));
 int cmdline_in(struct cmdline *cl, const char *buf, int size);
 int cmdline_write_char(struct rdline *rdl, char c);
 void cmdline_interact(struct cmdline *cl);
diff --git a/lib/librte_eal/common/include/rte_log.h b/lib/librte_eal/common/include/rte_log.h
index cb2d71a..565415a 100644
--- a/lib/librte_eal/common/include/rte_log.h
+++ b/lib/librte_eal/common/include/rte_log.h
@@ -258,7 +258,8 @@ int rte_log(uint32_t level, uint32_t logtype, const char *format, ...)
  *   - 0: Success.
  *   - Negative on error.
  */
-int rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap);
+int rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap)
+	__attribute__((format(printf,3,0)));
 
 /**
  * Generates a log message.
diff --git a/lib/librte_eal/common/include/rte_string_fns.h b/lib/librte_eal/common/include/rte_string_fns.h
index b933784..bbb8c5b 100644
--- a/lib/librte_eal/common/include/rte_string_fns.h
+++ b/lib/librte_eal/common/include/rte_string_fns.h
@@ -68,7 +68,8 @@ extern "C" {
  *
  */
 int
-rte_snprintf(char *buffer, int buflen, const char *format, ...);
+rte_snprintf(char *buffer, int buflen, const char *format, ...)
+	__attribute__((format(printf,3,4)));
 
 /**
  * Takes string "string" parameter and splits it at character "delim"
diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c
index 89088e7..2416e95 100644
--- a/lib/librte_kni/rte_kni.c
+++ b/lib/librte_kni/rte_kni.c
@@ -158,7 +158,7 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
 		}
 	}
 
-	rte_snprintf(intf_name, RTE_KNI_NAMESIZE, conf->name);
+	rte_snprintf(intf_name, RTE_KNI_NAMESIZE, "%s", conf->name);
 	rte_snprintf(mz_name, RTE_MEMZONE_NAMESIZE, "KNI_INFO_%s", intf_name);
 	mz = kni_memzone_reserve(mz_name, sizeof(struct rte_kni),
 				SOCKET_ID_ANY, 0);
@@ -184,8 +184,8 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
 	dev_info.group_id = conf->group_id;
 	dev_info.mbuf_size = conf->mbuf_size;
 
-	rte_snprintf(ctx->name, RTE_KNI_NAMESIZE, intf_name);
-	rte_snprintf(dev_info.name, RTE_KNI_NAMESIZE, intf_name);
+	rte_snprintf(ctx->name, RTE_KNI_NAMESIZE, "%s", intf_name);
+	rte_snprintf(dev_info.name, RTE_KNI_NAMESIZE, "%s", intf_name);
 
 	RTE_LOG(INFO, KNI, "pci: %02x:%02x:%02x \t %02x:%02x\n",
 		dev_info.bus, dev_info.devid, dev_info.function,
@@ -291,7 +291,7 @@ rte_kni_release(struct rte_kni *kni)
 	if (!kni || !kni->in_use)
 		return -1;
 
-	rte_snprintf(dev_info.name, sizeof(dev_info.name), kni->name);
+	rte_snprintf(dev_info.name, sizeof(dev_info.name), "%s", kni->name);
 	if (ioctl(kni_fd, RTE_KNI_IOCTL_RELEASE, &dev_info) < 0) {
 		RTE_LOG(ERR, KNI, "Fail to release kni device\n");
 		return -1;
-- 
1.9.3

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [dpdk-dev] [PATCH] EAL: add format(printf) attrib. to appropriate fns
  2014-06-17 18:42 [dpdk-dev] [PATCH] EAL: add format(printf) attrib. to appropriate fns Bruce Richardson
@ 2014-06-19  8:37 ` Thomas Monjalon
  2014-06-19 18:21   ` [dpdk-dev] [PATCH v2] EAL: fix usage of printf-like functions Bruce Richardson
  0 siblings, 1 reply; 8+ messages in thread
From: Thomas Monjalon @ 2014-06-19  8:37 UTC (permalink / raw)
  To: Bruce Richardson; +Cc: dev

2014-06-17 19:42, Bruce Richardson:
> Mark the rte_log, cmdline_printf and rte_snprintf functions as
> being printf-style functions. This causes compilation errors
> due to mis-matched parameter types, so the parameter types are
> fixed where appropriate.
> 
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>

Nice cleanup.

2 comments:
- I think title should be "fix usage of printf-like functions"
- there are some errors in ivshmem code

-- 
Thomas

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [dpdk-dev] [PATCH v2] EAL: fix usage of printf-like functions
  2014-06-19  8:37 ` Thomas Monjalon
@ 2014-06-19 18:21   ` Bruce Richardson
  2014-06-20  8:24     ` De Lara Guarch, Pablo
  0 siblings, 1 reply; 8+ messages in thread
From: Bruce Richardson @ 2014-06-19 18:21 UTC (permalink / raw)
  To: dev

Mark the rte_log, cmdline_printf and rte_snprintf functions as
being printf-style functions. This causes compilation errors
due to mis-matched parameter types, so the parameter types are
fixed where appropriate.

Changes in V2:
* Additional fixes for ivshmem-target compilation

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 app/cmdline_test/commands.c                    |  2 +-
 app/test/test_cmdline_etheraddr.c              |  2 +-
 app/test/test_eal_flags.c                      |  3 ++-
 app/test/test_ivshmem.c                        |  3 ++-
 app/test/test_mp_secondary.c                   |  3 ++-
 examples/exception_path/main.c                 |  4 +--
 examples/netmap_compat/lib/compat_netmap.c     |  8 +++---
 examples/qos_sched/args.c                      | 12 ++++++---
 examples/qos_sched/init.c                      | 17 ++++++-------
 examples/qos_sched/main.c                      | 34 ++++++++++++++------------
 lib/librte_cmdline/cmdline.h                   |  3 ++-
 lib/librte_eal/common/include/rte_log.h        |  3 ++-
 lib/librte_eal/common/include/rte_string_fns.h |  3 ++-
 lib/librte_eal/linuxapp/eal/eal_ivshmem.c      |  2 +-
 lib/librte_ivshmem/rte_ivshmem.c               |  4 +--
 lib/librte_kni/rte_kni.c                       |  8 +++---
 16 files changed, 62 insertions(+), 49 deletions(-)

diff --git a/app/cmdline_test/commands.c b/app/cmdline_test/commands.c
index 66c8fb9..404f51a 100644
--- a/app/cmdline_test/commands.c
+++ b/app/cmdline_test/commands.c
@@ -321,7 +321,7 @@ cmd_get_history_bufsize_parsed(__attribute__((unused)) void *parsed_result,
 		struct cmdline *cl,
 		__attribute__((unused)) void *data)
 {
-	cmdline_printf(cl, "History buffer size: %u\n",
+	cmdline_printf(cl, "History buffer size: %zu\n",
 			sizeof(cl->rdl.history_buf));
 }
 
diff --git a/app/test/test_cmdline_etheraddr.c b/app/test/test_cmdline_etheraddr.c
index c67a0a5..739f249 100644
--- a/app/test/test_cmdline_etheraddr.c
+++ b/app/test/test_cmdline_etheraddr.c
@@ -147,7 +147,7 @@ test_parse_etheraddr_invalid_param(void)
 
 	/* copy string to buffer */
 	rte_snprintf(buf, sizeof(buf), "%s",
-			ether_addr_valid_strs[0]);
+			ether_addr_valid_strs[0].str);
 
 	ret = cmdline_parse_etheraddr(NULL, buf, NULL);
 	if (ret == -1) {
diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c
index ea4a567..2401556 100644
--- a/app/test/test_eal_flags.c
+++ b/app/test/test_eal_flags.c
@@ -268,7 +268,8 @@ get_current_prefix(char * prefix, int size)
 
 	/* copy string all the way from second char up to start of _config */
 	rte_snprintf(prefix, size, "%.*s",
-			strnlen(buf, sizeof(buf)) - sizeof("_config"), &buf[1]);
+			(int)(strnlen(buf, sizeof(buf)) - sizeof("_config")),
+			&buf[1]);
 
 	return prefix;
 }
diff --git a/app/test/test_ivshmem.c b/app/test/test_ivshmem.c
index 227bba9..bafd487 100644
--- a/app/test/test_ivshmem.c
+++ b/app/test/test_ivshmem.c
@@ -84,7 +84,8 @@ get_current_prefix(char * prefix, int size)
 
 	/* copy string all the way from second char up to start of _config */
 	rte_snprintf(prefix, size, "%.*s",
-			strnlen(buf, sizeof(buf)) - sizeof("_config"), &buf[1]);
+			(int)(strnlen(buf, sizeof(buf)) - sizeof("_config")),
+			&buf[1]);
 
 	return prefix;
 }
diff --git a/app/test/test_mp_secondary.c b/app/test/test_mp_secondary.c
index 9d7d28e..5ec99a2 100644
--- a/app/test/test_mp_secondary.c
+++ b/app/test/test_mp_secondary.c
@@ -103,7 +103,8 @@ get_current_prefix(char * prefix, int size)
 
 	/* copy string all the way from second char up to start of _config */
 	rte_snprintf(prefix, size, "%.*s",
-			strnlen(buf, sizeof(buf)) - sizeof("_config"), &buf[1]);
+			(int)(strnlen(buf, sizeof(buf)) - sizeof("_config")),
+			&buf[1]);
 
 	return prefix;
 }
diff --git a/examples/exception_path/main.c b/examples/exception_path/main.c
index 78ed91d..3ece2ac 100644
--- a/examples/exception_path/main.c
+++ b/examples/exception_path/main.c
@@ -229,7 +229,7 @@ static int tap_create(char *name)
 	ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
 
 	if (name && *name)
-		rte_snprintf(ifr.ifr_name, IFNAMSIZ, name);
+		rte_snprintf(ifr.ifr_name, IFNAMSIZ, "%s", name);
 
 	ret = ioctl(fd, TUNSETIFF, (void *) &ifr);
 	if (ret < 0) {
@@ -238,7 +238,7 @@ static int tap_create(char *name)
 	}
 
 	if (name)
-		rte_snprintf(name, IFNAMSIZ, ifr.ifr_name);
+		rte_snprintf(name, IFNAMSIZ, "%s", ifr.ifr_name);
 
 	return fd;
 }
diff --git a/examples/netmap_compat/lib/compat_netmap.c b/examples/netmap_compat/lib/compat_netmap.c
index 946fab4..190151e 100644
--- a/examples/netmap_compat/lib/compat_netmap.c
+++ b/examples/netmap_compat/lib/compat_netmap.c
@@ -717,8 +717,8 @@ rte_netmap_init_port(uint8_t portid, const struct rte_netmap_port_conf *conf)
 
 		if (ret < 0) {
 			RTE_LOG(ERR, USER1,
-				"Couldn't configure TX queue %hhu of "
-				"port %hu\n",
+				"Couldn't configure TX queue %"PRIu16" of "
+				"port %"PRIu8"\n",
 				i, portid);
 			return (ret);
 		}
@@ -728,8 +728,8 @@ rte_netmap_init_port(uint8_t portid, const struct rte_netmap_port_conf *conf)
 
 		if (ret < 0) {
 			RTE_LOG(ERR, USER1,
-				"Couldn't configure RX queue %hu of "
-				"port %hhu\n",
+				"Couldn't configure RX queue %"PRIu16" of "
+				"port %"PRIu8"\n",
 				i, portid);
 			return (ret);
 		}
diff --git a/examples/qos_sched/args.c b/examples/qos_sched/args.c
index 99469fe..42ef5f9 100755
--- a/examples/qos_sched/args.c
+++ b/examples/qos_sched/args.c
@@ -264,17 +264,20 @@ app_parse_flow_conf(const char *conf_str)
 	}
 
 	if (pconf->rx_port >= RTE_MAX_ETHPORTS) {
-		RTE_LOG(ERR, APP, "pfc %u: invalid rx port %hu index\n", nb_pfc, pconf->rx_port);
+		RTE_LOG(ERR, APP, "pfc %u: invalid rx port %"PRIu8" index\n",
+				nb_pfc, pconf->rx_port);
 		return -1;
 	}
 	if (pconf->tx_port >= RTE_MAX_ETHPORTS) {
-		RTE_LOG(ERR, APP, "pfc %u: invalid tx port %hu index\n", nb_pfc, pconf->rx_port);
+		RTE_LOG(ERR, APP, "pfc %u: invalid tx port %"PRIu8" index\n",
+				nb_pfc, pconf->rx_port);
 		return -1;
 	}
 
 	mask = 1lu << pconf->rx_port;
 	if (app_used_rx_port_mask & mask) {
-		RTE_LOG(ERR, APP, "pfc %u: rx port %hu is used already\n", nb_pfc, pconf->rx_port);
+		RTE_LOG(ERR, APP, "pfc %u: rx port %"PRIu8" is used already\n",
+				nb_pfc, pconf->rx_port);
 		return -1;
 	}
 	app_used_rx_port_mask |= mask;
@@ -282,7 +285,8 @@ app_parse_flow_conf(const char *conf_str)
 
 	mask = 1lu << pconf->tx_port;
 	if (app_used_tx_port_mask & mask) {
-		RTE_LOG(ERR, APP, "pfc %u: port %hu is used already\n", nb_pfc, pconf->tx_port);
+		RTE_LOG(ERR, APP, "pfc %u: port %"PRIu8" is used already\n",
+				nb_pfc, pconf->tx_port);
 		return -1;
 	}
 	app_used_tx_port_mask |= mask;
diff --git a/examples/qos_sched/init.c b/examples/qos_sched/init.c
index 9d8c8b0..cc4c2c9 100755
--- a/examples/qos_sched/init.c
+++ b/examples/qos_sched/init.c
@@ -124,20 +124,20 @@ app_init_port(uint8_t portid, struct rte_mempool *mp)
 	tx_conf.txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS | ETH_TXQ_FLAGS_NOOFFLOADS;
 
 	/* init port */
-	RTE_LOG(INFO, APP, "Initializing port %hu... ", portid);
+	RTE_LOG(INFO, APP, "Initializing port %"PRIu8"... ", portid);
 	fflush(stdout);
 	ret = rte_eth_dev_configure(portid, 1, 1, &port_conf);
 	if (ret < 0)
-		rte_exit(EXIT_FAILURE, "Cannot configure device: err=%d, port=%hu\n",
-		ret, portid);
+		rte_exit(EXIT_FAILURE, "Cannot configure device: "
+				"err=%d, port=%"PRIu8"\n", ret, portid);
 
 	/* init one RX queue */
 	fflush(stdout);
 	ret = rte_eth_rx_queue_setup(portid, 0, (uint16_t)ring_conf.rx_size,
 		rte_eth_dev_socket_id(portid), &rx_conf, mp);
 	if (ret < 0)
-		rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup: err=%d, port=%hu\n",
-		ret, portid);
+		rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup: "
+				"err=%d, port=%"PRIu8"\n", ret, portid);
 
 	/* init one TX queue */
 	fflush(stdout);
@@ -145,14 +145,13 @@ app_init_port(uint8_t portid, struct rte_mempool *mp)
 		(uint16_t)ring_conf.tx_size, rte_eth_dev_socket_id(portid), &tx_conf);
 	if (ret < 0)
 		rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup: err=%d, "
-		"port=%hu queue=%d\n",
-		ret, portid, 0);
+				"port=%"PRIu8" queue=%d\n", ret, portid, 0);
 
 	/* Start device */
 	ret = rte_eth_dev_start(portid);
 	if (ret < 0)
-		rte_exit(EXIT_FAILURE, "rte_pmd_port_start: err=%d, port=%hu\n",
-		ret, portid);
+		rte_exit(EXIT_FAILURE, "rte_pmd_port_start: "
+				"err=%d, port=%"PRIu8"\n", ret, portid);
 
 	printf("done: ");
 
diff --git a/examples/qos_sched/main.c b/examples/qos_sched/main.c
index 2d9b077..19a4f85 100755
--- a/examples/qos_sched/main.c
+++ b/examples/qos_sched/main.c
@@ -125,8 +125,9 @@ app_main_loop(__attribute__((unused))void *dummy)
 	/* initialize mbuf memory */
 	if (mode == APP_RX_MODE) {
 		for (i = 0; i < rx_idx; i++) {
-			RTE_LOG(INFO, APP, "flow %u lcoreid %u reading port %hu\n",
-				i, lcore_id, rx_confs[i]->rx_port);
+			RTE_LOG(INFO, APP, "flow %u lcoreid %u "
+					"reading port %"PRIu8"\n",
+					i, lcore_id, rx_confs[i]->rx_port);
 		}
 
 		app_rx_thread(rx_confs);
@@ -139,8 +140,9 @@ app_main_loop(__attribute__((unused))void *dummy)
 			if (wt_confs[i]->m_table == NULL)
 				rte_panic("flow %u unable to allocate memory buffer\n", i);
 
-			RTE_LOG(INFO, APP, "flow %u lcoreid %u sched+write port %hu\n",
-				i, lcore_id, wt_confs[i]->tx_port);
+			RTE_LOG(INFO, APP, "flow %u lcoreid %u sched+write "
+					"port %"PRIu8"\n",
+					i, lcore_id, wt_confs[i]->tx_port);
 		}
 
 		app_mixed_thread(wt_confs);
@@ -153,8 +155,9 @@ app_main_loop(__attribute__((unused))void *dummy)
 			if (tx_confs[i]->m_table == NULL)
 				rte_panic("flow %u unable to allocate memory buffer\n", i);
 
-			RTE_LOG(INFO, APP, "flow %u lcoreid %u writing port %hu\n",
-				i, lcore_id, tx_confs[i]->tx_port);
+			RTE_LOG(INFO, APP, "flow %u lcoreid %u "
+					"writing port %"PRIu8"\n",
+					i, lcore_id, tx_confs[i]->tx_port);
 		}
 
 		app_tx_thread(tx_confs);
@@ -183,18 +186,19 @@ app_stat(void)
 		struct flow_conf *flow = &qos_conf[i];
 
 		rte_eth_stats_get(flow->rx_port, &stats);
-		printf("\nRX port %hu: rx: %"PRIu64 " err: %"PRIu64 " no_mbuf: %"PRIu64 "\n",
-			flow->rx_port,
-			stats.ipackets - rx_stats[i].ipackets,
-			stats.ierrors - rx_stats[i].ierrors,
-			stats.rx_nombuf - rx_stats[i].rx_nombuf);
+		printf("\nRX port %"PRIu8": rx: %"PRIu64 " err: %"PRIu64
+				" no_mbuf: %"PRIu64 "\n",
+				flow->rx_port,
+				stats.ipackets - rx_stats[i].ipackets,
+				stats.ierrors - rx_stats[i].ierrors,
+				stats.rx_nombuf - rx_stats[i].rx_nombuf);
 		memcpy(&rx_stats[i], &stats, sizeof(stats));
 
 		rte_eth_stats_get(flow->tx_port, &stats);
-		printf("TX port %hu: tx: %" PRIu64 " err: %" PRIu64 "\n",
-			flow->tx_port,
-			stats.opackets - tx_stats[i].opackets,
-			stats.oerrors - tx_stats[i].oerrors);
+		printf("TX port %"PRIu8": tx: %" PRIu64 " err: %" PRIu64 "\n",
+				flow->tx_port,
+				stats.opackets - tx_stats[i].opackets,
+				stats.oerrors - tx_stats[i].oerrors);
 		memcpy(&tx_stats[i], &stats, sizeof(stats));
 
 		//printf("MP = %d\n", rte_mempool_count(conf->app_pktmbuf_pool));
diff --git a/lib/librte_cmdline/cmdline.h b/lib/librte_cmdline/cmdline.h
index 535a119..4c28d37 100644
--- a/lib/librte_cmdline/cmdline.h
+++ b/lib/librte_cmdline/cmdline.h
@@ -79,7 +79,8 @@ struct cmdline {
 struct cmdline *cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_in, int s_out);
 void cmdline_set_prompt(struct cmdline *cl, const char *prompt);
 void cmdline_free(struct cmdline *cl);
-void cmdline_printf(const struct cmdline *cl, const char *fmt, ...);
+void cmdline_printf(const struct cmdline *cl, const char *fmt, ...)
+	__attribute__((format(printf,2,3)));
 int cmdline_in(struct cmdline *cl, const char *buf, int size);
 int cmdline_write_char(struct rdline *rdl, char c);
 void cmdline_interact(struct cmdline *cl);
diff --git a/lib/librte_eal/common/include/rte_log.h b/lib/librte_eal/common/include/rte_log.h
index cb2d71a..565415a 100644
--- a/lib/librte_eal/common/include/rte_log.h
+++ b/lib/librte_eal/common/include/rte_log.h
@@ -258,7 +258,8 @@ int rte_log(uint32_t level, uint32_t logtype, const char *format, ...)
  *   - 0: Success.
  *   - Negative on error.
  */
-int rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap);
+int rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap)
+	__attribute__((format(printf,3,0)));
 
 /**
  * Generates a log message.
diff --git a/lib/librte_eal/common/include/rte_string_fns.h b/lib/librte_eal/common/include/rte_string_fns.h
index b933784..bbb8c5b 100644
--- a/lib/librte_eal/common/include/rte_string_fns.h
+++ b/lib/librte_eal/common/include/rte_string_fns.h
@@ -68,7 +68,8 @@ extern "C" {
  *
  */
 int
-rte_snprintf(char *buffer, int buflen, const char *format, ...);
+rte_snprintf(char *buffer, int buflen, const char *format, ...)
+	__attribute__((format(printf,3,4)));
 
 /**
  * Takes string "string" parameter and splits it at character "delim"
diff --git a/lib/librte_eal/linuxapp/eal/eal_ivshmem.c b/lib/librte_eal/linuxapp/eal/eal_ivshmem.c
index 4ad76a7..b130e66 100644
--- a/lib/librte_eal/linuxapp/eal/eal_ivshmem.c
+++ b/lib/librte_eal/linuxapp/eal/eal_ivshmem.c
@@ -918,7 +918,7 @@ int rte_eal_ivshmem_init(void)
 					ivshmem_config->pci_devs[ivshmem_config->pci_devs_idx].ioremap_addr = res->phys_addr;
 					rte_snprintf(ivshmem_config->pci_devs[ivshmem_config->pci_devs_idx].path,
 							sizeof(ivshmem_config->pci_devs[ivshmem_config->pci_devs_idx].path),
-							path);
+							"%s", path);
 
 					ivshmem_config->pci_devs_idx++;
 				}
diff --git a/lib/librte_ivshmem/rte_ivshmem.c b/lib/librte_ivshmem/rte_ivshmem.c
index b3a0b36..ae63bb9 100644
--- a/lib/librte_ivshmem/rte_ivshmem.c
+++ b/lib/librte_ivshmem/rte_ivshmem.c
@@ -777,7 +777,7 @@ rte_ivshmem_metadata_cmdline_generate(char *buffer, unsigned size, const char *n
 	/* add /dev/zero to command-line to fill the space */
 	tmplen = rte_snprintf(cmdline_ptr, remaining_len, IVSHMEM_QEMU_CMD_FD_FMT,
 			"/dev/zero",
-			0x0,
+			(uint64_t)0x0,
 			zero_size);
 
 	cmdline_ptr = RTE_PTR_ADD(cmdline_ptr, tmplen);
@@ -792,7 +792,7 @@ rte_ivshmem_metadata_cmdline_generate(char *buffer, unsigned size, const char *n
 	/* add metadata file to the end of command-line */
 	tmplen = rte_snprintf(cmdline_ptr, remaining_len, IVSHMEM_QEMU_CMD_FD_FMT,
 			cfg_file_path,
-			0x0,
+			(uint64_t)0x0,
 			METADATA_SIZE_ALIGNED);
 
 	cmdline_ptr = RTE_PTR_ADD(cmdline_ptr, tmplen);
diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c
index 89088e7..2416e95 100644
--- a/lib/librte_kni/rte_kni.c
+++ b/lib/librte_kni/rte_kni.c
@@ -158,7 +158,7 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
 		}
 	}
 
-	rte_snprintf(intf_name, RTE_KNI_NAMESIZE, conf->name);
+	rte_snprintf(intf_name, RTE_KNI_NAMESIZE, "%s", conf->name);
 	rte_snprintf(mz_name, RTE_MEMZONE_NAMESIZE, "KNI_INFO_%s", intf_name);
 	mz = kni_memzone_reserve(mz_name, sizeof(struct rte_kni),
 				SOCKET_ID_ANY, 0);
@@ -184,8 +184,8 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
 	dev_info.group_id = conf->group_id;
 	dev_info.mbuf_size = conf->mbuf_size;
 
-	rte_snprintf(ctx->name, RTE_KNI_NAMESIZE, intf_name);
-	rte_snprintf(dev_info.name, RTE_KNI_NAMESIZE, intf_name);
+	rte_snprintf(ctx->name, RTE_KNI_NAMESIZE, "%s", intf_name);
+	rte_snprintf(dev_info.name, RTE_KNI_NAMESIZE, "%s", intf_name);
 
 	RTE_LOG(INFO, KNI, "pci: %02x:%02x:%02x \t %02x:%02x\n",
 		dev_info.bus, dev_info.devid, dev_info.function,
@@ -291,7 +291,7 @@ rte_kni_release(struct rte_kni *kni)
 	if (!kni || !kni->in_use)
 		return -1;
 
-	rte_snprintf(dev_info.name, sizeof(dev_info.name), kni->name);
+	rte_snprintf(dev_info.name, sizeof(dev_info.name), "%s", kni->name);
 	if (ioctl(kni_fd, RTE_KNI_IOCTL_RELEASE, &dev_info) < 0) {
 		RTE_LOG(ERR, KNI, "Fail to release kni device\n");
 		return -1;
-- 
1.9.3

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [dpdk-dev] [PATCH v2] EAL: fix usage of printf-like functions
  2014-06-19 18:21   ` [dpdk-dev] [PATCH v2] EAL: fix usage of printf-like functions Bruce Richardson
@ 2014-06-20  8:24     ` De Lara Guarch, Pablo
  2014-06-20 23:34       ` [dpdk-dev] [PATCH v3] " Bruce Richardson
  0 siblings, 1 reply; 8+ messages in thread
From: De Lara Guarch, Pablo @ 2014-06-20  8:24 UTC (permalink / raw)
  To: Richardson, Bruce, dev



> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Bruce Richardson
> Sent: Thursday, June 19, 2014 7:22 PM
> To: dev@dpdk.org
> Subject: [dpdk-dev] [PATCH v2] EAL: fix usage of printf-like functions
> 
> Mark the rte_log, cmdline_printf and rte_snprintf functions as
> being printf-style functions. This causes compilation errors
> due to mis-matched parameter types, so the parameter types are
> fixed where appropriate.
> 
> Changes in V2:
> * Additional fixes for ivshmem-target compilation
> 
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> ---

This patch compiles correctly before the 1.7 rc1. After it, i40e library introduces a compilation error that can be fixed by making the following change:

--- a/lib/librte_pmd_i40e/i40e_ethdev.c
+++ b/lib/librte_pmd_i40e/i40e_ethdev.c
@@ -1536,7 +1536,7 @@ i40e_allocate_dma_mem_d(__attribute__((unused)) struct i40e_hw *hw,
                return I40E_ERR_PARAM;

        id++;
-       rte_snprintf(z_name, sizeof(z_name), "i40e_dma_%lu", id);
+       rte_snprintf(z_name, sizeof(z_name), "i40e_dma_%"PRIu64, id);
        mz = rte_memzone_reserve_aligned(z_name, size, 0, 0, alignment);
        if (!mz)
                return I40E_ERR_NO_MEMORY;

Thanks,
Pablo

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [dpdk-dev] [PATCH v3] EAL: fix usage of printf-like functions
  2014-06-20  8:24     ` De Lara Guarch, Pablo
@ 2014-06-20 23:34       ` Bruce Richardson
  2014-06-20 23:58         ` Stephen Hemminger
  2014-06-27  0:48         ` Thomas Monjalon
  0 siblings, 2 replies; 8+ messages in thread
From: Bruce Richardson @ 2014-06-20 23:34 UTC (permalink / raw)
  To: dev

Mark the rte_log, cmdline_printf and rte_snprintf functions as
being printf-style functions. This causes compilation errors
due to mis-matched parameter types, so the parameter types are
fixed where appropriate.

Changes in V2:
* Additional fixes for ivshmem-target compilation

Changes in V3:
* additional printf-format fix for i40e driver as pointed out by Pablo De Lara

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 app/cmdline_test/commands.c                    |  2 +-
 app/test/test_cmdline_etheraddr.c              |  2 +-
 app/test/test_eal_flags.c                      |  3 ++-
 app/test/test_ivshmem.c                        |  3 ++-
 app/test/test_mp_secondary.c                   |  3 ++-
 examples/exception_path/main.c                 |  4 +--
 examples/netmap_compat/lib/compat_netmap.c     |  8 +++---
 examples/qos_sched/args.c                      | 12 ++++++---
 examples/qos_sched/init.c                      | 17 ++++++-------
 examples/qos_sched/main.c                      | 34 ++++++++++++++------------
 lib/librte_cmdline/cmdline.h                   |  3 ++-
 lib/librte_eal/common/include/rte_log.h        |  3 ++-
 lib/librte_eal/common/include/rte_string_fns.h |  3 ++-
 lib/librte_eal/linuxapp/eal/eal_ivshmem.c      |  2 +-
 lib/librte_ivshmem/rte_ivshmem.c               |  4 +--
 lib/librte_kni/rte_kni.c                       |  8 +++---
 lib/librte_pmd_i40e/i40e_ethdev.c              |  2 +-
 17 files changed, 63 insertions(+), 50 deletions(-)

diff --git a/app/cmdline_test/commands.c b/app/cmdline_test/commands.c
index 66c8fb9..404f51a 100644
--- a/app/cmdline_test/commands.c
+++ b/app/cmdline_test/commands.c
@@ -321,7 +321,7 @@ cmd_get_history_bufsize_parsed(__attribute__((unused)) void *parsed_result,
 		struct cmdline *cl,
 		__attribute__((unused)) void *data)
 {
-	cmdline_printf(cl, "History buffer size: %u\n",
+	cmdline_printf(cl, "History buffer size: %zu\n",
 			sizeof(cl->rdl.history_buf));
 }
 
diff --git a/app/test/test_cmdline_etheraddr.c b/app/test/test_cmdline_etheraddr.c
index c67a0a5..739f249 100644
--- a/app/test/test_cmdline_etheraddr.c
+++ b/app/test/test_cmdline_etheraddr.c
@@ -147,7 +147,7 @@ test_parse_etheraddr_invalid_param(void)
 
 	/* copy string to buffer */
 	rte_snprintf(buf, sizeof(buf), "%s",
-			ether_addr_valid_strs[0]);
+			ether_addr_valid_strs[0].str);
 
 	ret = cmdline_parse_etheraddr(NULL, buf, NULL);
 	if (ret == -1) {
diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c
index ea4a567..2401556 100644
--- a/app/test/test_eal_flags.c
+++ b/app/test/test_eal_flags.c
@@ -268,7 +268,8 @@ get_current_prefix(char * prefix, int size)
 
 	/* copy string all the way from second char up to start of _config */
 	rte_snprintf(prefix, size, "%.*s",
-			strnlen(buf, sizeof(buf)) - sizeof("_config"), &buf[1]);
+			(int)(strnlen(buf, sizeof(buf)) - sizeof("_config")),
+			&buf[1]);
 
 	return prefix;
 }
diff --git a/app/test/test_ivshmem.c b/app/test/test_ivshmem.c
index 227bba9..bafd487 100644
--- a/app/test/test_ivshmem.c
+++ b/app/test/test_ivshmem.c
@@ -84,7 +84,8 @@ get_current_prefix(char * prefix, int size)
 
 	/* copy string all the way from second char up to start of _config */
 	rte_snprintf(prefix, size, "%.*s",
-			strnlen(buf, sizeof(buf)) - sizeof("_config"), &buf[1]);
+			(int)(strnlen(buf, sizeof(buf)) - sizeof("_config")),
+			&buf[1]);
 
 	return prefix;
 }
diff --git a/app/test/test_mp_secondary.c b/app/test/test_mp_secondary.c
index 9d7d28e..5ec99a2 100644
--- a/app/test/test_mp_secondary.c
+++ b/app/test/test_mp_secondary.c
@@ -103,7 +103,8 @@ get_current_prefix(char * prefix, int size)
 
 	/* copy string all the way from second char up to start of _config */
 	rte_snprintf(prefix, size, "%.*s",
-			strnlen(buf, sizeof(buf)) - sizeof("_config"), &buf[1]);
+			(int)(strnlen(buf, sizeof(buf)) - sizeof("_config")),
+			&buf[1]);
 
 	return prefix;
 }
diff --git a/examples/exception_path/main.c b/examples/exception_path/main.c
index 78ed91d..3ece2ac 100644
--- a/examples/exception_path/main.c
+++ b/examples/exception_path/main.c
@@ -229,7 +229,7 @@ static int tap_create(char *name)
 	ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
 
 	if (name && *name)
-		rte_snprintf(ifr.ifr_name, IFNAMSIZ, name);
+		rte_snprintf(ifr.ifr_name, IFNAMSIZ, "%s", name);
 
 	ret = ioctl(fd, TUNSETIFF, (void *) &ifr);
 	if (ret < 0) {
@@ -238,7 +238,7 @@ static int tap_create(char *name)
 	}
 
 	if (name)
-		rte_snprintf(name, IFNAMSIZ, ifr.ifr_name);
+		rte_snprintf(name, IFNAMSIZ, "%s", ifr.ifr_name);
 
 	return fd;
 }
diff --git a/examples/netmap_compat/lib/compat_netmap.c b/examples/netmap_compat/lib/compat_netmap.c
index 946fab4..190151e 100644
--- a/examples/netmap_compat/lib/compat_netmap.c
+++ b/examples/netmap_compat/lib/compat_netmap.c
@@ -717,8 +717,8 @@ rte_netmap_init_port(uint8_t portid, const struct rte_netmap_port_conf *conf)
 
 		if (ret < 0) {
 			RTE_LOG(ERR, USER1,
-				"Couldn't configure TX queue %hhu of "
-				"port %hu\n",
+				"Couldn't configure TX queue %"PRIu16" of "
+				"port %"PRIu8"\n",
 				i, portid);
 			return (ret);
 		}
@@ -728,8 +728,8 @@ rte_netmap_init_port(uint8_t portid, const struct rte_netmap_port_conf *conf)
 
 		if (ret < 0) {
 			RTE_LOG(ERR, USER1,
-				"Couldn't configure RX queue %hu of "
-				"port %hhu\n",
+				"Couldn't configure RX queue %"PRIu16" of "
+				"port %"PRIu8"\n",
 				i, portid);
 			return (ret);
 		}
diff --git a/examples/qos_sched/args.c b/examples/qos_sched/args.c
index 99469fe..42ef5f9 100755
--- a/examples/qos_sched/args.c
+++ b/examples/qos_sched/args.c
@@ -264,17 +264,20 @@ app_parse_flow_conf(const char *conf_str)
 	}
 
 	if (pconf->rx_port >= RTE_MAX_ETHPORTS) {
-		RTE_LOG(ERR, APP, "pfc %u: invalid rx port %hu index\n", nb_pfc, pconf->rx_port);
+		RTE_LOG(ERR, APP, "pfc %u: invalid rx port %"PRIu8" index\n",
+				nb_pfc, pconf->rx_port);
 		return -1;
 	}
 	if (pconf->tx_port >= RTE_MAX_ETHPORTS) {
-		RTE_LOG(ERR, APP, "pfc %u: invalid tx port %hu index\n", nb_pfc, pconf->rx_port);
+		RTE_LOG(ERR, APP, "pfc %u: invalid tx port %"PRIu8" index\n",
+				nb_pfc, pconf->rx_port);
 		return -1;
 	}
 
 	mask = 1lu << pconf->rx_port;
 	if (app_used_rx_port_mask & mask) {
-		RTE_LOG(ERR, APP, "pfc %u: rx port %hu is used already\n", nb_pfc, pconf->rx_port);
+		RTE_LOG(ERR, APP, "pfc %u: rx port %"PRIu8" is used already\n",
+				nb_pfc, pconf->rx_port);
 		return -1;
 	}
 	app_used_rx_port_mask |= mask;
@@ -282,7 +285,8 @@ app_parse_flow_conf(const char *conf_str)
 
 	mask = 1lu << pconf->tx_port;
 	if (app_used_tx_port_mask & mask) {
-		RTE_LOG(ERR, APP, "pfc %u: port %hu is used already\n", nb_pfc, pconf->tx_port);
+		RTE_LOG(ERR, APP, "pfc %u: port %"PRIu8" is used already\n",
+				nb_pfc, pconf->tx_port);
 		return -1;
 	}
 	app_used_tx_port_mask |= mask;
diff --git a/examples/qos_sched/init.c b/examples/qos_sched/init.c
index 9d8c8b0..cc4c2c9 100755
--- a/examples/qos_sched/init.c
+++ b/examples/qos_sched/init.c
@@ -124,20 +124,20 @@ app_init_port(uint8_t portid, struct rte_mempool *mp)
 	tx_conf.txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS | ETH_TXQ_FLAGS_NOOFFLOADS;
 
 	/* init port */
-	RTE_LOG(INFO, APP, "Initializing port %hu... ", portid);
+	RTE_LOG(INFO, APP, "Initializing port %"PRIu8"... ", portid);
 	fflush(stdout);
 	ret = rte_eth_dev_configure(portid, 1, 1, &port_conf);
 	if (ret < 0)
-		rte_exit(EXIT_FAILURE, "Cannot configure device: err=%d, port=%hu\n",
-		ret, portid);
+		rte_exit(EXIT_FAILURE, "Cannot configure device: "
+				"err=%d, port=%"PRIu8"\n", ret, portid);
 
 	/* init one RX queue */
 	fflush(stdout);
 	ret = rte_eth_rx_queue_setup(portid, 0, (uint16_t)ring_conf.rx_size,
 		rte_eth_dev_socket_id(portid), &rx_conf, mp);
 	if (ret < 0)
-		rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup: err=%d, port=%hu\n",
-		ret, portid);
+		rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup: "
+				"err=%d, port=%"PRIu8"\n", ret, portid);
 
 	/* init one TX queue */
 	fflush(stdout);
@@ -145,14 +145,13 @@ app_init_port(uint8_t portid, struct rte_mempool *mp)
 		(uint16_t)ring_conf.tx_size, rte_eth_dev_socket_id(portid), &tx_conf);
 	if (ret < 0)
 		rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup: err=%d, "
-		"port=%hu queue=%d\n",
-		ret, portid, 0);
+				"port=%"PRIu8" queue=%d\n", ret, portid, 0);
 
 	/* Start device */
 	ret = rte_eth_dev_start(portid);
 	if (ret < 0)
-		rte_exit(EXIT_FAILURE, "rte_pmd_port_start: err=%d, port=%hu\n",
-		ret, portid);
+		rte_exit(EXIT_FAILURE, "rte_pmd_port_start: "
+				"err=%d, port=%"PRIu8"\n", ret, portid);
 
 	printf("done: ");
 
diff --git a/examples/qos_sched/main.c b/examples/qos_sched/main.c
index 2d9b077..19a4f85 100755
--- a/examples/qos_sched/main.c
+++ b/examples/qos_sched/main.c
@@ -125,8 +125,9 @@ app_main_loop(__attribute__((unused))void *dummy)
 	/* initialize mbuf memory */
 	if (mode == APP_RX_MODE) {
 		for (i = 0; i < rx_idx; i++) {
-			RTE_LOG(INFO, APP, "flow %u lcoreid %u reading port %hu\n",
-				i, lcore_id, rx_confs[i]->rx_port);
+			RTE_LOG(INFO, APP, "flow %u lcoreid %u "
+					"reading port %"PRIu8"\n",
+					i, lcore_id, rx_confs[i]->rx_port);
 		}
 
 		app_rx_thread(rx_confs);
@@ -139,8 +140,9 @@ app_main_loop(__attribute__((unused))void *dummy)
 			if (wt_confs[i]->m_table == NULL)
 				rte_panic("flow %u unable to allocate memory buffer\n", i);
 
-			RTE_LOG(INFO, APP, "flow %u lcoreid %u sched+write port %hu\n",
-				i, lcore_id, wt_confs[i]->tx_port);
+			RTE_LOG(INFO, APP, "flow %u lcoreid %u sched+write "
+					"port %"PRIu8"\n",
+					i, lcore_id, wt_confs[i]->tx_port);
 		}
 
 		app_mixed_thread(wt_confs);
@@ -153,8 +155,9 @@ app_main_loop(__attribute__((unused))void *dummy)
 			if (tx_confs[i]->m_table == NULL)
 				rte_panic("flow %u unable to allocate memory buffer\n", i);
 
-			RTE_LOG(INFO, APP, "flow %u lcoreid %u writing port %hu\n",
-				i, lcore_id, tx_confs[i]->tx_port);
+			RTE_LOG(INFO, APP, "flow %u lcoreid %u "
+					"writing port %"PRIu8"\n",
+					i, lcore_id, tx_confs[i]->tx_port);
 		}
 
 		app_tx_thread(tx_confs);
@@ -183,18 +186,19 @@ app_stat(void)
 		struct flow_conf *flow = &qos_conf[i];
 
 		rte_eth_stats_get(flow->rx_port, &stats);
-		printf("\nRX port %hu: rx: %"PRIu64 " err: %"PRIu64 " no_mbuf: %"PRIu64 "\n",
-			flow->rx_port,
-			stats.ipackets - rx_stats[i].ipackets,
-			stats.ierrors - rx_stats[i].ierrors,
-			stats.rx_nombuf - rx_stats[i].rx_nombuf);
+		printf("\nRX port %"PRIu8": rx: %"PRIu64 " err: %"PRIu64
+				" no_mbuf: %"PRIu64 "\n",
+				flow->rx_port,
+				stats.ipackets - rx_stats[i].ipackets,
+				stats.ierrors - rx_stats[i].ierrors,
+				stats.rx_nombuf - rx_stats[i].rx_nombuf);
 		memcpy(&rx_stats[i], &stats, sizeof(stats));
 
 		rte_eth_stats_get(flow->tx_port, &stats);
-		printf("TX port %hu: tx: %" PRIu64 " err: %" PRIu64 "\n",
-			flow->tx_port,
-			stats.opackets - tx_stats[i].opackets,
-			stats.oerrors - tx_stats[i].oerrors);
+		printf("TX port %"PRIu8": tx: %" PRIu64 " err: %" PRIu64 "\n",
+				flow->tx_port,
+				stats.opackets - tx_stats[i].opackets,
+				stats.oerrors - tx_stats[i].oerrors);
 		memcpy(&tx_stats[i], &stats, sizeof(stats));
 
 		//printf("MP = %d\n", rte_mempool_count(conf->app_pktmbuf_pool));
diff --git a/lib/librte_cmdline/cmdline.h b/lib/librte_cmdline/cmdline.h
index 535a119..4c28d37 100644
--- a/lib/librte_cmdline/cmdline.h
+++ b/lib/librte_cmdline/cmdline.h
@@ -79,7 +79,8 @@ struct cmdline {
 struct cmdline *cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_in, int s_out);
 void cmdline_set_prompt(struct cmdline *cl, const char *prompt);
 void cmdline_free(struct cmdline *cl);
-void cmdline_printf(const struct cmdline *cl, const char *fmt, ...);
+void cmdline_printf(const struct cmdline *cl, const char *fmt, ...)
+	__attribute__((format(printf,2,3)));
 int cmdline_in(struct cmdline *cl, const char *buf, int size);
 int cmdline_write_char(struct rdline *rdl, char c);
 void cmdline_interact(struct cmdline *cl);
diff --git a/lib/librte_eal/common/include/rte_log.h b/lib/librte_eal/common/include/rte_log.h
index cb2d71a..565415a 100644
--- a/lib/librte_eal/common/include/rte_log.h
+++ b/lib/librte_eal/common/include/rte_log.h
@@ -258,7 +258,8 @@ int rte_log(uint32_t level, uint32_t logtype, const char *format, ...)
  *   - 0: Success.
  *   - Negative on error.
  */
-int rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap);
+int rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap)
+	__attribute__((format(printf,3,0)));
 
 /**
  * Generates a log message.
diff --git a/lib/librte_eal/common/include/rte_string_fns.h b/lib/librte_eal/common/include/rte_string_fns.h
index b933784..bbb8c5b 100644
--- a/lib/librte_eal/common/include/rte_string_fns.h
+++ b/lib/librte_eal/common/include/rte_string_fns.h
@@ -68,7 +68,8 @@ extern "C" {
  *
  */
 int
-rte_snprintf(char *buffer, int buflen, const char *format, ...);
+rte_snprintf(char *buffer, int buflen, const char *format, ...)
+	__attribute__((format(printf,3,4)));
 
 /**
  * Takes string "string" parameter and splits it at character "delim"
diff --git a/lib/librte_eal/linuxapp/eal/eal_ivshmem.c b/lib/librte_eal/linuxapp/eal/eal_ivshmem.c
index 4ad76a7..b130e66 100644
--- a/lib/librte_eal/linuxapp/eal/eal_ivshmem.c
+++ b/lib/librte_eal/linuxapp/eal/eal_ivshmem.c
@@ -918,7 +918,7 @@ int rte_eal_ivshmem_init(void)
 					ivshmem_config->pci_devs[ivshmem_config->pci_devs_idx].ioremap_addr = res->phys_addr;
 					rte_snprintf(ivshmem_config->pci_devs[ivshmem_config->pci_devs_idx].path,
 							sizeof(ivshmem_config->pci_devs[ivshmem_config->pci_devs_idx].path),
-							path);
+							"%s", path);
 
 					ivshmem_config->pci_devs_idx++;
 				}
diff --git a/lib/librte_ivshmem/rte_ivshmem.c b/lib/librte_ivshmem/rte_ivshmem.c
index b3a0b36..ae63bb9 100644
--- a/lib/librte_ivshmem/rte_ivshmem.c
+++ b/lib/librte_ivshmem/rte_ivshmem.c
@@ -777,7 +777,7 @@ rte_ivshmem_metadata_cmdline_generate(char *buffer, unsigned size, const char *n
 	/* add /dev/zero to command-line to fill the space */
 	tmplen = rte_snprintf(cmdline_ptr, remaining_len, IVSHMEM_QEMU_CMD_FD_FMT,
 			"/dev/zero",
-			0x0,
+			(uint64_t)0x0,
 			zero_size);
 
 	cmdline_ptr = RTE_PTR_ADD(cmdline_ptr, tmplen);
@@ -792,7 +792,7 @@ rte_ivshmem_metadata_cmdline_generate(char *buffer, unsigned size, const char *n
 	/* add metadata file to the end of command-line */
 	tmplen = rte_snprintf(cmdline_ptr, remaining_len, IVSHMEM_QEMU_CMD_FD_FMT,
 			cfg_file_path,
-			0x0,
+			(uint64_t)0x0,
 			METADATA_SIZE_ALIGNED);
 
 	cmdline_ptr = RTE_PTR_ADD(cmdline_ptr, tmplen);
diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c
index 89088e7..2416e95 100644
--- a/lib/librte_kni/rte_kni.c
+++ b/lib/librte_kni/rte_kni.c
@@ -158,7 +158,7 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
 		}
 	}
 
-	rte_snprintf(intf_name, RTE_KNI_NAMESIZE, conf->name);
+	rte_snprintf(intf_name, RTE_KNI_NAMESIZE, "%s", conf->name);
 	rte_snprintf(mz_name, RTE_MEMZONE_NAMESIZE, "KNI_INFO_%s", intf_name);
 	mz = kni_memzone_reserve(mz_name, sizeof(struct rte_kni),
 				SOCKET_ID_ANY, 0);
@@ -184,8 +184,8 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
 	dev_info.group_id = conf->group_id;
 	dev_info.mbuf_size = conf->mbuf_size;
 
-	rte_snprintf(ctx->name, RTE_KNI_NAMESIZE, intf_name);
-	rte_snprintf(dev_info.name, RTE_KNI_NAMESIZE, intf_name);
+	rte_snprintf(ctx->name, RTE_KNI_NAMESIZE, "%s", intf_name);
+	rte_snprintf(dev_info.name, RTE_KNI_NAMESIZE, "%s", intf_name);
 
 	RTE_LOG(INFO, KNI, "pci: %02x:%02x:%02x \t %02x:%02x\n",
 		dev_info.bus, dev_info.devid, dev_info.function,
@@ -291,7 +291,7 @@ rte_kni_release(struct rte_kni *kni)
 	if (!kni || !kni->in_use)
 		return -1;
 
-	rte_snprintf(dev_info.name, sizeof(dev_info.name), kni->name);
+	rte_snprintf(dev_info.name, sizeof(dev_info.name), "%s", kni->name);
 	if (ioctl(kni_fd, RTE_KNI_IOCTL_RELEASE, &dev_info) < 0) {
 		RTE_LOG(ERR, KNI, "Fail to release kni device\n");
 		return -1;
diff --git a/lib/librte_pmd_i40e/i40e_ethdev.c b/lib/librte_pmd_i40e/i40e_ethdev.c
index 1b4e822..3880fd3 100644
--- a/lib/librte_pmd_i40e/i40e_ethdev.c
+++ b/lib/librte_pmd_i40e/i40e_ethdev.c
@@ -1513,7 +1513,7 @@ i40e_allocate_dma_mem_d(__attribute__((unused)) struct i40e_hw *hw,
 		return I40E_ERR_PARAM;
 
 	id++;
-	rte_snprintf(z_name, sizeof(z_name), "i40e_dma_%lu", id);
+	rte_snprintf(z_name, sizeof(z_name), "i40e_dma_%"PRIu64, id);
 	mz = rte_memzone_reserve_aligned(z_name, size, 0, 0, alignment);
 	if (!mz)
 		return I40E_ERR_NO_MEMORY;
-- 
1.9.3

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [dpdk-dev] [PATCH v3] EAL: fix usage of printf-like functions
  2014-06-20 23:34       ` [dpdk-dev] [PATCH v3] " Bruce Richardson
@ 2014-06-20 23:58         ` Stephen Hemminger
  2014-06-21  0:02           ` Richardson, Bruce
  2014-06-27  0:48         ` Thomas Monjalon
  1 sibling, 1 reply; 8+ messages in thread
From: Stephen Hemminger @ 2014-06-20 23:58 UTC (permalink / raw)
  To: Bruce Richardson; +Cc: dev

On Sat, 21 Jun 2014 00:34:30 +0100
Bruce Richardson <bruce.richardson@intel.com> wrote:

> +			(int)(strnlen(buf, sizeof(buf)) - sizeof("_config")),

minor nit, paren not needed here
			(int)strnlen(buf, sizeof...)

better yet change rte_snprintf() to take a size_t to make it compatiable with snprintf

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [dpdk-dev] [PATCH v3] EAL: fix usage of printf-like functions
  2014-06-20 23:58         ` Stephen Hemminger
@ 2014-06-21  0:02           ` Richardson, Bruce
  0 siblings, 0 replies; 8+ messages in thread
From: Richardson, Bruce @ 2014-06-21  0:02 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: dev

> -----Original Message-----
> From: Stephen Hemminger [mailto:stephen@networkplumber.org]
> Sent: Friday, June 20, 2014 4:58 PM
> To: Richardson, Bruce
> Cc: dev@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH v3] EAL: fix usage of printf-like functions
> 
> On Sat, 21 Jun 2014 00:34:30 +0100
> Bruce Richardson <bruce.richardson@intel.com> wrote:
> 
> > +			(int)(strnlen(buf, sizeof(buf)) - sizeof("_config")),
> 
> minor nit, paren not needed here
> 			(int)strnlen(buf, sizeof...)
> 
> better yet change rte_snprintf() to take a size_t to make it compatiable with
> snprintf

Removing the paren still gives the same error, as the whole expression needs to be int, not just the first part of it. 
As for acception size_t vs int, the errors about the type come from the compiler based on its understanding of the printf format, not from anything we have done with rte_snprintf, so I'm not sure how we could change things to make size_t values acceptable here.

/Bruce

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [dpdk-dev] [PATCH v3] EAL: fix usage of printf-like functions
  2014-06-20 23:34       ` [dpdk-dev] [PATCH v3] " Bruce Richardson
  2014-06-20 23:58         ` Stephen Hemminger
@ 2014-06-27  0:48         ` Thomas Monjalon
  1 sibling, 0 replies; 8+ messages in thread
From: Thomas Monjalon @ 2014-06-27  0:48 UTC (permalink / raw)
  To: Bruce Richardson; +Cc: dev

> Mark the rte_log, cmdline_printf and rte_snprintf functions as
> being printf-style functions. This causes compilation errors
> due to mis-matched parameter types, so the parameter types are
> fixed where appropriate.
> 
> Changes in V2:
> * Additional fixes for ivshmem-target compilation
> 
> Changes in V3:
> * additional printf-format fix for i40e driver as pointed out by Pablo De
> Lara
> 
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>

Acked-by: Thomas Monjalon <thomas.monjalon@6wind.com>

Applied for version 1.7.0.

Thanks
-- 
Thomas

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-06-27  0:48 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-17 18:42 [dpdk-dev] [PATCH] EAL: add format(printf) attrib. to appropriate fns Bruce Richardson
2014-06-19  8:37 ` Thomas Monjalon
2014-06-19 18:21   ` [dpdk-dev] [PATCH v2] EAL: fix usage of printf-like functions Bruce Richardson
2014-06-20  8:24     ` De Lara Guarch, Pablo
2014-06-20 23:34       ` [dpdk-dev] [PATCH v3] " Bruce Richardson
2014-06-20 23:58         ` Stephen Hemminger
2014-06-21  0:02           ` Richardson, Bruce
2014-06-27  0:48         ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).