* [PATCH RESEND] examples/vm_power_manager: add missing <stdlib.h> header include for strtol
@ 2026-08-28 21:53 Thomas Petazzoni
2026-08-28 22:18 ` Stephen Hemminger
2026-08-29 2:43 ` [PATCH 1/2] examples/vm_power_manager: fix includes Stephen Hemminger
0 siblings, 2 replies; 4+ messages in thread
From: Thomas Petazzoni @ 2026-08-28 21:53 UTC (permalink / raw)
To: dev
Cc: Guillaume Gardet, Guillaume Gardet, Thomas Petazzoni,
Anatoly Burakov, Sivaprasad Tummala, Lee Daly, Marcin Hajkowski
From: Guillaume Gardet <Guillaume.Gardet@arm.com>
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
Fixes: 0e8f47491f090f44a4956429cb27f6942b6618b0 ("examples/vm_power: add command to query CPU frequency")
Signed-off-by: Guillaume Gardet <guillaume.gardet@arm.com>
[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 <thomas.petazzoni@bootlin.com>
---
examples/vm_power_manager/guest_cli/vm_power_cli_guest.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/examples/vm_power_manager/guest_cli/vm_power_cli_guest.c b/examples/vm_power_manager/guest_cli/vm_power_cli_guest.c
index 4114593cee..63a59c8b10 100644
--- a/examples/vm_power_manager/guest_cli/vm_power_cli_guest.c
+++ b/examples/vm_power_manager/guest_cli/vm_power_cli_guest.c
@@ -6,6 +6,7 @@
#include <stdint.h>
#include <string.h>
#include <stdio.h>
+#include <stdlib.h>
#include <termios.h>
#include <cmdline_rdline.h>
--
2.55.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH RESEND] examples/vm_power_manager: add missing <stdlib.h> header include for strtol
2026-08-28 21:53 [PATCH RESEND] examples/vm_power_manager: add missing <stdlib.h> header include for strtol Thomas Petazzoni
@ 2026-08-28 22:18 ` Stephen Hemminger
2026-08-29 2:43 ` [PATCH 1/2] examples/vm_power_manager: fix includes Stephen Hemminger
1 sibling, 0 replies; 4+ messages in thread
From: Stephen Hemminger @ 2026-08-28 22:18 UTC (permalink / raw)
To: Thomas Petazzoni
Cc: dev, Guillaume Gardet, Anatoly Burakov, Sivaprasad Tummala,
Lee Daly, Marcin Hajkowski
On Fri, 28 Aug 2026 23:53:50 +0200
Thomas Petazzoni <thomas.petazzoni@bootlin.com> wrote:
> From: Guillaume Gardet <Guillaume.Gardet@arm.com>
>
> 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
>
> Fixes: 0e8f47491f090f44a4956429cb27f6942b6618b0 ("examples/vm_power: add command to query CPU frequency")
> Signed-off-by: Guillaume Gardet <guillaume.gardet@arm.com>
> [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 <thomas.petazzoni@bootlin.com>
> ---
> examples/vm_power_manager/guest_cli/vm_power_cli_guest.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/examples/vm_power_manager/guest_cli/vm_power_cli_guest.c b/examples/vm_power_manager/guest_cli/vm_power_cli_guest.c
> index 4114593cee..63a59c8b10 100644
> --- a/examples/vm_power_manager/guest_cli/vm_power_cli_guest.c
> +++ b/examples/vm_power_manager/guest_cli/vm_power_cli_guest.c
> @@ -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
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] examples/vm_power_manager: fix includes
2026-08-28 21:53 [PATCH RESEND] examples/vm_power_manager: add missing <stdlib.h> header include for strtol Thomas Petazzoni
2026-08-28 22:18 ` Stephen Hemminger
@ 2026-08-29 2:43 ` Stephen Hemminger
2026-08-29 2:43 ` [PATCH 2/2] examples/vm_power_manager: fix vCPU number parsing Stephen Hemminger
1 sibling, 1 reply; 4+ messages in thread
From: Stephen Hemminger @ 2026-08-29 2:43 UTC (permalink / raw)
To: dev
Cc: Stephen Hemminger, Guillaume Gardet, Anatoly Burakov,
Sivaprasad Tummala
Use include-what-you-use to get the correct set of includes
for this command.
Reported-by: Guillaume Gardet <Guillaume.Gardet@arm.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
.../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(-)
diff --git a/examples/vm_power_manager/guest_cli/vm_power_cli_guest.c b/examples/vm_power_manager/guest_cli/vm_power_cli_guest.c
index 4114593cee..cd0d87d1e7 100644
--- a/examples/vm_power_manager/guest_cli/vm_power_cli_guest.c
+++ b/examples/vm_power_manager/guest_cli/vm_power_cli_guest.c
@@ -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>
diff --git a/examples/vm_power_manager/guest_cli/vm_power_cli_guest.h b/examples/vm_power_manager/guest_cli/vm_power_cli_guest.h
index b578ec0723..a93fabfa8e 100644
--- a/examples/vm_power_manager/guest_cli/vm_power_cli_guest.h
+++ b/examples/vm_power_manager/guest_cli/vm_power_cli_guest.h
@@ -5,6 +5,8 @@
#ifndef VM_POWER_CLI_H_
#define VM_POWER_CLI_H_
+#include <rte_common.h>
+
#ifdef __cplusplus
extern "C" {
#endif
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] examples/vm_power_manager: fix vCPU number parsing
2026-08-29 2:43 ` [PATCH 1/2] examples/vm_power_manager: fix includes Stephen Hemminger
@ 2026-08-29 2:43 ` Stephen Hemminger
0 siblings, 0 replies; 4+ messages in thread
From: Stephen Hemminger @ 2026-08-29 2:43 UTC (permalink / raw)
To: dev; +Cc: Stephen Hemminger, Anatoly Burakov, Sivaprasad Tummala
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".
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
.../guest_cli/vm_power_cli_guest.c | 113 +++++++++---------
1 file changed, 59 insertions(+), 54 deletions(-)
diff --git a/examples/vm_power_manager/guest_cli/vm_power_cli_guest.c b/examples/vm_power_manager/guest_cli/vm_power_cli_guest.c
index cd0d87d1e7..f7ffda1381 100644
--- a/examples/vm_power_manager/guest_cli/vm_power_cli_guest.c
+++ b/examples/vm_power_manager/guest_cli/vm_power_cli_guest.c
@@ -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) {
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-08-29 2:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-28 21:53 [PATCH RESEND] examples/vm_power_manager: add missing <stdlib.h> header include for strtol Thomas Petazzoni
2026-08-28 22:18 ` Stephen Hemminger
2026-08-29 2:43 ` [PATCH 1/2] examples/vm_power_manager: fix includes Stephen Hemminger
2026-08-29 2:43 ` [PATCH 2/2] examples/vm_power_manager: fix vCPU number parsing Stephen Hemminger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox