net/batman-adv/hash.c
Source file repositories/reference/linux-study-clean/net/batman-adv/hash.c
File Facts
- System
- Linux kernel
- Corpus path
net/batman-adv/hash.c- Extension
.c- Size
- 1731 bytes
- Lines
- 84
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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
hash.hmain.hlinux/gfp.hlinux/lockdep.hlinux/slab.h
Detected Declarations
function batadv_hash_initfunction batadv_hash_destroyfunction batadv_hash_newfunction batadv_hash_set_lock_class
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (C) B.A.T.M.A.N. contributors:
*
* Simon Wunderlich, Marek Lindner
*/
#include "hash.h"
#include "main.h"
#include <linux/gfp.h>
#include <linux/lockdep.h>
#include <linux/slab.h>
/* clears the hash */
static void batadv_hash_init(struct batadv_hashtable *hash)
{
u32 i;
for (i = 0; i < hash->size; i++) {
INIT_HLIST_HEAD(&hash->table[i]);
spin_lock_init(&hash->list_locks[i]);
}
atomic_set(&hash->generation, 0);
}
/**
* batadv_hash_destroy() - Free only the hashtable and the hash itself
* @hash: hash object to destroy
*/
void batadv_hash_destroy(struct batadv_hashtable *hash)
{
kfree(hash->list_locks);
kfree(hash->table);
kfree(hash);
}
/**
* batadv_hash_new() - Allocates and clears the hashtable
* @size: number of hash buckets to allocate
*
* Return: newly allocated hashtable, NULL on errors
*/
struct batadv_hashtable *batadv_hash_new(u32 size)
{
struct batadv_hashtable *hash;
hash = kmalloc_obj(*hash, GFP_ATOMIC);
if (!hash)
return NULL;
hash->table = kmalloc_objs(*hash->table, size, GFP_ATOMIC);
if (!hash->table)
goto free_hash;
hash->list_locks = kmalloc_objs(*hash->list_locks, size, GFP_ATOMIC);
if (!hash->list_locks)
goto free_table;
hash->size = size;
batadv_hash_init(hash);
return hash;
free_table:
kfree(hash->table);
free_hash:
kfree(hash);
return NULL;
}
/**
* batadv_hash_set_lock_class() - Set specific lockdep class for hash spinlocks
* @hash: hash object to modify
* @key: lockdep class key address
*/
void batadv_hash_set_lock_class(struct batadv_hashtable *hash,
struct lock_class_key *key)
{
u32 i;
for (i = 0; i < hash->size; i++)
lockdep_set_class(&hash->list_locks[i], key);
}
Annotation
- Immediate include surface: `hash.h`, `main.h`, `linux/gfp.h`, `linux/lockdep.h`, `linux/slab.h`.
- Detected declarations: `function batadv_hash_init`, `function batadv_hash_destroy`, `function batadv_hash_new`, `function batadv_hash_set_lock_class`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.