The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Yury Norov <ynorov@nvidia.com>
Cc: Arnav Kapoor <kapoorarnav43@gmail.com>,
	Yury Norov <yury.norov@gmail.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Jonathan Cameron <jic23@kernel.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] bitfield: kunit: test FIELD_FIT() with values that overflow the shift
Date: Sun, 6 Dec 2026 13:09:34 +0200	[thread overview]
Message-ID: <axVCbleDhl-Vfjpb@ashevche-desk.local> (raw)
In-Reply-To: <axRpdTU0eXYi1lTw@yury>

On Sat, Dec 05, 2026 at 02:43:49PM -0500, Yury Norov wrote:
> On Fri, Dec 04, 2026 at 07:26:13PM +0200, Andy Shevchenko wrote:
> > On Fri, Dec 04, 2026 at 10:03:12PM +0530, Arnav Kapoor wrote:

...

> > > +#define CHECK_FIT(mask, val, res) do {					\
> > > +		bool fit = FIELD_FIT(mask, val);			\
> > > +									\
> > > +		KUNIT_EXPECT_EQ_MSG(context, fit, res,			\
> > > +				    "FIELD_FIT(%s, %s)", #mask, #val);	\
> > > +	} while (0)
> > > +
> > > +static void __init test_bitfields_fit(struct kunit *context)
> > > +{
> > > +	s32 big = BIT(24), neg = -1, min = S32_MIN;
> > > +	u32 three = 3, four = 4;
> > > +
> > > +	CHECK_FIT((u32)0x00000300, three, true);
> > > +	CHECK_FIT((u32)0x00000300, four, false);
> > > +	CHECK_FIT((u32)0x00000300, neg, false);
> > > +	/* These must not pass by having their high bits shifted out */
> > > +	CHECK_FIT((u32)0x00000300, big, false);
> > > +	CHECK_FIT((u32)0x00000300, min, false);
> > > +	CHECK_FIT((u32)0xf0000000, big, false);
> > > +
> > > +	CHECK_FIT(GENMASK(9, 8), big, false);
> > > +	CHECK_FIT(GENMASK(9, 8), min, false);
> > > +}
> > 
> > #undef CHECK_FIT
> 
> I missed your comment here while moving this patch in bitmap-for-next.
> This is .c file, so this CHECK_FIT can't pollute anything else.

Yes, but this is not the point.

> Can you explain what for the #undef? If it's really needed, I'll add it
> inplace.

Sure, the rationale is purely because it's a set of test cases. We might
have more than a single test against something, say called "FIT", and we may
want to use the same name of the macro for slightly different data. You may
argue that this is not a good style, but I can answer that this is test cases
and sometimes it might make sense. So, in test cases I prefer robustness over
implicit assumptions.

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2026-12-06 11:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 16:33 [PATCH 0/2] bitfield: fix FIELD_FIT() for values that overflow the shift Arnav Kapoor
2026-12-04 16:33 ` [PATCH 1/2] bitfield: make FIELD_FIT() check the value, not the shifted value Arnav Kapoor
2026-12-04 16:33 ` [PATCH 2/2] bitfield: kunit: test FIELD_FIT() with values that overflow the shift Arnav Kapoor
2026-12-04 17:26   ` Andy Shevchenko
2026-12-05 19:43     ` Yury Norov
2026-12-06 11:09       ` Andy Shevchenko [this message]
2026-12-04 17:27 ` [PATCH 0/2] bitfield: fix FIELD_FIT() for " Andy Shevchenko
2026-12-04 19:53   ` Jonathan Cameron
2026-12-05  4:52 ` Yury Norov

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=axVCbleDhl-Vfjpb@ashevche-desk.local \
    --to=andriy.shevchenko@intel.com \
    --cc=jic23@kernel.org \
    --cc=kapoorarnav43@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=ynorov@nvidia.com \
    --cc=yury.norov@gmail.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