linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: Przemek Kitszel <przemyslaw.kitszel@intel.com>
Cc: Jiri Pirko <jiri@resnulli.us>,
	netdev@vger.kernel.org, "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Shannon Nelson <shannon.nelson@amd.com>,
	Michael Chan <michael.chan@broadcom.com>,
	Cai Huoqing <cai.huoqing@linux.dev>,
	George Cherian <george.cherian@marvell.com>,
	Danielle Ratson <danieller@nvidia.com>,
	Moshe Shemesh <moshe@nvidia.com>,
	Saeed Mahameed <saeedm@nvidia.com>,
	Ariel Elior <aelior@marvell.com>,
	Manish Chopra <manishc@marvell.com>,
	Igor Russkikh <irusskikh@marvell.com>,
	Coiby Xu <coiby.xu@gmail.com>,
	Brett Creeley <brett.creeley@amd.com>,
	Sunil Goutham <sgoutham@marvell.com>,
	Linu Cherian <lcherian@marvell.com>,
	Geetha sowjanya <gakula@marvell.com>,
	Jerin Jacob <jerinj@marvell.com>, hariprasad <hkelam@marvell.com>,
	Subbaraya Sundeep <sbhatta@marvell.com>,
	Ido Schimmel <idosch@nvidia.com>, Petr Machata <petrm@nvidia.com>,
	Eran Ben Elisha <eranbe@nvidia.com>,
	Aya Levin <ayal@mellanox.com>, Leon Romanovsky <leon@kernel.org>,
	linux-kernel@vger.kernel.org,
	Benjamin Poirier <bpoirier@suse.com>,
	Jesse Brandeburg <jesse.brandeburg@intel.com>,
	Jiri Pirko <jiri@nvidia.com>
Subject: Re: [PATCH net-next v3 01/11] devlink: retain error in struct devlink_fmsg
Date: Thu, 19 Oct 2023 15:00:37 +0200	[thread overview]
Message-ID: <20231019130037.GI2100445@kernel.org> (raw)
In-Reply-To: <20231018202647.44769-2-przemyslaw.kitszel@intel.com>

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 <jesse.brandeburg@intel.com>
> Reviewed-by: Jiri Pirko <jiri@nvidia.com>
> Signed-off-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>

...

> @@ -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
> 

  reply	other threads:[~2023-10-19 13:01 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-18 20:26 [PATCH net-next v3 00/11] devlink: retain error in struct devlink_fmsg Przemek Kitszel
2023-10-18 20:26 ` [PATCH net-next v3 01/11] " Przemek Kitszel
2023-10-19 13:00   ` Simon Horman [this message]
2023-10-19 21:49     ` Przemek Kitszel
2023-10-18 20:26 ` [PATCH net-next v3 02/11] netdevsim: devlink health: use retained error fmsg API Przemek Kitszel
2023-10-19 15:56   ` Simon Horman
2023-10-18 20:26 ` [PATCH net-next v3 03/11] pds_core: " Przemek Kitszel
2023-10-19 15:56   ` Simon Horman
2023-10-18 20:26 ` [PATCH net-next v3 04/11] bnxt_en: " Przemek Kitszel
2023-10-19 15:56   ` Simon Horman
2023-10-18 20:26 ` [PATCH net-next v3 05/11] hinic: " Przemek Kitszel
2023-10-19 15:57   ` Simon Horman
2023-10-18 20:26 ` [PATCH net-next v3 06/11] octeontx2-af: " Przemek Kitszel
2023-10-19 15:57   ` Simon Horman
2023-10-18 20:26 ` [PATCH net-next v3 07/11] mlxsw: core: " Przemek Kitszel
2023-10-19 15:57   ` Simon Horman
2023-10-18 20:26 ` [PATCH net-next v3 08/11] net/mlx5: " Przemek Kitszel
2023-10-19 15:58   ` Simon Horman
2023-10-24  9:50   ` Dan Carpenter
2023-10-24 13:43     ` Przemek Kitszel
2023-10-18 20:26 ` [PATCH net-next v3 09/11] qed: " Przemek Kitszel
2023-10-19 15:58   ` Simon Horman
2023-10-18 20:26 ` [PATCH net-next v3 10/11] staging: qlge: " Przemek Kitszel
2023-10-19 15:58   ` Simon Horman
2023-10-18 20:26 ` [PATCH net-next v3 11/11] devlink: convert most of devlink_fmsg_*() to return void Przemek Kitszel
2023-10-19 13:44 ` [PATCH net-next v3 00/11] devlink: retain error in struct devlink_fmsg Jiri Pirko
2023-10-19 21:50   ` Przemek Kitszel
2023-10-20  9:36     ` Jiri Pirko
2023-10-20 10:40 ` patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231019130037.GI2100445@kernel.org \
    --to=horms@kernel.org \
    --cc=aelior@marvell.com \
    --cc=ayal@mellanox.com \
    --cc=bpoirier@suse.com \
    --cc=brett.creeley@amd.com \
    --cc=cai.huoqing@linux.dev \
    --cc=coiby.xu@gmail.com \
    --cc=danieller@nvidia.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=eranbe@nvidia.com \
    --cc=gakula@marvell.com \
    --cc=george.cherian@marvell.com \
    --cc=hkelam@marvell.com \
    --cc=idosch@nvidia.com \
    --cc=irusskikh@marvell.com \
    --cc=jerinj@marvell.com \
    --cc=jesse.brandeburg@intel.com \
    --cc=jiri@nvidia.com \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=lcherian@marvell.com \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=manishc@marvell.com \
    --cc=michael.chan@broadcom.com \
    --cc=moshe@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=petrm@nvidia.com \
    --cc=przemyslaw.kitszel@intel.com \
    --cc=saeedm@nvidia.com \
    --cc=sbhatta@marvell.com \
    --cc=sgoutham@marvell.com \
    --cc=shannon.nelson@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).