lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230926042938.509234-3-changbin.du@huawei.com>
Date:   Tue, 26 Sep 2023 12:29:35 +0800
From:   Changbin Du <changbin.du@...wei.com>
To:     Peter Zijlstra <peterz@...radead.org>,
        Ingo Molnar <mingo@...hat.com>,
        Arnaldo Carvalho de Melo <acme@...nel.org>
CC:     Mark Rutland <mark.rutland@....com>,
        Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
        Jiri Olsa <jolsa@...nel.org>,
        Namhyung Kim <namhyung@...nel.org>,
        Ian Rogers <irogers@...gle.com>,
        Adrian Hunter <adrian.hunter@...el.com>,
        <linux-perf-users@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
        <changbin.du@...il.com>, Changbin Du <changbin.du@...wei.com>
Subject: [PATCH v5 2/5] perf: util: support string type option for perf_parse_sublevel_options

Add string type option to get non-int value.

Signed-off-by: Changbin Du <changbin.du@...wei.com>
---
 tools/perf/util/parse-sublevel-options.c | 12 +++++++++---
 tools/perf/util/parse-sublevel-options.h |  7 +++++++
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/parse-sublevel-options.c b/tools/perf/util/parse-sublevel-options.c
index a841d17ffd57..d08a1ccc9616 100644
--- a/tools/perf/util/parse-sublevel-options.c
+++ b/tools/perf/util/parse-sublevel-options.c
@@ -34,10 +34,16 @@ static int parse_one_sublevel_option(const char *str,
 		return -1;
 	}
 
-	if (vstr)
-		v = atoi(vstr);
+	if (vstr) {
+		/* The value of option either is a integer or string. */
+		if (opt->value_ptr) {
+			v = atoi(vstr);
+			*opt->value_ptr = v;
+		} else {
+			*opt->str_ptr = strdup(vstr);
+		}
+	}
 
-	*opt->value_ptr = v;
 	free(s);
 	return 0;
 }
diff --git a/tools/perf/util/parse-sublevel-options.h b/tools/perf/util/parse-sublevel-options.h
index 578b18ef03bb..d536ebe43b58 100644
--- a/tools/perf/util/parse-sublevel-options.h
+++ b/tools/perf/util/parse-sublevel-options.h
@@ -3,7 +3,14 @@
 
 struct sublevel_option {
 	const char *name;
+
+	/*
+	 * Only one of below can be non-null. So we simply support
+	 * two types: integer and string. For string, the caller is
+	 * responsible for freeing allocated memory after use.
+	 */
 	int *value_ptr;
+	char **str_ptr;
 };
 
 int perf_parse_sublevel_options(const char *str, struct sublevel_option *opts);
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ