net/ethtool/bitset.c
Source file repositories/reference/linux-study-clean/net/ethtool/bitset.c
File Facts
- System
- Linux kernel
- Corpus path
net/ethtool/bitset.c- Extension
.c- Size
- 23818 bytes
- Lines
- 875
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: implementation source
- Status
- source implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/ethtool_netlink.hlinux/bitmap.hbitset.hnetlink.h
Detected Declarations
function u32function ethnl_upper_bitsfunction ethnl_bitmap32_clearfunction ethnl_bitmap32_not_zerofunction ethnl_bitmap32_updatefunction ethnl_bitmap32_test_bitfunction ethnl_bitset32_sizefunction ethnl_put_bitset32function ethnl_bitset_is_compactfunction ethnl_name_to_idxfunction ethnl_parse_bitfunction ethnl_bitmap32_equalfunction ethnl_update_bitset32_verbosefunction nla_for_each_nestedfunction ethnl_compact_sanity_checksfunction nla_lenfunction ethnl_update_bitset32function ethnl_update_bitsetfunction nla_for_each_nestedfunction ethnl_bitset_sizefunction ethnl_put_bitsetfunction ethnl_update_bitsetfunction ethnl_bitset_sizefunction ethnl_put_bitsetfunction ethnl_update_bitset
Annotated Snippet
if (end_word == start_word) {
mask &= ethnl_lower_bits(end);
if (dst[start_word] & mask) {
dst[start_word] &= ~mask;
*mod = true;
}
return;
}
if (dst[start_word] & mask) {
dst[start_word] &= ~mask;
*mod = true;
}
start_word++;
}
for (i = start_word; i < end_word; i++) {
if (dst[i]) {
dst[i] = 0;
*mod = true;
}
}
if (end % 32) {
mask = ethnl_lower_bits(end);
if (dst[end_word] & mask) {
dst[end_word] &= ~mask;
*mod = true;
}
}
}
/**
* ethnl_bitmap32_not_zero() - Check if any bit is set in an interval
* @map: bitmap to test
* @start: beginning of the interval
* @end: end of the interval
*
* Return: true if there is non-zero bit with index @start <= i < @end,
* false if the whole interval is zero
*/
static bool ethnl_bitmap32_not_zero(const u32 *map, unsigned int start,
unsigned int end)
{
unsigned int start_word = start / 32;
unsigned int end_word = end / 32;
u32 mask;
if (end <= start)
return false;
if (start % 32) {
mask = ethnl_upper_bits(start);
if (end_word == start_word) {
mask &= ethnl_lower_bits(end);
return map[start_word] & mask;
}
if (map[start_word] & mask)
return true;
start_word++;
}
if (memchr_inv(map + start_word, '\0',
(end_word - start_word) * sizeof(u32)))
return true;
if (end % 32 == 0)
return false;
return map[end_word] & ethnl_lower_bits(end);
}
/**
* ethnl_bitmap32_update() - Modify u32 based bitmap according to value/mask
* pair
* @dst: bitmap to update
* @nbits: bit size of the bitmap
* @value: values to set
* @mask: mask of bits to set
* @mod: set to true if bitmap is modified, preserve if not
*
* Set bits in @dst bitmap which are set in @mask to values from @value, leave
* the rest untouched. If destination bitmap was modified, set @mod to true,
* leave as it is if not.
*/
static void ethnl_bitmap32_update(u32 *dst, unsigned int nbits,
const u32 *value, const u32 *mask, bool *mod)
{
while (nbits > 0) {
u32 real_mask = mask ? *mask : ~(u32)0;
u32 new_value;
if (nbits < 32)
real_mask &= ethnl_lower_bits(nbits);
Annotation
- Immediate include surface: `linux/ethtool_netlink.h`, `linux/bitmap.h`, `bitset.h`, `netlink.h`.
- Detected declarations: `function u32`, `function ethnl_upper_bits`, `function ethnl_bitmap32_clear`, `function ethnl_bitmap32_not_zero`, `function ethnl_bitmap32_update`, `function ethnl_bitmap32_test_bit`, `function ethnl_bitset32_size`, `function ethnl_put_bitset32`, `function ethnl_bitset_is_compact`, `function ethnl_name_to_idx`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.