From e8ed6c78177fbbafa326d9efc590a51705848200 Mon Sep 17 00:00:00 2001 From: Bruce Richardson Date: Sat, 21 Jun 2014 00:34:30 +0100 Subject: [PATCH] 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. Signed-off-by: Bruce Richardson Acked-by: Thomas Monjalon --- 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 +- .../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 66c8fb9f08..404f51af6f 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 c67a0a51fc..739f2498dd 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 ea4a567d86..2401556a4e 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 227bba929a..bafd48790d 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 9d7d28e5dc..5ec99a2b10 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 78ed91d7c7..3ece2ac295 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 946fab4ac0..190151ed56 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 99469fecc0..42ef5f9115 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 9d8c8b0916..cc4c2c9e48 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 2d9b077a05..19a4f85ac7 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 535a1191f3..4c28d37d46 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 cb2d71ada7..565415af16 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 b93378425c..bbb8c5ba55 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 4ad76a7928..b130e668b9 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 b3a0b3607b..ae63bb9c37 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 89088e7893..2416e95534 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 6bc3998e1f..ade92ecb6d 100644 --- a/lib/librte_pmd_i40e/i40e_ethdev.c +++ b/lib/librte_pmd_i40e/i40e_ethdev.c @@ -1517,7 +1517,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; -- 2.20.1