The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Joel Fernandes <joelagnelf@nvidia.com>
To: Yury Norov <yury.norov@gmail.com>, acourbot@nvidia.com
Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
	dakr@kernel.org, Alistair Popple <apopple@nvidia.com>,
	Miguel Ojeda <ojeda@kernel.org>,
	Alex Gaynor <alex.gaynor@gmail.com>,
	Boqun Feng <boqun.feng@gmail.com>, Gary Guo <gary@garyguo.net>,
	bjorn3_gh@protonmail.com, Benno Lossin <lossin@kernel.org>,
	Andreas Hindborg <a.hindborg@kernel.org>,
	Alice Ryhl <aliceryhl@google.com>,
	Trevor Gross <tmgross@umich.edu>,
	David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	John Hubbard <jhubbard@nvidia.com>, Timur Tabi <ttabi@nvidia.com>,
	joel@joelfernandes.org, Elle Rhumsaa <elle@weathered-steel.dev>,
	Daniel Almeida <daniel.almeida@collabora.com>,
	nouveau@lists.freedesktop.org
Subject: Re: [PATCH v3 5/5] rust: Add KUNIT tests for bitfield
Date: Fri, 19 Sep 2025 19:02:27 -0400	[thread overview]
Message-ID: <20250919230227.GA1901670@joelbox2> (raw)
In-Reply-To: <20250916095918.GA1647262@joelbox2>

On Tue, Sep 16, 2025 at 05:59:18AM -0400, Joel Fernandes wrote:
[...]
> > > > The same question for the setters. What would happen for this:
> > > > 
> > > >     let bf = bf::default()
> > > >              .set_state(0xf)
> > > >              .set_ready(true);
> > > > 
> > > > I think that after the first out-of-boundary in set_state(), you
> > > > should abort the call chain, make sure you're not touching memory
> > > > in set_ready() and returning some type of error.
> > > 
> > > Here, on out of boundary, we just ignore the extra bits passed to
> > > set_state. I think it would be odd if we errored out honestly. We are
> > > using 'as u8' in the struct so we would accept any u8 as input, but
> > > then if we complained that extra bits were sent, that would be odd.
> > 
> > That really depends on your purpose. If your end goal is the safest API
> > in the world, and you're ready to sacrifice some performance (which is
> > exactly opposite to the C case), then you'd return to your user with a
> > simple question: are you sure you can fit this 8-bit number into a 3-bit
> > storage?   
> 
> I think personally I am OK with rejecting requests about this, so we can
> agree on this.

It is not possible to reject values passed to set, because it returns Self
and follows the builder-pattern, to do this we will need to return Result,
and have the caller unwrap it, and have to rename it to try_set().

Instead of that, I would just extract the bits from the value the user passed
and ignore the rest (example if 0xff is passed for a 4-bit bitfield, then the
field is 0xf.)

Alex what do you think, should set_ be fallible?

thanks,

 - Joel


  parent reply	other threads:[~2025-09-19 23:02 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-09 21:20 [PATCH v3 0/5] Introduce bitfield and move register macro to rust/kernel/ Joel Fernandes
2025-09-09 21:20 ` [PATCH v3 1/5] nova-core: bitfield: Move bitfield-specific code from register! into new macro Joel Fernandes
2025-09-09 21:20 ` [PATCH v3 2/5] nova-core: bitfield: Add support for different storage widths Joel Fernandes
2025-09-09 21:20 ` [PATCH v3 3/5] nova-core: bitfield: Add support for custom visiblity Joel Fernandes
2025-09-09 21:20 ` [PATCH v3 4/5] rust: Move register and bitfield macros out of Nova Joel Fernandes
2025-09-09 21:36   ` Miguel Ojeda
2025-09-10  0:15     ` Joel Fernandes
2025-09-09 21:20 ` [PATCH v3 5/5] rust: Add KUNIT tests for bitfield Joel Fernandes
2025-09-10  3:04   ` Yury Norov
2025-09-10 23:08     ` Joel Fernandes
2025-09-11  1:47       ` Yury Norov
2025-09-16  9:59         ` Joel Fernandes
2025-09-16 10:10           ` Joel Fernandes
2025-09-19 23:02           ` Joel Fernandes [this message]
2025-09-20  0:39           ` Joel Fernandes
2025-09-20  0:52             ` John Hubbard
2025-09-20  9:33               ` Joel Fernandes
2025-09-21 11:41             ` Miguel Ojeda
2025-09-10 23:22     ` Joel Fernandes

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=20250919230227.GA1901670@joelbox2 \
    --to=joelagnelf@nvidia.com \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=apopple@nvidia.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=elle@weathered-steel.dev \
    --cc=gary@garyguo.net \
    --cc=jhubbard@nvidia.com \
    --cc=joel@joelfernandes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=nouveau@lists.freedesktop.org \
    --cc=ojeda@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tmgross@umich.edu \
    --cc=ttabi@nvidia.com \
    --cc=tzimmermann@suse.de \
    --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