From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84A43C433DF for ; Tue, 20 Oct 2020 08:38:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2E1B822240 for ; Tue, 20 Oct 2020 08:38:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392089AbgJTIip (ORCPT ); Tue, 20 Oct 2020 04:38:45 -0400 Received: from lhrrgout.huawei.com ([185.176.76.210]:2995 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2389211AbgJTIio (ORCPT ); Tue, 20 Oct 2020 04:38:44 -0400 Received: from lhreml724-chm.china.huawei.com (unknown [172.18.7.108]) by Forcepoint Email with ESMTP id D81CDD4F6E017D6BAAEB; Tue, 20 Oct 2020 09:38:42 +0100 (IST) Received: from [127.0.0.1] (10.47.3.97) by lhreml724-chm.china.huawei.com (10.201.108.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1913.5; Tue, 20 Oct 2020 09:38:41 +0100 Subject: Re: [PATCH 1/2] perf jevents: Tidy error handling To: kajoljain , Namhyung Kim CC: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Yao Jin , , linux-kernel , Linuxarm References: <1603121908-53543-1-git-send-email-john.garry@huawei.com> <1603121908-53543-2-git-send-email-john.garry@huawei.com> From: John Garry Message-ID: <3fda581b-3f2b-5dce-b388-916117d20e7c@huawei.com> Date: Tue, 20 Oct 2020 09:35:28 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.1.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.47.3.97] X-ClientProxiedBy: lhreml708-chm.china.huawei.com (10.201.108.57) To lhreml724-chm.china.huawei.com (10.201.108.75) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 20/10/2020 09:14, kajoljain wrote: > > > On 10/20/20 11:13 AM, Namhyung Kim wrote: >> Hello, >> >> On Tue, Oct 20, 2020 at 12:42 AM John Garry wrote: >>> >>> There is much duplication in the error handling for directory traversing >>> for processing JSONs. >>> >>> Factor out the common code to tidy a bit. >>> >>> Signed-off-by: John Garry >>> --- >> [SNIP] >>> -empty_map: >>> +err_processing_std_arch_event_dir: >>> + err_string_ext = " for std arch event"; >>> +err_processing_dir: >>> + if (verbose || rc > 0) { >>> + pr_info("%s: Error walking file tree %s%s\n", prog, ldirname, >>> + err_string_ext); >> >> This was printed only if verbose is set but now changed. > pr_info() is silenced if verbose is unset, so in effect it is the same - see pr_info() definition in json.h > Hi John, > Yes I agree with Namhyung. > So, this is our original checks > > if (rc && verbose) { > pr_info("%s: Error walking file tree %s\n", prog, ldirname); > goto empty_map; > } else if (rc < 0) { > /* Make build fail */ > fclose(eventsfp); > free_arch_std_events(); > ret = 1; > goto out_free_mapfile; > } else if (rc) { > goto empty_map; > } > > May be we can use similar checks: > > if( verbose) > pr_info("%s: Error walking file tree %s%s\n", prog, ldirname,err_string_ext); > if(rc > 0) > empty_map = 1; > else > ret = 1; > Not that it matters much, this logic is slightly different for verbose set and rc < 0. I don't mind going with that, so let me know. Thanks for checking, John > Thanks, > Kajol Jain > >> >> Thanks >> Namhyung >> >> >>> + empty_map = 1; >>> + } else { >>> + ret = 1; >>> + } >>> +err_close_eventsfp: >>> fclose(eventsfp); >>> - create_empty_mapping(output_file); >>> + if (empty_map) >>> + create_empty_mapping(output_file); >>> +err_out: >>> free_arch_std_events(); >>> -out_free_mapfile: >>> free(mapfile); >>> return ret; >>> } >>> -- >>> 2.26.2 >>> > . >