Message ID | 20240111232923.8138-1-ilkka@os.amperecomputing.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-24134-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1791315dyi; Thu, 11 Jan 2024 15:40:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IGWrcawq+bUTRYwcOoOvYRFd4Nq2Mwt53GIOt/74EblcHeIvlHDN8oAQOW6m7W34ydO2mN0 X-Received: by 2002:a05:6e02:13e1:b0:360:8928:2170 with SMTP id w1-20020a056e0213e100b0036089282170mr140347ilj.26.1705016431292; Thu, 11 Jan 2024 15:40:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705016431; cv=pass; d=google.com; s=arc-20160816; b=jcyRuRYr6jaZKXKyNsZ+dw3fpwbXL5RuEi/R+1V0stLSrgt47Yx9yRdPe1BtZxKihB fMVytRXcu4aMrW1a80lCSE5ZkZ9pYX80ju1OCjyaz5jZj8OqF6g+mA9cWDQubbVyjcoA qzNWdsT7oU0CjV8th1sFrL2JcNNoF9vz1j6N9gtZWCxQvRmL8I0WbuUsgBzf5fyHk+5v 5ZeSC04DvyZfuKDl3LR9e0yL7TpairtGfOXMGhasmiGJUsOCIwhcBKVEwPTHBuQG8mkW 7fjWLQegVFEBckC6B3ih6FtiUeUSq7KCfPJdgzn1lFFvOp9AIqVr4T1vinaj1pWoq8F2 8wew== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :content-transfer-encoding:message-id:date:subject:cc:to:from :dkim-signature; bh=G5l2oJHVJEVTgfkSmfZDvgNoUGFAJDlrGmip4VsfC3M=; fh=62cXzDRCxlCiCftFUz+vLjLs4EQy2lWfosXv3pevDK0=; b=A/4fitvhmdENYwd/hSxYbHgxb5V/BwyQxFN1nJyrvDwNcpPSaYRavUOk+HYLshy/3f MtzSjwM8f9/NK3aXaajlmb9lrDYmbRze5bagMgKipFnvONnwqtnMOOnsRClsjV5FP5V2 V3xIth49AKvU9Hw2k3wqixSxq0ku5LbBqdN0Uenk+PqL2uPIfMLcCAOpeLVH7sOyMzVR QwUchaMRYjUu81SjdEE5vtwLCNenDXfWQYFu+Ppdp6FEYlIswYQvSxIr56zaaaDQPhpB ogbUWbsMSvrkEViQ1/npJBmxXB0ktW9Ye3Jm/7e/LldTTDUBDk7erUx75cwhCUvBC6R9 hgRg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@os.amperecomputing.com header.s=selector2 header.b=iHwzdN2+; arc=pass (i=1 spf=pass spfdomain=os.amperecomputing.com dkim=pass dkdomain=os.amperecomputing.com dmarc=pass fromdomain=os.amperecomputing.com); spf=pass (google.com: domain of linux-kernel+bounces-24134-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24134-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amperecomputing.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id g11-20020a63564b000000b005cde420a01fsi1969957pgm.667.2024.01.11.15.40.31 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 15:40:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24134-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@os.amperecomputing.com header.s=selector2 header.b=iHwzdN2+; arc=pass (i=1 spf=pass spfdomain=os.amperecomputing.com dkim=pass dkdomain=os.amperecomputing.com dmarc=pass fromdomain=os.amperecomputing.com); spf=pass (google.com: domain of linux-kernel+bounces-24134-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24134-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amperecomputing.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id E967E284AD5 for <ouuuleilei@gmail.com>; Thu, 11 Jan 2024 23:30:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F036B59B7F; Thu, 11 Jan 2024 23:30:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=os.amperecomputing.com header.i=@os.amperecomputing.com header.b="iHwzdN2+" Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2127.outbound.protection.outlook.com [40.107.223.127]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 235DD5A0E1; Thu, 11 Jan 2024 23:29:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=os.amperecomputing.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=os.amperecomputing.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lc9FpCvTwLm76MHz3oGQOTx6xoZaFIxuQM4h8laIipnog86oWBXMH5IKYcyfIa/N3CE3aVGUvDjNSfCaD8h0ubqhjXl+s5qJ0zSOPI+7bXIr0b9SqtlSDJJZHpK5ItqMCm3fuFtIWoAtx378MxjF+tfHmel/HRo4D8ucS80dCpTETCQVbDOScoSIhIsRhU9knLYTooVpf4+IW3kHuqEQpBUC2zgbvOHBdFSPvH3Ku8fV5EeL/bA4/gzj0STy+yQVRmqKUMzirt3gowGxMbFjxnTcoFfCGnJ9JEVOQwlHD6pBMzdSUzqXmGZCP/IjuuXNLUZxNMSV7hOD58jNiL+E0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=G5l2oJHVJEVTgfkSmfZDvgNoUGFAJDlrGmip4VsfC3M=; b=PE70fQzGAfV7+RBLxCynYjFeUQKpGwC0McuyuuprVqqm7IKSZOMdNvcfrX+NPZ9t7wD700kcsr2BoGJ3M8IjyKZxo60cTg2DRgIMr9G0g0FIlmMp6FIP+culTl1xOOnLiHFQoFDIRfiJ+6GCLfIcO9IsnJ7ruFT55HMecVDeHHWthpDVn+OiDzw7ibATyDUfqksAosbaWivzfAl3+UnOPRcFs7sReaMQ8vmWUuSgl0OPghhvYhNREGRXmjE45BcBUtXCN363UNbPMCr/yq0DUUyqD+iD071v2v3CdIZK93tIy5ZBpzT0Go+QrQy8T7boy07sOVGjvzYBVOGi82e7Cg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=G5l2oJHVJEVTgfkSmfZDvgNoUGFAJDlrGmip4VsfC3M=; b=iHwzdN2+TO2LGqe3zpTOMydvTVVcz763oJe8caMAUnz2TRNeAaz0/zKMRIYNpYlWy5op1WJjxpFWTk9UKYb18VJ5q0hh1LVSlTHgGGL/NX6IANQ/1EEQuZym/3tjN1RFjMEkwlcX6pxdE73Vcan6l8gKfyBt2qtWhOpvuxq+mGM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from PH0PR01MB8166.prod.exchangelabs.com (2603:10b6:510:293::17) by PH0PR01MB6375.prod.exchangelabs.com (2603:10b6:510:17::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7181.21; Thu, 11 Jan 2024 23:29:54 +0000 Received: from PH0PR01MB8166.prod.exchangelabs.com ([fe80::5549:ab3d:70af:8693]) by PH0PR01MB8166.prod.exchangelabs.com ([fe80::5549:ab3d:70af:8693%7]) with mapi id 15.20.7181.019; Thu, 11 Jan 2024 23:29:53 +0000 From: Ilkka Koskinen <ilkka@os.amperecomputing.com> To: Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@redhat.com>, Arnaldo Carvalho de Melo <acme@kernel.org>, Mark Rutland <mark.rutland@arm.com>, Alexander Shishkin <alexander.shishkin@linux.intel.com>, Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>, Ian Rogers <irogers@google.com>, Adrian Hunter <adrian.hunter@intel.com> Cc: Ilkka Koskinen <ilkka@os.amperecomputing.com>, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] perf data convert: Fix segfault when converting to json on arm64 Date: Thu, 11 Jan 2024 15:29:23 -0800 Message-ID: <20240111232923.8138-1-ilkka@os.amperecomputing.com> X-Mailer: git-send-email 2.43.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: CH5P221CA0008.NAMP221.PROD.OUTLOOK.COM (2603:10b6:610:1f2::24) To PH0PR01MB8166.prod.exchangelabs.com (2603:10b6:510:293::17) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR01MB8166:EE_|PH0PR01MB6375:EE_ X-MS-Office365-Filtering-Correlation-Id: 400567c1-9668-46e2-e4f8-08dc12fd36d6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dxZns6xkB9+5iA9a4wD8QUJVpAp7ZJLcwj85xEn3EfAtkXA7UFzuV8rw+t7sYUEaOCqzZdBSr+LqEo1zWye56+Ybjj0KNhBypC2HFQ+MtC2ljrRuKi/4vXzcb5CWcmmcw9u9CvYi3mmRJfq6YdgIcM+lzZP5zZhxu9xEpcSmpGWseZrgdeqHBewxfdYBvxNxzK09+isd29n6Pzp6VgjIb//ZEgv4z2Kwwpx3ZurLy0rVkqzWUZxwLeK1VYUOI4PbZ/RqWrbm1c+G2x5UdlIzigERv3TizymDsQ+DcE+SUmQ3l87eMSfuTKdjIsC/yHyZ7/CeNlcGaYNXL+c2Q4Md85tN4yvoz553eGfkkAglWo1wRAwLkTR9RmseMk216SER4DbdNdDHnkrvREZ7z5zkwGOVhqlRup7oFZCFwAvPFFYV/+7ud5Kq91qY2Iwkon7cGEMIi+zidnCNoGzHXAGW2NxFX7ClgDlb85hajmAWxAjLTqzKWWssfYvc+3yar/njIjgDKUkGt9KQizXgsirfZYNEsLZBOmGtB2sCN4a66qhIHYhNhWd3ULnvjWX+pLUO6CbPSyXAb+9h+4PfZCkcZzoMgNOj6r2WD26YtInKn4u2DwsHran6VF5WhG4MRGEC X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR01MB8166.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(376002)(346002)(39850400004)(366004)(136003)(230922051799003)(186009)(451199024)(64100799003)(1800799012)(4326008)(8676002)(8936002)(2906002)(4744005)(7416002)(5660300002)(86362001)(38350700005)(478600001)(83380400001)(1076003)(2616005)(26005)(6666004)(6512007)(6506007)(38100700002)(41300700001)(52116002)(316002)(66556008)(66476007)(66946007)(6486002)(110136005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: G4JydZ3o4TJquqA393XNaTq9KjmwNq+JWOhVS3B9M7FKqsiavjlddgYyOkpkYTvEQf+gziz28NNfMXkJRFvpGIFtbjgSyK1ILpeXdbg5RHW4+peXT3z67GAB1InQ+oIG3mG4mHDME51C0AJI3ZX/KJQU4pU8/mt1bL/liLdadGMKTr0dgafgyRJQ4+AK+w6zARUzj9eEmgYRxF2TXEBkXXjCN5jrbm4M55tQef/sWJpLCib7EpPsGCtQKBtz1AztVSbPG/4JQK8jeuz09xlU2j2kW78vnOtgflxE/ZkFE86HmJtLnR2flSqzftoi4oOPCSz/KkTuqE6mLZEP6HUbaW76Ix02gboG1fmjfVyeWzib1qtGvjJSj4pQhJXFV+Wg/i4W76x38DkcGx4m1ZEfIsZsYOsE4enofm0c0RBzSRjvR3P24wBsE9EJ2of3SX8Jr4VDROAVDi2sr0RtplHo0zhpe06om6Byg5DSbX3YoAwhfsnejfpKyMZf33h1DoaA7uiC0qR1uhyjWtX67cVQeVnc0COmKOL9jVkSKLFqMqrg+C5sU1r7yo/6+aPwKsro1hmWx4gVzURSeQDfWPbUU9v6b6314XcEMC758zuBnChahaVegNz/e+EugZxU4zBj45g/pJPBhJGrD3MD9U88P6lqB74+P9/sP0+F9wMeXTIXX0Ap91tpo4Q6skW5QRhE/UR84q05bcOiA3HkazOR4KOW313K/qg8FoZ9zBjAOOlKNioLf1toe+8Eda9vGrbodV5r6BAL4mZwk6DAQLv595x6NB7DjkIkBzWrAtG6zb7SgOqKO27RX56qTW5d7BXAM32UAtoHDHEGbOZiELvO8H/uCVFBnICWEr1JOK455U/Dkw2Zv7SJMW91fFzT+GhCqOA6daQYLB+8wKm+SP8f1Ulju2YutEtYQMT6Y0PtmqAHPhf4ZhF/uPMXDg1v59LPHoVXAxOoMFklpSI9MFnq6agyX1Wo/94lIiiGYnXwx48Ujv7NgjeTJzomXEpAcK7mk7c/3Sfq/4vg1pmYIuJNq/7rThr9sAZCqfWDk7PSrvG3iNV7sOv6thVs+qPy8q+s53EQJzUSRMoCxcHUePCTbyihx5dA1aOq2giy6Dgr6M5ojuubsK6Pjm73VKRMbWyqJrG1VLa1+XDgbBaRVMWAdi+lFPBIgi3wWIsuiufGWzAvVSw7p3aI5zg9azKcax2pQnJtd0A6wfrMKOMFFhMeIXk0u8OUmLBvEe55v4qvyk05MXP9k592ghvrioIjVsgvcL40pYPJ13GymDlMU2NFBzUM1OMGA88m6cbhmbtXS/qt5B/IrxjSm1TpTLlTX/Pm8GnpZFjqdUdlXKA4D0wBGyzsTFqOSVk+d9TXrWZuOSRaKxE/C8Iugh2ZuyTeVJanSSjIGLokFa5DztAQBmELmetrdxfK3JD39/YXZfQe+j8xcYM4B/mTKhuXMCqSkPVATokexXHBeCxQuEDAYeDw5xBmwan8s1ie6R0iyPmaK9AMjdV4rJ7wmM5KSvEvm84EhX7ZLoKvSX8kTU6bh6pLEdpjT2Az4aLg6AgSLF1ZyG4Y+nqnChGtt3vLchkaSMf/SKrAOjOyQw3b9V/hAs0RacNNEhWctvNd3CAf0eyUS+I= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 400567c1-9668-46e2-e4f8-08dc12fd36d6 X-MS-Exchange-CrossTenant-AuthSource: PH0PR01MB8166.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jan 2024 23:29:53.7921 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: bJ/C7V2+2LuOjgCCDbb8OfPaLkFHMMdDtrj4u/sGhpkvkF6HVpj51Cv/WMaudHxSlkKvEiy0kQsK+vNBvC4DCMAXAaUyadSPiD+Nuyquqj1dod7XBD4g0W+tvd7OYIl5 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR01MB6375 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787839309420933507 X-GMAIL-MSGID: 1787839309420933507 |
Series |
perf data convert: Fix segfault when converting to json on arm64
|
|
Commit Message
Ilkka Koskinen
Jan. 11, 2024, 11:29 p.m. UTC
Arm64 doesn't have Model in /proc/cpuinfo and, thus, cpu_desc doesn't get
assigned.
Running
$ perf data convert --to-json perf.data.json
ends up calling output_json_string() with NULL pointer, which causes a
segmentation fault.
Signed-off-by: Ilkka Koskinen <ilkka@os.amperecomputing.com>
---
tools/perf/util/data-convert-json.c | 5 +++++
1 file changed, 5 insertions(+)
Comments
On 11/01/2024 23:29, Ilkka Koskinen wrote: > Arm64 doesn't have Model in /proc/cpuinfo and, thus, cpu_desc doesn't get > assigned. > > Running > $ perf data convert --to-json perf.data.json > > ends up calling output_json_string() with NULL pointer, which causes a > segmentation fault. > > Signed-off-by: Ilkka Koskinen <ilkka@os.amperecomputing.com> > --- > tools/perf/util/data-convert-json.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/tools/perf/util/data-convert-json.c b/tools/perf/util/data-convert-json.c > index 5bb3c2ba95ca..5d6de1cef546 100644 > --- a/tools/perf/util/data-convert-json.c > +++ b/tools/perf/util/data-convert-json.c > @@ -97,6 +97,11 @@ static void output_json_format(FILE *out, bool comma, int depth, const char *for > static void output_json_key_string(FILE *out, bool comma, int depth, > const char *key, const char *value) > { > + if (!value) { > + pr_info("No value set for key %s\n", key); > + return; > + } > + > output_json_delimiters(out, comma, depth); > output_json_string(out, key); > fputs(": ", out); It looks like this would hide new errors on any of the other fields that output_json_key_string() is called on. Maybe it would be better to only wrap the call to output cpu_desc with the if? If that's the only one that we think is optional, and even better only do it for arm64. I mention this because the test for 'perf data convert' only checks for valid json syntax, but not any fields. So we might want to avoid others going missing. Thanks James
Hello, On Fri, Jan 12, 2024 at 3:35 AM James Clark <james.clark@arm.com> wrote: > > > > On 11/01/2024 23:29, Ilkka Koskinen wrote: > > Arm64 doesn't have Model in /proc/cpuinfo and, thus, cpu_desc doesn't get > > assigned. > > > > Running > > $ perf data convert --to-json perf.data.json > > > > ends up calling output_json_string() with NULL pointer, which causes a > > segmentation fault. > > > > Signed-off-by: Ilkka Koskinen <ilkka@os.amperecomputing.com> > > --- > > tools/perf/util/data-convert-json.c | 5 +++++ > > 1 file changed, 5 insertions(+) > > > > diff --git a/tools/perf/util/data-convert-json.c b/tools/perf/util/data-convert-json.c > > index 5bb3c2ba95ca..5d6de1cef546 100644 > > --- a/tools/perf/util/data-convert-json.c > > +++ b/tools/perf/util/data-convert-json.c > > @@ -97,6 +97,11 @@ static void output_json_format(FILE *out, bool comma, int depth, const char *for > > static void output_json_key_string(FILE *out, bool comma, int depth, > > const char *key, const char *value) > > { > > + if (!value) { > > + pr_info("No value set for key %s\n", key); > > + return; > > + } > > + > > output_json_delimiters(out, comma, depth); > > output_json_string(out, key); > > fputs(": ", out); > > > It looks like this would hide new errors on any of the other fields that > output_json_key_string() is called on. Maybe it would be better to only > wrap the call to output cpu_desc with the if? If that's the only one > that we think is optional, and even better only do it for arm64. > > I mention this because the test for 'perf data convert' only checks for > valid json syntax, but not any fields. So we might want to avoid others > going missing. Makes sense. Ilkka, can you send v2 with this? Thanks, Namhyung
On Tue, 16 Jan 2024, Namhyung Kim wrote: > Hello, > > On Fri, Jan 12, 2024 at 3:35 AM James Clark <james.clark@arm.com> wrote: >> >> >> >> On 11/01/2024 23:29, Ilkka Koskinen wrote: >>> Arm64 doesn't have Model in /proc/cpuinfo and, thus, cpu_desc doesn't get >>> assigned. >>> >>> Running >>> $ perf data convert --to-json perf.data.json >>> >>> ends up calling output_json_string() with NULL pointer, which causes a >>> segmentation fault. >>> >>> Signed-off-by: Ilkka Koskinen <ilkka@os.amperecomputing.com> >>> --- >>> tools/perf/util/data-convert-json.c | 5 +++++ >>> 1 file changed, 5 insertions(+) >>> >>> diff --git a/tools/perf/util/data-convert-json.c b/tools/perf/util/data-convert-json.c >>> index 5bb3c2ba95ca..5d6de1cef546 100644 >>> --- a/tools/perf/util/data-convert-json.c >>> +++ b/tools/perf/util/data-convert-json.c >>> @@ -97,6 +97,11 @@ static void output_json_format(FILE *out, bool comma, int depth, const char *for >>> static void output_json_key_string(FILE *out, bool comma, int depth, >>> const char *key, const char *value) >>> { >>> + if (!value) { >>> + pr_info("No value set for key %s\n", key); >>> + return; >>> + } >>> + >>> output_json_delimiters(out, comma, depth); >>> output_json_string(out, key); >>> fputs(": ", out); >> >> >> It looks like this would hide new errors on any of the other fields that >> output_json_key_string() is called on. Maybe it would be better to only >> wrap the call to output cpu_desc with the if? If that's the only one >> that we think is optional, and even better only do it for arm64. >> >> I mention this because the test for 'perf data convert' only checks for >> valid json syntax, but not any fields. So we might want to avoid others >> going missing. > > Makes sense. Ilkka, can you send v2 with this? I initially considered the choice James suggested but I kind of thought that pr_info() might be enough. However, I don't have strong prefence on either. I'll send an updated version soon. Cheers, Ilkka > > Thanks, > Namhyung >
diff --git a/tools/perf/util/data-convert-json.c b/tools/perf/util/data-convert-json.c index 5bb3c2ba95ca..5d6de1cef546 100644 --- a/tools/perf/util/data-convert-json.c +++ b/tools/perf/util/data-convert-json.c @@ -97,6 +97,11 @@ static void output_json_format(FILE *out, bool comma, int depth, const char *for static void output_json_key_string(FILE *out, bool comma, int depth, const char *key, const char *value) { + if (!value) { + pr_info("No value set for key %s\n", key); + return; + } + output_json_delimiters(out, comma, depth); output_json_string(out, key); fputs(": ", out);