Subject: Re: [PATCH net-next 2/8] devlink: use min_t to calculate data_size

From: Jakub Kicinski <[email-masked]>
Date: Fri, 18 Nov 2022 17:36:28 -0800

On Thu, 17 Nov 2022 14:07:57 -0800 Jacob Keller wrote:
> The calculation for the data_size in the devlink_nl_read_snapshot_fill
> function uses an if statement that is better expressed using the min_t
> macro.
> 
> Noticed-by: Jakub Kicinski <[email-masked]>

I'm afraid that's not a real tag. You can just drop it, 
I get sufficient credits.

> diff --git a/net/core/devlink.c b/net/core/devlink.c
> index 96afc7013959..932476956d7e 100644
> --- a/net/core/devlink.c
> +++ b/net/core/devlink.c
> @@ -6410,14 +6410,10 @@ static int devlink_nl_region_read_snapshot_fill(struct sk_buff *skb,
>  	*new_offset = start_offset;
>  
>  	while (curr_offset < end_offset) {
> -		u32 data_size;
> +		u32 data_size = min_t(u32, end_offset - curr_offset,
> +				      DEVLINK_REGION_READ_CHUNK_SIZE);

nit: don't put multi-line statements on the declaration line if it's 
not the only variable.

>  		u8 *data;
>  
> -		if (end_offset - curr_offset < DEVLINK_REGION_READ_CHUNK_SIZE)
> -			data_size = end_offset - curr_offset;
> -		else
> -			data_size = DEVLINK_REGION_READ_CHUNK_SIZE;