examples/vm_power_manager: add missing <stdlib.h> header include for strtol
PATCH RESEND 1/1 examples/vm_power_manager: add missing <stdlib.h> header include for strtol
From: Guillaume Gardet <[email protected]>
strtol is defined in stdlib.h
Fixes the following build failure:
../examples/vm_power_manager/guest_cli/vm_power_cli_guest.c: In function ‘cmd_query_freq_list_parsed’:../examples/vm_power_manager/guest_cli/vm_power_cli_guest.c:208:42: error: implicit declaration of function ‘strtol’; did you mean ‘strtok’? [-Wimplicit-function-declaration]
208 | lcore_id = (unsigned int)strtol(res->cpu_num, &ep, 10);
| ^~~~~~
| strtok[Thomas:
- retrieve patch from
https://build.opensuse.org/projects/openSUSE:42:Factory-Candidates-Check/packages/dpdk/files/0001-examples-vm_power_manager-add-missing-header.patch?expand=1
- improve commit message]
--- examples/vm_power_manager/guest_cli/vm_power_cli_guest.c | 1 + 1 file changed, 1 insertion(+)
examples/vm_power_manager/guest_cli/vm_power_cli_guest.c +1 -0
@@ -6,6 +6,7 @@#include <stdint.h> #include <string.h> #include <stdio.h> +#include <stdlib.h> #include <termios.h> #include <cmdline_rdline.h>
Signature · 1 line
2.55.0
Quoted 28 lines · On Fri, 28 Aug 2026 23:53:50 +0200 Thomas Petazzoni…
From: Guillaume Gardet <[email protected]>
strtol is defined in
stdlib.hFixes the following build failure:
../examples/vm_power_manager/guest_cli/vm_power_cli_guest.c: In function ‘cmd_query_freq_list_parsed’:../examples/vm_power_manager/guest_cli/vm_power_cli_guest.c:208:42: error: implicit declaration of function ‘strtol’; did you mean ‘strtok’? [-Wimplicit-function-declaration]208 | lcore_id = (unsigned int)strtol(res->cpu_num, &ep, 10); | ^~~~~~ | strtokFixes 0e8f47491f090f44a4956429cb27f6942b6618b0 ("examples/vm_power: add command to query CPU frequency")Signed-off-by Guillaume Gardet <[email protected]>[Thomas:
- retrieve patch from
https://build.opensuse.org/projects/openSUSE:42:Factory-Candidates-Check/packages/dpdk/files/0001-examples-vm_power_manager-add-missing-header.patch?expand=1
- improve commit message]Signed-off-by Thomas Petazzoni <[email protected]>--- examples/vm_power_manager/guest_cli/vm_power_cli_guest.c | 1 + 1 file changed, 1 insertion(+)examples/vm_power_manager/guest_cli/vm_power_cli_guest.c +0
-0
examples/vm_power_manager/guest_cli/vm_power_cli_guest.c line 12
Quoted 7 lines
examples/vm_power_manager/guest_cli/vm_power_cli_guest.c +1
-0@@ -6,6 +6,7 @@#include <stdint.h> #include <string.h> #include <stdio.h> +#include <stdlib.h> #include <termios.h> #include <cmdline_rdline.h>
There is a pre-existing bug here. strtol() can returned signed value. Probably should be using strtoul
29/08/2026 00:18, Stephen Hemminger:
Quoted 37 lines
Quoted 34 lines · On Fri, 28 Aug 2026 23:53:50 +0200 Thomas Petazzoni…
From: Guillaume Gardet <[email protected]>
strtol is defined in
stdlib.hFixes the following build failure:
../examples/vm_power_manager/guest_cli/vm_power_cli_guest.c: In function ‘cmd_query_freq_list_parsed’:../examples/vm_power_manager/guest_cli/vm_power_cli_guest.c:208:42: error: implicit declaration of function ‘strtol’; did you mean ‘strtok’? [-Wimplicit-function-declaration]208 | lcore_id = (unsigned int)strtol(res->cpu_num, &ep, 10); | ^~~~~~ | strtokFixes 0e8f47491f090f44a4956429cb27f6942b6618b0 ("examples/vm_power: add command to query CPU frequency")Signed-off-by Guillaume Gardet <[email protected]>[Thomas:
- retrieve patch from
https://build.opensuse.org/projects/openSUSE:42:Factory-Candidates-Check/packages/dpdk/files/0001-examples-vm_power_manager-add-missing-header.patch?expand=1
- improve commit message]Signed-off-by Thomas Petazzoni <[email protected]>--- examples/vm_power_manager/guest_cli/vm_power_cli_guest.c | 1 + 1 file changed, 1 insertion(+)examples/vm_power_manager/guest_cli/vm_power_cli_guest.c +1
-0@@ -6,6 +6,7 @@#include <stdint.h> #include <string.h> #include <stdio.h> +#include <stdlib.h> #include <termios.h>
Quoted 4 lines
examples/vm_power_manager/guest_cli/vm_power_cli_guest.c line 12
Quoted 1 line
examples/vm_power_manager/guest_cli/vm_power_cli_guest.c +0
-0#include <cmdline_rdline.h> There is a pre-existing bug here.
strtol()can returned signed value. Probably should be using strtoul
I assume this patch is superseded by the 2 patches Stephen sent.
PATCH 1/2 examples/vm_power_manager: fix includes
In reply to Thomas PetazzoniUse include-what-you-use to get the correct set of includes for this command.
--- .../vm_power_manager/guest_cli/vm_power_cli_guest.c | 12 ++++++++---- .../vm_power_manager/guest_cli/vm_power_cli_guest.h | 2 ++ 2 files changed, 10 insertions(+), 4 deletions(-)
examples/vm_power_manager/guest_cli/vm_power_cli_guest.c +8 -4
@@ -2,21 +2,25 @@* Copyright(c) 2010-2014 Intel Corporation */ - -#include <stdint.h> #include <string.h> #include <stdio.h> -#include <termios.h> +#include <errno.h> +#include <stdbool.h> +#include <inttypes.h> +#include <stdlib.h> -#include <cmdline_rdline.h> #include <cmdline_parse.h> #include <cmdline_parse_string.h> #include <cmdline_parse_num.h> #include <cmdline_socket.h> #include <cmdline.h> + +#include <rte_build_config.h> #include <rte_log.h> #include <rte_lcore.h> #include <rte_ethdev.h> +#include <rte_errno.h> +#include <rte_ether.h> #include <rte_power_cpufreq.h> #include <rte_power_guest_channel.h>
examples/vm_power_manager/guest_cli/vm_power_cli_guest.h +2 -0
@@ -5,6 +5,8 @@ #ifndef VM_POWER_CLI_H_ #define VM_POWER_CLI_H_ +#include <rte_common.h> + #ifdef __cplusplus extern "C" { #endif
Signature · 1 line
2.53.0
PATCH 2/2 examples/vm_power_manager: fix vCPU number parsing
The guest CLI parsed the vCPU argument of the query_cpu_freq and query_cpu_caps commands with strtol(), storing the result in an unsigned variable. Use strtoul() to match the type, and parse into an unsigned long so the range check applies to the value strtoul() returned rather than to an already truncated one.
The original code also accepted trailing garbage, so "3xyz" and "3 4" parsed as 3; reject any unconsumed input.
Both commands duplicated this parsing along with the "all" handling. Factor it into parse_vcpu_arg() and report the offending string and the valid range instead of "Invalid parameter provided".
--- .../guest_cli/vm_power_cli_guest.c | 113 +++++++++--------- 1 file changed, 59 insertions(+), 54 deletions(-)
examples/vm_power_manager/guest_cli/vm_power_cli_guest.c +59 -54
@@ -145,6 +145,47 @@ struct cmd_freq_list_result {cmdline_fixed_string_t cpu_num; }; +/* +* Parse the vCPU argument of a query command, which is either "all" or a +* single vCPU number. A number indexes the per-vCPU arrays in the channel +* reply packets, so it must be below RTE_POWER_MAX_VCPU_PER_VM. +* +* Returns 1 for "all", 0 for a single vCPU, or -1 on error after printing +* the reason. On success *lcore_id is the lcore to communicate over, which +* for "all" is the first enabled lcore. +*/ +static int +parse_vcpu_arg (struct cmdline *cl,const char *str,unsigned int *lcore_id) +{ +unsigned long val; +char *ep; + +if (!strcmp (str,"all" )) { +/* Get first enabled lcore. */ + *lcore_id =rte_get_next_lcore (-1 ,0 ,0 ); +if (*lcore_id ==RTE_MAX_LCORE ) { +cmdline_printf (cl,"Enabled core not found.\n" ); +return -1 ; + } +return 1 ; + } + + errno =0 ; + val =strtoul (str, &ep,10 ); +if (errno !=0 || ep == str || *ep !='\0' ) { +cmdline_printf (cl,"Invalid vCPU number \"%s\".\n" , str); +return -1 ; + } +if (val >=RTE_POWER_MAX_VCPU_PER_VM ) { +cmdline_printf (cl,"vCPU number \"%s\" is out of range (max %u).\n" , + str,RTE_POWER_MAX_VCPU_PER_VM -1 ); +return -1 ; + } + + *lcore_id = val; +return 0 ; +} +static int query_data (struct rte_power_channel_packet *pkt,unsigned int lcore_id) {
@@ -179,46 +220,28 @@ receive_freq_list(struct rte_power_channel_packet_freq_list *pkt_freq_list,static void cmd_query_freq_list_parsed (void *parsed_result, - __rte_unused struct cmdline *cl, +struct cmdline *cl, __rte_unused void *data) {struct cmd_freq_list_result *res = parsed_result;unsigned int lcore_id;struct rte_power_channel_packet_freq_list pkt_freq_list;struct rte_power_channel_packet pkt; -bool query_list = false; +bool query_list;int ret; -char *ep;memset (&pkt,0 ,sizeof (pkt));memset (&pkt_freq_list,0 ,sizeof (pkt_freq_list)); -if (!strcmp (res->cpu_num,"all" )) { - -/* Get first enabled lcore. */ - lcore_id =rte_get_next_lcore (-1 , -0 , -0 ); -if (lcore_id ==RTE_MAX_LCORE ) { -cmdline_printf (cl,"Enabled core not found.\n" ); -return ; - } + ret =parse_vcpu_arg (cl, res->cpu_num, &lcore_id); +if (ret <0 ) +return ; - pkt.command =RTE_POWER_QUERY_FREQ_LIST ; -strlcpy (pkt.vm_name, policy.vm_name,sizeof (pkt.vm_name)); - query_list = true; - }else { - errno =0 ; - lcore_id = (unsigned int )strtol (res->cpu_num, &ep,10 ); -if (errno !=0 || lcore_id >=RTE_POWER_MAX_VCPU_PER_VM || - ep == res->cpu_num) { -cmdline_printf (cl,"Invalid parameter provided.\n" ); -return ; - } - pkt.command =RTE_POWER_QUERY_FREQ ; -strlcpy (pkt.vm_name, policy.vm_name,sizeof (pkt.vm_name)); + query_list = (ret ==1 ); + pkt.command = query_list ?RTE_POWER_QUERY_FREQ_LIST :RTE_POWER_QUERY_FREQ ; +strlcpy (pkt.vm_name, policy.vm_name,sizeof (pkt.vm_name)); +if (!query_list) pkt.resource_id = lcore_id; - } ret =query_data (&pkt, lcore_id);if (ret <0 ) {
@@ -289,46 +312,28 @@ receive_capabilities(struct rte_power_channel_packet_caps_list *pkt_caps_list,static void cmd_query_caps_list_parsed (void *parsed_result, - __rte_unused struct cmdline *cl, +struct cmdline *cl, __rte_unused void *data) {struct cmd_query_caps_result *res = parsed_result;unsigned int lcore_id;struct rte_power_channel_packet_caps_list pkt_caps_list;struct rte_power_channel_packet pkt; -bool query_list = false; +bool query_list;int ret; -char *ep;memset (&pkt,0 ,sizeof (pkt));memset (&pkt_caps_list,0 ,sizeof (pkt_caps_list)); -if (!strcmp (res->cpu_num,"all" )) { - -/* Get first enabled lcore. */ - lcore_id =rte_get_next_lcore (-1 , -0 , -0 ); -if (lcore_id ==RTE_MAX_LCORE ) { -cmdline_printf (cl,"Enabled core not found.\n" ); -return ; - } + ret =parse_vcpu_arg (cl, res->cpu_num, &lcore_id); +if (ret <0 ) +return ; - pkt.command =RTE_POWER_QUERY_CAPS_LIST ; -strlcpy (pkt.vm_name, policy.vm_name,sizeof (pkt.vm_name)); - query_list = true; - }else { - errno =0 ; - lcore_id = (unsigned int )strtol (res->cpu_num, &ep,10 ); -if (errno !=0 || lcore_id >=RTE_POWER_MAX_VCPU_PER_VM || - ep == res->cpu_num) { -cmdline_printf (cl,"Invalid parameter provided.\n" ); -return ; - } - pkt.command =RTE_POWER_QUERY_CAPS ; -strlcpy (pkt.vm_name, policy.vm_name,sizeof (pkt.vm_name)); + query_list = (ret ==1 ); + pkt.command = query_list ?RTE_POWER_QUERY_CAPS_LIST :RTE_POWER_QUERY_CAPS ; +strlcpy (pkt.vm_name, policy.vm_name,sizeof (pkt.vm_name)); +if (!query_list) pkt.resource_id = lcore_id; - } ret =query_data (&pkt, lcore_id);if (ret <0 ) {
Signature · 1 line
2.53.0
Re: [PATCH 1/2] examples/vm_power_manager: fix includes
In reply to Stephen Hemminger29/08/2026 04:43, Stephen Hemminger:
Quoted 5 lines
Use include-what-you-use to get the correct set of includes for this command.
Reported-by Guillaume Gardet <[email protected]>Signed-off-by Stephen Hemminger <[email protected]>
Series applied with .mailmap and Fixes lines additions, thanks.