From nobody Fri Feb 13 12:31:04 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 529B0CE79A6 for ; Tue, 26 Sep 2023 04:30:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233600AbjIZEaN (ORCPT ); Tue, 26 Sep 2023 00:30:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232781AbjIZEaI (ORCPT ); Tue, 26 Sep 2023 00:30:08 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BDDDE9; Mon, 25 Sep 2023 21:30:00 -0700 (PDT) Received: from kwepemd200002.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Rvmtl5tMbzrT3Y; Tue, 26 Sep 2023 12:27:43 +0800 (CST) Received: from M910t.huawei.com (10.110.54.157) by kwepemd200002.china.huawei.com (7.221.188.186) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.23; Tue, 26 Sep 2023 12:29:56 +0800 From: Changbin Du To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo CC: Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , , , , Changbin Du Subject: [PATCH v5 2/5] perf: util: support string type option for perf_parse_sublevel_options Date: Tue, 26 Sep 2023 12:29:35 +0800 Message-ID: <20230926042938.509234-3-changbin.du@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230926042938.509234-1-changbin.du@huawei.com> References: <20230926042938.509234-1-changbin.du@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.110.54.157] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd200002.china.huawei.com (7.221.188.186) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add string type option to get non-int value. Signed-off-by: Changbin Du --- 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/par= se-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; } =20 - if (vstr) - v =3D atoi(vstr); + if (vstr) { + /* The value of option either is a integer or string. */ + if (opt->value_ptr) { + v =3D atoi(vstr); + *opt->value_ptr =3D v; + } else { + *opt->str_ptr =3D strdup(vstr); + } + } =20 - *opt->value_ptr =3D v; free(s); return 0; } diff --git a/tools/perf/util/parse-sublevel-options.h b/tools/perf/util/par= se-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 @@ =20 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; }; =20 int perf_parse_sublevel_options(const char *str, struct sublevel_option *o= pts); --=20 2.25.1