Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp331226rdb; Thu, 19 Oct 2023 06:02:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFWr2MiJJRZK/GkKVpw19smJql2Vpi2i9XmISafsGI4OQRYOYsJHO4AOWIcbqWEPZx4BMHd X-Received: by 2002:a17:90b:38c8:b0:27d:2c3c:7e25 with SMTP id nn8-20020a17090b38c800b0027d2c3c7e25mr1977407pjb.46.1697720532682; Thu, 19 Oct 2023 06:02:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720532; cv=none; d=google.com; s=arc-20160816; b=Y57HQlVIp91KOPyzRbmuW6kFzlsPynSmY12tHE8Vyz1LDeDCpjt6J4mKWfUUb0lN/o 338qWqpw2glzZbsvkxTiNtRNvg3PRqH1deDpTS0PdPnL34S6vBfSMQmazjAo53NAG7jj jL4MszOvgDbdAYIwPLEEBoM/nBQhRI5KscgZgexMRqL5suGsiyCZbUFCZQcTB4YuRNwf lDlTRDNWK35O18fRqujKsqZeK3k9d2QahD/vlmQ+ERHeR9qvBxP263JeiMqKi+foh1YQ TFyJq7fbITjrXq1SK14SKI3tX8pyJSvNrJfK8mrY7DL8NoW/FKV0ZGPwdPo72C/UZQu1 Tqww== 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=Oj0nK2yqayBBaFGHVEIpmVso6Iaruy2xorUQKVdBtPk=; fh=AqS6ZF42sqBD08bMEJvkD9K/OSoDMA3YWnJnQ5ICYVM=; b=nLv2rttsVjRUiBCiK29CDaqg71hlKMaS++E1PgnptrPj5/as19TVReTaxEpgx+t1aZ uXFuZHM1B6FvHeQLs/J8YcrgxlUsvj7TaqVSaQW0Vk2CfPGuOMLAOs/DYp5+AJKF4gOa sWk5onz8MBUj+fhmyZ4IGYs06lRayx6W1JHpCMp/RvqmuDSWfGwIoTec2PvYJLo/P4vR 77yXxc848DOhBENW468G3eVhUjCEVbKNhNTqSXo+mzlGoCSj4V3bvSRL1hiVjNkcuYzS rQxp1nMHv01Jw+S6Atswqowy4crRwP124FU+SpJX16UJZc45jP/diUXy87k07W8txRLn +jjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ryaqfFw+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id mi11-20020a17090b4b4b00b0027ced8e1837si2071332pjb.180.2023.10.19.06.02.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 06:02:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ryaqfFw+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 0A0FE80B81C1; Thu, 19 Oct 2023 06:02:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235399AbjJSNBv (ORCPT + 99 others); Thu, 19 Oct 2023 09:01:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235423AbjJSNBg (ORCPT ); Thu, 19 Oct 2023 09:01:36 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C6AA1737 for ; Thu, 19 Oct 2023 06:00:48 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F03D1C116AC; Thu, 19 Oct 2023 13:00:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697720448; bh=UaNVdnVtS+6Y8Bshaztbg+8lEOSi39R7ycoX+4dZ6pA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ryaqfFw+Um1JiXJ/cvml2Ts72RDlw1VPiTE4HrJJc83VENXKHBG9V3jrfo7BzweXJ nCq2j6VVCnj/fo9L7NyyXpzPJ61jsS8RGDvy1SohZCp4r5eW7sBqfps7Syn2QLlMue fGKx4RRFnojw3NO8i3Vd10Amvrz/CG1BM0NmpN4Odh/BmiLtmYXO6OPknPTkLumujH 6OGEkfXgW5uKna/ST3fNefqE4abgz9oIfM8MUzd7BLNqDXGN859DLI7oHfvhcU/XO9 DkZZTCMojrif7yFjcdyqR7hAit9YA3jkQ2e7qrsOmRoRLc2Utd97u99taPCdBYm3+B 6SGCSUFP1/uCg== Date: Thu, 19 Oct 2023 15:00:37 +0200 From: Simon Horman To: Przemek Kitszel Cc: Jiri Pirko , netdev@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shannon Nelson , Michael Chan , Cai Huoqing , George Cherian , Danielle Ratson , Moshe Shemesh , Saeed Mahameed , Ariel Elior , Manish Chopra , Igor Russkikh , Coiby Xu , Brett Creeley , Sunil Goutham , Linu Cherian , Geetha sowjanya , Jerin Jacob , hariprasad , Subbaraya Sundeep , Ido Schimmel , Petr Machata , Eran Ben Elisha , Aya Levin , Leon Romanovsky , linux-kernel@vger.kernel.org, Benjamin Poirier , Jesse Brandeburg , Jiri Pirko Subject: Re: [PATCH net-next v3 01/11] devlink: retain error in struct devlink_fmsg Message-ID: <20231019130037.GI2100445@kernel.org> References: <20231018202647.44769-1-przemyslaw.kitszel@intel.com> <20231018202647.44769-2-przemyslaw.kitszel@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231018202647.44769-2-przemyslaw.kitszel@intel.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 19 Oct 2023 06:02:00 -0700 (PDT) On Wed, Oct 18, 2023 at 10:26:37PM +0200, Przemek Kitszel wrote: > Retain error value in struct devlink_fmsg, to relieve drivers from > checking it after each call. > Note that fmsg is an in-memory builder/buffer of formatted message, > so it's not the case that half baked message was sent somewhere. > > We could find following scheme in multiple drivers: > err = devlink_fmsg_obj_nest_start(fmsg); > if (err) > return err; > err = devlink_fmsg_string_pair_put(fmsg, "src", src); > if (err) > return err; > err = devlink_fmsg_something(fmsg, foo, bar); > if (err) > return err; > // and so on... > err = devlink_fmsg_obj_nest_end(fmsg); > > With retaining error API that translates to: > devlink_fmsg_obj_nest_start(fmsg); > devlink_fmsg_string_pair_put(fmsg, "src", src); > devlink_fmsg_something(fmsg, foo, bar); > // and so on... > devlink_fmsg_obj_nest_end(fmsg); > > What means we check error just when is time to send. > > Possible error scenarios are developer error (API misuse) and memory > exhaustion, both cases are good candidates to choose readability > over fastest possible exit. > > Note that this patch keeps returning errors, to allow per-driver conversion > to the new API, but those are not needed at this point already. > > This commit itself is an illustration of benefits for the dev-user, > more of it will be in separate commits of the series. > > Reviewed-by: Jesse Brandeburg > Reviewed-by: Jiri Pirko > Signed-off-by: Przemek Kitszel ... > @@ -1027,14 +934,12 @@ int devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name, Hi Przemek, The line before this hunk is: err = devlink_fmsg_binary_put(fmsg, value + offset, data_size); And, as of this patch, the implementation of devlink_fmsg_binary_pair_nest_start() looks like this: int devlink_fmsg_binary_put(struct devlink_fmsg *fmsg, const void *value, u16 value_len) { if (!fmsg->putting_binary) return -EINVAL; return devlink_fmsg_put_value(fmsg, value, value_len, NLA_BINARY); } Which may return an error, if the if condition is met, without setting fmsg->err. > if (err) > break; > /* Exit from loop with a break (instead of > - * return) to make sure putting_binary is turned off in > - * devlink_fmsg_binary_pair_nest_end > + * return) to make sure putting_binary is turned off > */ > } > > - end_err = devlink_fmsg_binary_pair_nest_end(fmsg); > - if (end_err) > - err = end_err; Prior to this patch, the value of err from the loop above was preserved, unless devlink_fmsg_binary_pair_nest_end generated an error. > + err = devlink_fmsg_binary_pair_nest_end(fmsg); But now it looks like this is only the case if fmsg->err corresponds to err when the loop was exited. Or in other words, the err returned by devlink_fmsg_binary_put() is not propagated to the caller if !fmsg->putting_binary. If so, is this intentional? > + fmsg->putting_binary = false; > > return err; > } > -- > 2.38.1 >