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=-5.5 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 5BFBEC2D0A3 for ; Thu, 29 Oct 2020 10:55:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0D08F20738 for ; Thu, 29 Oct 2020 10:55:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726934AbgJ2Kz4 (ORCPT ); Thu, 29 Oct 2020 06:55:56 -0400 Received: from foss.arm.com ([217.140.110.172]:60384 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726025AbgJ2Kz4 (ORCPT ); Thu, 29 Oct 2020 06:55:56 -0400 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 30E0213A1; Thu, 29 Oct 2020 03:55:55 -0700 (PDT) Received: from [192.168.2.22] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3D6B13F66E; Thu, 29 Oct 2020 03:55:45 -0700 (PDT) Subject: Re: [PATCH v5 06/21] perf arm-spe: Refactor printing string to buffer To: Leo Yan Cc: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Dave Martin , Wei Li , James Clark , Al Grant , "linux-kernel@vger.kernel.org" References: <20201029071927.9308-1-leo.yan@linaro.org> <20201029071927.9308-7-leo.yan@linaro.org> <20201029105159.GG16862@leoy-ThinkPad-X240s> From: =?UTF-8?Q?Andr=c3=a9_Przywara?= Organization: ARM Ltd. Message-ID: Date: Thu, 29 Oct 2020 10:54:37 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <20201029105159.GG16862@leoy-ThinkPad-X240s> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 29/10/2020 10:51, Leo Yan wrote: > Hi Andre, > > On Thu, Oct 29, 2020 at 10:23:39AM +0000, Andr� Przywara wrote: > > [...] > >>> +static int arm_spe_pkt_snprintf(int *err, char **buf_p, size_t *blen, >>> + const char *fmt, ...) >>> +{ >>> + va_list ap; >>> + int ret; >>> + >>> + va_start(ap, fmt); >>> + ret = vsnprintf(*buf_p, *blen, fmt, ap); >>> + va_end(ap); >>> + >>> + if (ret < 0) { >>> + if (err && !*err) >>> + *err = ret; >>> + } else { >>> + *buf_p += ret; >>> + *blen -= ret; >>> + } >>> + >>> + return ret; >>> +} >> >> So this now implements the old behaviour of ignoring previous errors, in >> all cases, since we don't check for errors and bail out in the callers. >> >> If you simply check for validity of err and for it being 0 before >> proceeding with the va_start() above, this should be fixed. > > I think you are suggesting below code, could you take a look for it > before I proceed to respin new patch?> > static int arm_spe_pkt_snprintf(int *err, char **buf_p, size_t *blen, > const char *fmt, ...) > { > va_list ap; > int ret; > > /* Bail out if any error occurred */ > if (err && *err) > return *err; > > va_start(ap, fmt); > ret = vsnprintf(*buf_p, *blen, fmt, ap); > va_end(ap); > > if (ret < 0) { > if (err && !*err) > *err = ret; > } else { > *buf_p += ret; > *blen -= ret; > } > > return ret; > } Yes, this is what I had in mind. Cheers, Andre