netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: Mahmoud Maatuq <mahmoudmatook.mm@gmail.com>,
	 linux-kernel@vger.kernel.org,  linux-kselftest@vger.kernel.org,
	 kuba@kernel.org,  netdev@vger.kernel.org,
	 willemdebruijn.kernel@gmail.com,  davem@davemloft.net,
	 pabeni@redhat.com,  edumazet@google.com,  shuah@kernel.org
Cc: linux-kernel-mentees@lists.linuxfoundation.org,
	 Mahmoud Maatuq <mahmoudmatook.mm@gmail.com>
Subject: Re: [PATCH 1/2] selftests: Provide local define of min() and max()
Date: Sun, 20 Aug 2023 11:15:01 -0400	[thread overview]
Message-ID: <64e22df53d1e6_3580162945b@willemb.c.googlers.com.notmuch> (raw)
In-Reply-To: <20230819195005.99387-2-mahmoudmatook.mm@gmail.com>

Mahmoud Maatuq wrote:
> to avoid manual calculation of min and max values
> and fix coccinelle warnings such WARNING opportunity for min()/max()
> adding one common definition that could be used in multiple files
> under selftests.
> there are also some defines for min/max scattered locally inside sources
> under selftests.
> this also prepares for cleaning up those redundant defines and include
> kselftest.h instead.
> 
> Signed-off-by: Mahmoud Maatuq <mahmoudmatook.mm@gmail.com>
> ---
>  tools/testing/selftests/kselftest.h | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h
> index 829be379545a..e8eb7e9afbc6 100644
> --- a/tools/testing/selftests/kselftest.h
> +++ b/tools/testing/selftests/kselftest.h
> @@ -55,6 +55,13 @@
>  #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
>  #endif
>  
> +#ifndef min
> +# define min(x, y) ((x) < (y) ? (x) : (y))
> +#endif
> +#ifndef max
> +# define max(x, y) ((x) < (y) ? (y) : (x))
> +#endif
> +

Should this more closely follow include/linux/minmax.h, which is a lot
more strict?

I'm fine with this simpler, more relaxed, version for testing, but
calling it out for people to speak up.

Only the first two of these comments in minmax.h apply to this
userspace code.

/*
 * min()/max()/clamp() macros must accomplish three things:
 *
 * - avoid multiple evaluations of the arguments (so side-effects like
 *   "x++" happen only once) when non-constant.
 * - perform strict type-checking (to generate warnings instead of
 *   nasty runtime surprises). See the "unnecessary" pointer comparison
 *   in __typecheck().
 * - retain result as a constant expressions when called with only
 *   constant expressions (to avoid tripping VLA warnings in stack
 *   allocation usage).
 */

Note that a more strict version that includes __typecheck would
warn on the type difference between total_len and cfg_mss. Fine
with changing the type of cfg_mss in the follow-on patch to address
that.


  reply	other threads:[~2023-08-20 15:19 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-19 19:50 [PATCH 0/2] selftests: Introduce common min()/max() and apply them in net tests Mahmoud Maatuq
2023-08-19 19:50 ` [PATCH 1/2] selftests: Provide local define of min() and max() Mahmoud Maatuq
2023-08-20 15:15   ` Willem de Bruijn [this message]
2023-08-21 13:04     ` David Laight
2023-08-22 14:34       ` Willem de Bruijn
2023-08-22 14:48         ` David Laight
2023-08-23 19:35           ` Mahmoud Matook
2023-08-24  8:53             ` David Laight
2023-08-19 19:50 ` [PATCH 2/2] selftests/net: replace ternary operator with min()/max() Mahmoud Maatuq
2023-08-20 15:10   ` Willem de Bruijn
2023-08-23 19:40     ` Mahmoud Matook

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=64e22df53d1e6_3580162945b@willemb.c.googlers.com.notmuch \
    --to=willemdebruijn.kernel@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel-mentees@lists.linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mahmoudmatook.mm@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shuah@kernel.org \
    /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).