Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp4987729pxb; Sun, 6 Feb 2022 09:45:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJyKfRYhAaeMdyeDeOxHUr1JMfqoYVkD3szNN9p5enRq9Nay+hBqcXb9HC1YLEWkpqJAXvfg X-Received: by 2002:a63:90c1:: with SMTP id a184mr6224455pge.206.1644169529020; Sun, 06 Feb 2022 09:45:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644169529; cv=none; d=google.com; s=arc-20160816; b=lo++d4xPGhwUm9mcNrVRx5+kHvv0fHKei4FBJOOnLiBBUdXeP7Cjh2Atrh6FuRwvux Qx2rFJh9zwK05RwP0KzJRxXwnOogQoQrNUKNgY++Q00To2mSP/Dnw49Y4x7YFohpQQTe kYyXs8+I/yjcBvxXQF7kP9IDRzQT9JDmNfvrc9Eg0e1PJWF8LJ3hUd3/+WE+Dg8mArYR RtTPoy+lby6MqJ2IFE34jkh/Fjb0CGZ8gfzKnPkuA1eW9jPVxlI6l7YMJCzVc2sGz1iu 83LrTx55yYTed2xS37BEqrnLeOD1xD9Evvt1QkRfg4TPvYmzKvV87IeutmVWWHoJTgJ6 oy5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=vaSqgE6r7uuTNeCf7vJPzhyWyOi8uPO8VeRBSs+O0eg=; b=lpEr/tyMhhqa9uFC8MG7bTbLm4yh8V7ric86pS0mcu6TtZHZhJAn3K+VEwxalshvqz o6CnWPy8yPYgB6/tb8ZUAolmAzOKwfELAsD1MbDQKV2be64a0qCAZ8/tYRXHQrzzuOU3 da14JgynRmOz7zb+GirruTk/Nf6cQYJEXGMrqVLA2lJ5+i9K1ytyFFZ2Yuym3DQhSepN px8XgvfNLrpMWnVHsNl0syogkzTOt4cTwYpyPIRjFEz1FQB0e6N9EzQAssBMJzVdYN5H YAZ8kBnoyG98KdD/GEtPiwabBo69Mf5mv+xY5UniEvij/DFfATxAEgNx1+IyYOGsctMR S9lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LxCfANQ8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lk14si866626pjb.106.2022.02.06.09.45.15; Sun, 06 Feb 2022 09:45:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LxCfANQ8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234607AbiBFLxG (ORCPT + 99 others); Sun, 6 Feb 2022 06:53:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234592AbiBFLld (ORCPT ); Sun, 6 Feb 2022 06:41:33 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70AF2C06173B; Sun, 6 Feb 2022 03:41:32 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0703760F6A; Sun, 6 Feb 2022 11:41:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B856C340E9; Sun, 6 Feb 2022 11:41:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1644147691; bh=FSobEMJAK/NwOtYWPruGcvTq24jw7zYFBv6+hsMP0eI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=LxCfANQ8XIuBZsh2jOoR+dU53Px+UhlQLmk9ig3nL1U2FYTtackbUCe4gMoYWarex R1hfoLhgYFoGssT5Zs60s7Si9FfGZxgaSdtbHTSnrdxFzZ1fWrEjZWB8DuOdp0DBH0 8AyMotMC0wmS6ZauG5HqlEPQnpiPP+GqLNFwf3ZkZUn8lwJSSYya4fgk1OS1zvdNMV SsiJ3pUQfdrCX4BV6v/h7zLgaKyXNLV8d9wDiRU/2FCkpWKx5FhTS0mMuoyi2J+3ZX EyGX8wVENcuBxGKKgmTPSXzfDwLn82QP3mnBAJoW4cnygBtsfkd1XFLmcO1Sh7SvDU GOfBF4g3xskvg== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id E9872404A6; Sun, 6 Feb 2022 08:41:28 -0300 (-03) Date: Sun, 6 Feb 2022 08:41:28 -0300 From: Arnaldo Carvalho de Melo To: James Clark Cc: Ameer Hamza , German Gomez , peterz@infradead.org, mingo@redhat.com, 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 Subject: Re: [PATCH] perf session: check for null pointer before derefernce Message-ID: References: <20220124150001.93145-1-amhamza.mgc@gmail.com> <7c068167-e8bb-74f3-97d9-dd0c5858ee19@arm.com> <20220124202907.GA5741@hamza-OptiPlex-7040> <8983b963-2139-ecb3-3a31-b5e225db389c@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8983b963-2139-ecb3-3a31-b5e225db389c@arm.com> X-Url: http://acmel.wordpress.com X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Tue, Jan 25, 2022 at 09:35:49AM +0000, James Clark escreveu: > > > 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 Thanks, applied. - Arnaldo > > > > 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 > > -- - Arnaldo