All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yury Norov <ynorov@nvidia.com>
To: Luiz Angelo Daros de Luca <luizluca@gmail.com>
Cc: "Andrew Lunn" <andrew@lunn.ch>,
	"Vladimir Oltean" <olteanv@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Simon Horman" <horms@kernel.org>,
	"Linus Walleij" <linusw@kernel.org>,
	"Alvin Šipraga" <alsi@bang-olufsen.dk>,
	"Yury Norov" <yury.norov@gmail.com>,
	"Rasmus Villemoes" <linux@rasmusvillemoes.dk>,
	"Russell King" <linux@armlinux.org.uk>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [net-next PATCH 04/10] bitfield.h: add FIELD_WIDTH()
Date: Tue, 31 Mar 2026 22:15:49 -0400	[thread overview]
Message-ID: <acx_1dOF3EjvGt4B@yury> (raw)
In-Reply-To: <20260331-realtek_forward-v1-4-44fb63033b7e@gmail.com>

On Tue, Mar 31, 2026 at 08:00:04PM -0300, Luiz Angelo Daros de Luca wrote:
> Some hardware stores logical fields split across multiple registers,
> requiring partial values to be reassembled using shifts and masks.
> 
> Add FIELD_WIDTH(), a helper that returns the number of contiguous bits
> covered by a bitfield mask. This allows callers to determine how much a
> partial value needs to be shifted when reconstructing a field.
> 
> This complements FIELD_MAX() and FIELD_FIT(), and avoids reimplementing
> bit counting logic in drivers.
> 
> Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
> ---
>  include/linux/bitfield.h | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h
> index 54aeeef1f0ec..8d6c1c309c3b 100644
> --- a/include/linux/bitfield.h
> +++ b/include/linux/bitfield.h
> @@ -111,6 +111,19 @@
>  		(typeof(_mask))((_mask) >> __bf_shf(_mask));		\
>  	})
>  
> +/**
> + * FIELD_WIDTH() - return the width of a bitfield
> + * @_mask: shifted mask defining the field's length and position
> + *
> + * Returns the number of contiguous bits covered by @_mask.
> + * This corresponds to the bit width of FIELD_MAX(@_mask).
> + */
> +#define FIELD_WIDTH(_mask)						\

Please no underscored names unless necessary.

> +	({								\
> +		__BF_FIELD_CHECK(_mask, 0ULL, 0ULL, "FIELD_WIDTH: ");	\
> +		__bf_shf(~FIELD_MAX(_mask));				\
> +	})

I believe, this should be:

  #define FIELD_WIDTH(mask) ({                                  \
        __BF_FIELD_CHECK_MASK(mask, 0ULL, "FIELD_WIDTH: ");     \
        HWEIGHT(mask);                                          \
  })

Thanks,
Yury

> +
>  /**
>   * FIELD_FIT() - check if value fits in the field
>   * @_mask: shifted mask defining the field's length and position
> 
> -- 
> 2.53.0
> 

  reply	other threads:[~2026-04-01  2:20 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-31 23:00 [net-next PATCH 00/10] net: dsa: realtek: rtl8365mb: bridge offloading and VLAN support Luiz Angelo Daros de Luca
2026-03-31 23:00 ` [net-next PATCH 01/10] net: dsa: tag_rtl8_4: update format description Luiz Angelo Daros de Luca
2026-04-07  7:33   ` Linus Walleij
2026-03-31 23:00 ` [net-next PATCH 02/10] net: dsa: realtek: rtl8365mb: set STP state to disabled early Luiz Angelo Daros de Luca
2026-03-31 23:00 ` [net-next PATCH 03/10] net: dsa: realtek: rtl8365mb: prepare for multiple source files Luiz Angelo Daros de Luca
2026-04-07  7:35   ` Linus Walleij
2026-03-31 23:00 ` [net-next PATCH 04/10] bitfield.h: add FIELD_WIDTH() Luiz Angelo Daros de Luca
2026-04-01  2:15   ` Yury Norov [this message]
2026-04-02  4:00     ` Luiz Angelo Daros de Luca
2026-04-02  9:27       ` David Laight
2026-04-02 13:52         ` Yury Norov
2026-04-02 22:21           ` David Laight
2026-04-03 14:09             ` Luiz Angelo Daros de Luca
2026-04-03 16:18               ` Yury Norov
2026-04-04 14:54               ` David Laight
2026-04-04 15:12               ` David Laight
2026-04-02 13:45       ` Yury Norov
2026-03-31 23:00 ` [net-next PATCH 05/10] net: dsa: realtek: rtl8365mb: add table lookup interface Luiz Angelo Daros de Luca
2026-04-07  7:43   ` Linus Walleij
2026-03-31 23:00 ` [net-next PATCH 06/10] net: dsa: realtek: rtl8365mb: add VLAN support Luiz Angelo Daros de Luca
2026-04-01  2:27   ` Yury Norov
2026-04-02  2:45     ` Luiz Angelo Daros de Luca
2026-04-02 14:22       ` Yury Norov
2026-04-07  7:59   ` Linus Walleij
2026-04-10  7:05     ` Luiz Angelo Daros de Luca
2026-04-10  7:36       ` Linus Walleij
2026-04-22  4:10         ` Luiz Angelo Daros de Luca
2026-04-27 18:07           ` Luiz Angelo Daros de Luca
2026-04-27 20:11             ` Linus Walleij
2026-04-28  9:26             ` Gabor Juhos
2026-03-31 23:00 ` [net-next PATCH 07/10] net: dsa: realtek: rtl8365mb: add port_bridge_{join,leave} Luiz Angelo Daros de Luca
2026-04-07  8:11   ` Linus Walleij
2026-04-22  5:42     ` Luiz Angelo Daros de Luca
2026-03-31 23:00 ` [net-next PATCH 08/10] net: dsa: realtek: rtl8365mb: add FDB support Luiz Angelo Daros de Luca
2026-04-07  9:11   ` Linus Walleij
2026-04-22  6:56     ` Luiz Angelo Daros de Luca
2026-03-31 23:00 ` [net-next PATCH 09/10] net: dsa: realtek: rtl8365mb: add bridge port flags Luiz Angelo Daros de Luca
2026-04-07  9:20   ` Linus Walleij
2026-04-22  6:06     ` Luiz Angelo Daros de Luca
2026-03-31 23:00 ` [net-next PATCH 10/10] net: dsa: tag_rtl8_4: set KEEP flag Luiz Angelo Daros de Luca
2026-04-07  9:22   ` Linus Walleij

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=acx_1dOF3EjvGt4B@yury \
    --to=ynorov@nvidia.com \
    --cc=alsi@bang-olufsen.dk \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=linux@rasmusvillemoes.dk \
    --cc=luizluca@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.