Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp4241233pxb; Tue, 25 Jan 2022 06:30:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJxKVRva0I9QkKgxSkzRr3O3cEmmLk0WUBjbvhwOZ5EiIqyvHhhn+vLDiyUWN5mFwVeeXHY5 X-Received: by 2002:a63:7c48:: with SMTP id l8mr15381260pgn.383.1643121048191; Tue, 25 Jan 2022 06:30:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643121048; cv=none; d=google.com; s=arc-20160816; b=dfVcIZlUg3eRL+uS7DEXU6pt50ev/XPp9bVjAOhLQ5aQj/Kxv/Z5NtLmLP2+bY7su2 vmNfdgYIxky4+h7ZPa0dmxSLIjT8Wv/d0uw6a3AkfdNzYzX4njFc49ETmFB0i8qFmATM TB0rEloS6ZfEuV+djAh3NZUU1eyFhKnmjf+dazKwC93oW4r4X4ij0qD7FB59qR9p1eH8 x2IdrXvuEwWd04SrLZAZq8hvbookZJjn82XMDMBXuIHCRRpy65ZawUihgKjUGQK9UlFY Cr6hvddBWnNvrEHILC9LO/ItW6daxfBZNh/TdRe7kQjzMXufdTIQz+ioy1zuGa0niQAw 9S9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=VFY078Uq84nYT7VHfPaT1WMAj4xvD2DmF2WmOfGWFzo=; b=s4acFF//bvpjIaIpVBuFaeQAa1TtVOgbq4Bx7vJkkYtEyw/l3YrLa7jlYOiQMHT2OF 4XQGiuvOBVrwVEvEv5nLMaFhiSwMbbHyeR2+AxI3UKCqYktnpTcYt7epj2qywBfhCFFd Y29LehHBwbdbzvoGsz8sFmPX60NUyhS44aybYeaNE0wrIPBe5Znoj6RCZ8s5Pw4R+72I sPF1sNLCTEy4bBiSOLW2bFGqHDvQmdZmxxwt8kMMQacqn3xpFll7AuPm6dpjdq5APeiv tzi9qOE82rzB44SegY2k+J/9aRG7rpE3gNhxEXqv3hEMBTqyuaB8VPhiE++WkxCaSQgh tHag== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u21si18164651pfk.181.2022.01.25.06.30.35; Tue, 25 Jan 2022 06:30:48 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236162AbiAYJkD (ORCPT + 99 others); Tue, 25 Jan 2022 04:40:03 -0500 Received: from foss.arm.com ([217.140.110.172]:58436 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1456108AbiAYJfy (ORCPT ); Tue, 25 Jan 2022 04:35:54 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 35552D6E; Tue, 25 Jan 2022 01:35:53 -0800 (PST) Received: from [10.57.40.103] (unknown [10.57.40.103]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 347053F793; Tue, 25 Jan 2022 01:35:51 -0800 (PST) Subject: Re: [PATCH] perf session: check for null pointer before derefernce To: Ameer Hamza Cc: German Gomez , peterz@infradead.org, mingo@redhat.com, acme@kernel.org, rickyman7@gmail.com, alexey.v.bayduraev@linux.intel.com, adrian.hunter@intel.com, leo.yan@linaro.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org References: <20220124150001.93145-1-amhamza.mgc@gmail.com> <7c068167-e8bb-74f3-97d9-dd0c5858ee19@arm.com> <20220124202907.GA5741@hamza-OptiPlex-7040> From: James Clark Message-ID: <8983b963-2139-ecb3-3a31-b5e225db389c@arm.com> Date: Tue, 25 Jan 2022 09:35:49 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <20220124202907.GA5741@hamza-OptiPlex-7040> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 24/01/2022 20:29, Ameer Hamza wrote: > On Mon, Jan 24, 2022 at 03:30:17PM +0000, James Clark wrote: >> >> >> On 24/01/2022 15:00, Ameer Hamza wrote: >>> Move null pointer check before dereferncing the variable >>> >>> Addresses-Coverity: 1497622 ("Derereference before null check") >>> >>> Signed-off-by: Ameer Hamza >>> --- >>> tools/perf/util/session.c | 2 +- >>> 1 file changed, 1 insertion(+), 1 deletion(-) >>> >>> diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c >>> index f19348dddd55..e1014ab62c10 100644 >>> --- a/tools/perf/util/session.c >>> +++ b/tools/perf/util/session.c >>> @@ -1503,11 +1503,11 @@ static int machines__deliver_event(struct machines *machines, >>> ++evlist->stats.nr_unknown_id; >>> return 0; >>> } >>> - dump_sample(evsel, event, sample, perf_env__arch(machine->env)); >>> if (machine == NULL) { >>> ++evlist->stats.nr_unprocessable_samples; >>> return 0; >>> } >>> + dump_sample(evsel, event, sample, perf_env__arch(machine->env)); >>> return evlist__deliver_sample(evlist, tool, event, sample, evsel, machine); >>> case PERF_RECORD_MMAP: >>> return tool->mmap(tool, event, sample, machine); >>> >> >> Hi Ameer, >> >> This mistake was made recently, but I don't think your change is the desired behavior. >> >> It should be possible to dump stuff if machine is null. null or an empty string >> should be passed to dump_sample(). It looks like some of the printfs still attempt to >> show something in this case, although I didn't check them all. > > Hi James, > > Thank you for your response. I understand your point. > > Do you think following changes would be ok? Yep looks good. With that change: Reviewed-by: James Clark > > diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c > index f19348dddd55..210eeee3dd70 100644 > --- a/tools/perf/util/session.c > +++ b/tools/perf/util/session.c > @@ -1503,11 +1503,12 @@ static int machines__deliver_event(struct machines *machines, > ++evlist->stats.nr_unknown_id; > return 0; > } > - dump_sample(evsel, event, sample, perf_env__arch(machine->env)); > if (machine == NULL) { > ++evlist->stats.nr_unprocessable_samples; > + dump_sample(evsel, event, sample, perf_env__arch(NULL)); > return 0; > } > + dump_sample(evsel, event, sample, perf_env__arch(machine->env)); > return evlist__deliver_sample(evlist, tool, event, sample, evsel, machine); > case PERF_RECORD_MMAP: > return tool->mmap(tool, event, sample, machine); > > Thanks, > Hamza >