[dpdk-dev] [PATCH] EAL: add format(printf) attrib. to appropriate fns

Bruce Richardson bruce.richardson at intel.com
Tue Jun 17 20:42:42 CEST 2014


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 at 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



More information about the dev mailing list