Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3940217pxj; Mon, 21 Jun 2021 09:49:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwi2NulV91LjwQah/1WK2zAoHbd1TTbrO5OQTnpFI3TlDn0svxERCdMRnv3c2fvfNFWH09u X-Received: by 2002:a17:906:a40c:: with SMTP id l12mr24117653ejz.180.1624294156814; Mon, 21 Jun 2021 09:49:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624294156; cv=none; d=google.com; s=arc-20160816; b=Ur8V0/dPdBzkryb3rmjVBCQ9tsoTpVNKw4JtpMwwtzdIOBF02ZZRR5FF69oZ7GvSND lPx5XE/+s1STg/QkE/nKta0vzo1mr2o4MrsftD2YfYT+JQuIZAfp8KGQmZGrC3b3dCGf f7L51IdI5N4Ba8GDX87FRQ6qho8tjPVWMfyFJ8GwwgF23bg32ZVww5284ikdz5Hu5C+y 6+rz807adHkQRRQnFyCysIos8p5h7yvFnCyEsVYy5vRUmTXk9DE7+r50Ar/V5RjLIQeJ W3WlunzhUwjSG1VyyteSfGKyagRJmiCXAb3U3JLUczMkHLHEbSHQJvMDdbR6BhnMcmuY Hj1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mXAZ7mYg4A84/kqp4F9uNpVgk2lqHXE5htYjlm5UJi4=; b=Vdr6v4yb4AYN3fKBqyj2+cFGIJb7JWka5gcqrGqL5/vNPEnh+ODldPCniZ2XPwSp7s j3EFWCU9vtVg6ozf967wFmWa11+1j/5TZ++QcgBFZ8q/D3Qoj8KTWk31unNXwIhbdpG1 BBbz3as+DaLQoigf6EDWwK8F792h6xuQmRJOAoBhXfJJGfPlRrwf5wQVx0uLr2CtfemF RKDND286JaEvnLCCtHd0eONuAqfA4S4L8FFokNhac9gxAYoy3IB02/AD6EGBrC9vk3wA lcFJeBk11JyGy9lZacPp67e++xOTo2WXvtAC6d3L8AYPZtZLhL/vYyQb0ljHeZ19jxGi spXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=htNY5KSh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bs19si11200240ejb.398.2021.06.21.09.48.53; Mon, 21 Jun 2021 09:49:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=htNY5KSh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233055AbhFUQtL (ORCPT + 99 others); Mon, 21 Jun 2021 12:49:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:37914 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233646AbhFUQpH (ORCPT ); Mon, 21 Jun 2021 12:45:07 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0481761040; Mon, 21 Jun 2021 16:32:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624293143; bh=TUDia6ZNuQqMxoADShp9wR3w1y43Dohd6yJsjfneYzI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=htNY5KShJHGquRIYmc0kGPMlIOYfxGzaU45FJyBATiQO60tgicqPidk/IY9oTZvWM ZeXJ3efq0+kbi4QqMXYaKBYCqf7P3cTlsEvyfnimLXTfqapvfuqzV4Zrav2x5aSnGI cI3JgPc1cMPIDFZbc7DZpUmo+PqXG+B6FKOYLW68= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, John Garry , Ian Rogers , Alexander Shishkin , Jiri Olsa , Kajol Jain , Mark Rutland , Namhyung Kim , Peter Zijlstra , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 5.12 114/178] perf metricgroup: Return error code from metricgroup__add_metric_sys_event_iter() Date: Mon, 21 Jun 2021 18:15:28 +0200 Message-Id: <20210621154926.650552769@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210621154921.212599475@linuxfoundation.org> References: <20210621154921.212599475@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: John Garry [ Upstream commit fe7a98b9d9b36e5c8a22d76b67d29721f153f66e ] The error code is not set at all in the sys event iter function. This may lead to an uninitialized value of "ret" in metricgroup__add_metric() when no CPU metric is added. Fix by properly setting the error code. It is not necessary to init "ret" to 0 in metricgroup__add_metric(), as if we have no CPU or sys event metric matching, then "has_match" should be 0 and "ret" is set to -EINVAL. However gcc cannot detect that it may not have been set after the map_for_each_metric() loop for CPU metrics, which is strange. Fixes: be335ec28efa8 ("perf metricgroup: Support adding metrics for system PMUs") Signed-off-by: John Garry Acked-by: Ian Rogers Cc: Alexander Shishkin Cc: Jiri Olsa Cc: Kajol Jain Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lore.kernel.org/lkml/1623335580-187317-3-git-send-email-john.garry@huawei.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/metricgroup.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 1af71ac1cc68..939aed36e0c2 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -1072,16 +1072,18 @@ static int metricgroup__add_metric_sys_event_iter(struct pmu_event *pe, ret = add_metric(d->metric_list, pe, d->metric_no_group, &m, NULL, d->ids); if (ret) - return ret; + goto out; ret = resolve_metric(d->metric_no_group, d->metric_list, NULL, d->ids); if (ret) - return ret; + goto out; *(d->has_match) = true; - return *d->ret; +out: + *(d->ret) = ret; + return ret; } static int metricgroup__add_metric(const char *metric, bool metric_no_group, -- 2.30.2