From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753332AbbIJIY7 (ORCPT ); Thu, 10 Sep 2015 04:24:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54553 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751305AbbIJIY4 (ORCPT ); Thu, 10 Sep 2015 04:24:56 -0400 Date: Thu, 10 Sep 2015 10:24:52 +0200 From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , lkml , David Ahern , Ingo Molnar , Namhyung Kim , Peter Zijlstra , Matt Fleming , =?iso-8859-1?Q?Rapha=EBl?= Beamonte Subject: Re: [PATCH 4/5] perf tools: Propagate error info from tp_format Message-ID: <20150910082452.GC19014@krava.brq.redhat.com> References: <1441615087-13886-1-git-send-email-jolsa@kernel.org> <1441615087-13886-5-git-send-email-jolsa@kernel.org> <20150909205813.GV3475@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150909205813.GV3475@kernel.org> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 09, 2015 at 05:58:13PM -0300, Arnaldo Carvalho de Melo wrote: SNIP > This kind of stuff is ok, as evsel is a local variable and you kept the > interface for perf_evsel__syscall_newtp(), i.e. it returns NULL if a new > evsel can't be instantiated. > > Ok, but that is a different interface than the one used by > perf_evsel__newtp(), that also instantiates a new evsel. > > So when one thinks about "foo__new()" we now need to check which one of > the two interfaces it uses, if err.h or if the old NULL based failure > reporting one. > > Double tricky if it is foo__new() and foo__new_variant(), as > perf_evsel__syscall_newtp() and perf_evsel__newtp(), i.e. both will > return a "struct perf_evsel" instance, but one using err.h, the other > use NULL. > > Ok, you marked the ones using a comment, wonder if we couldn't use > 'sparse' somehow here, is it used to check IS_ERR() usage in the kernel? hum, not sure.. will check ;-) at least we could mark related functions with __must_check to force the return value check > > Ah, but what about this in trace__event_handler() in builtin-trace.c? > > if (evsel->tp_format) { > event_format__fprintf(evsel->tp_format, sample->cpu, > sample->raw_data, sample->raw_size, > trace->output); > } > > > Don't we have to use IS_ERR() here? Ok, no, because if setting up > evsel->tp_format fails, then that evsel will be destroyed and > perf_evsel__newtp() will return ERR_PTR(), so it is ok not no use > ERR_PTR(evsel->tp_format) because it will only be != NULL when it was > successfully set up. > > But then, in perf_evsel__newtp_idx if zalloc() fails we will not return > ERR_PTR(), but instead NULL, a-ha, this one seems to be a real bug, no? hate those allocations in declarations.. never do any good ;-) yep, NULL is not an error, so it's real bug, attached patch should fix it thanks, jirka --- diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 08c20ee4e27d..162973bec713 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -256,7 +256,7 @@ struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int perf_evsel__init(evsel, &attr, idx); } - return evsel; + return evsel ?: ERR_PTR(err); out_free: zfree(&evsel->name);