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.4 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, 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 28E8AC2D0A3 for ; Thu, 29 Oct 2020 11:06:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9E21020759 for ; Thu, 29 Oct 2020 11:06:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="EphyJo2K" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726999AbgJ2LGQ (ORCPT ); Thu, 29 Oct 2020 07:06:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726078AbgJ2LGP (ORCPT ); Thu, 29 Oct 2020 07:06:15 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A6DCC0613CF for ; Thu, 29 Oct 2020 04:06:14 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id o129so2057728pfb.1 for ; Thu, 29 Oct 2020 04:06:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=AjypJEOlHsBxT2MXyKdhhIhqcKDZCftJZ37NZpTJExY=; b=EphyJo2KzSt2N6h/sjIrO+h4VKDgDqcfHRCCKb2I4IZ+1jpajOeVj0tFz78kPJKO+L d0yClkIB6+Dn17GYpFYLiOVrJIP/CgY2ibyzB+tHhkE+y8+mH7ArMe7khNfKLglhmnRD VBteZaGip3EoJMGg1o1Rn31a/tUBE7A0FCN+0CVoimPiV7eQHMs8zpxIzWVXuGEWjS70 ZLYNVKxv3SGZTYrRh/vnFH8nFTe4DhbTxkGFvuiiMLyo1jBoAEH0djhTqsFykb+F/GRT veyKEDtpMqQ3NKMBqeurZNK/sAISwobNycUgCwjaBBujIwPUHzyn4OBjBu0udl3c0U2e HbJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=AjypJEOlHsBxT2MXyKdhhIhqcKDZCftJZ37NZpTJExY=; b=rZUxS7lWth/HUORqLhOgbcC2MGmLpoS4mp6ilXUUdvmDUWhwRfQl4PDEXBaR7UFGTY r9g6TJ5jWYqr3/z+cdLk+go0XVhyagj5je/AZ5tV6A58f3SzSs+/breNeKL7pSvXL8dj OtzUt/dx/qfgc4qdhM1BCw83SinaIQnWwfpZTnzHZ/7hrOCgnEIWJsLPVrTbHIG7iNVo E7klQXjJzFzN7/s7zBmzYNhtAyFLsCK7uHS2fjNwySJap48xtn2Tu2TSyEUhba/ADnzB YEz5x2zG8j/JFjjdjRfsuvpxRmHmWJjjtXL8F7eJIEW1+j3PKA/QwDsSNShGFKsj359/ s+1g== X-Gm-Message-State: AOAM53070rBN9LC2cn89ikX9m/vd6xQxzPFeJ3HxduYzWI4vYY0CHyOX Y3jshOtP9ryQFSXvn66sQU4+IQ== X-Google-Smtp-Source: ABdhPJzD8q3gApKC8ryynmFbUbGBjRUWuI4M9lU3NSGVvgD6/TpTdnTyvIMFTTikdTyfIJM8ekgtkg== X-Received: by 2002:a17:90a:a898:: with SMTP id h24mr3826758pjq.179.1603969573827; Thu, 29 Oct 2020 04:06:13 -0700 (PDT) Received: from leoy-ThinkPad-X240s ([103.141.182.112]) by smtp.gmail.com with ESMTPSA id h26sm138984pfq.139.2020.10.29.04.06.09 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 29 Oct 2020 04:06:13 -0700 (PDT) Date: Thu, 29 Oct 2020 19:06:05 +0800 From: Leo Yan To: =?iso-8859-1?Q?Andr=E9?= Przywara 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" Subject: Re: [PATCH v5 06/21] perf arm-spe: Refactor printing string to buffer Message-ID: <20201029110605.GI16862@leoy-ThinkPad-X240s> References: <20201029071927.9308-1-leo.yan@linaro.org> <20201029071927.9308-7-leo.yan@linaro.org> <20201029105159.GG16862@leoy-ThinkPad-X240s> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 29, 2020 at 10:54:37AM +0000, André Przywara wrote: > 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. Thanks for confirmation, Andre. Leo