netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon@kernel.org>
To: David Laight <David.Laight@aculab.com>
Cc: Anand Khoje <anand.a.khoje@oracle.com>,
	"linux-rdma@vger.kernel.org" <linux-rdma@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"saeedm@mellanox.com" <saeedm@mellanox.com>,
	"tariqt@nvidia.com" <tariqt@nvidia.com>,
	"edumazet@google.com" <edumazet@google.com>,
	"kuba@kernel.org" <kuba@kernel.org>,
	"pabeni@redhat.com" <pabeni@redhat.com>,
	"davem@davemloft.net" <davem@davemloft.net>
Subject: Re: [PATCH v4] net/mlx5: Reclaim max 50K pages at once
Date: Mon, 15 Jul 2024 13:23:59 +0300	[thread overview]
Message-ID: <20240715102359.GA55002@unreal> (raw)
In-Reply-To: <c702670609914da89e934879b5c89de7@AcuMS.aculab.com>

On Mon, Jul 15, 2024 at 08:22:19AM +0000, David Laight wrote:
> From: Leon Romanovsky
> > Sent: 01 July 2024 12:50
> > To: David Laight <David.Laight@ACULAB.COM>
> ...
> > > > BTW, this can be written as:
> > > > 	req->npages = max_t(s32, npages, MAX_RECLAIM_NPAGES);
> > >
> > > That shouldn't need all the (s32) casts.
> > 
> > #define doesn't have a type, so it is better to be explicit here.
> 
> The constant has a type, the cast just hides any checking that might be done.

According to the C standard, type can be int, long int or long long int:
 "The type of an integer constant is the first of the corresponding list
 in which its value can be represented.".

> Would you really write:
> 	if ((s32)npages > (s32)-50000)
> 		...
> Because that is what you are generating.
>

So instead of comparing s32 with int, which can be misleading. I prefer to compare s32 with s32.
 
> Here it probably doesn't matter, but it is really bad practise.
> If, for example, 'npages' is 64 bit than the cast can change the value.

In our case npages is s32.

Thanks

      reply	other threads:[~2024-07-15 10:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-19 13:28 [PATCH v4] net/mlx5: Reclaim max 50K pages at once Anand Khoje
2024-06-24  9:57 ` Leon Romanovsky
2024-06-24 15:48   ` Anand Khoje
2024-06-28 15:13   ` David Laight
2024-07-01 11:49     ` Leon Romanovsky
2024-07-15  8:22       ` David Laight
2024-07-15 10:23         ` Leon Romanovsky [this message]

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=20240715102359.GA55002@unreal \
    --to=leon@kernel.org \
    --cc=David.Laight@aculab.com \
    --cc=anand.a.khoje@oracle.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=saeedm@mellanox.com \
    --cc=tariqt@nvidia.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).