drivers/regulator/event.c
Source file repositories/reference/linux-study-clean/drivers/regulator/event.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/regulator/event.c- Extension
.c- Size
- 2096 bytes
- Lines
- 92
- Domain
- Driver Families
- Bucket
- drivers/regulator
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
regulator/regulator.hnet/netlink.hnet/genetlink.hlinux/atomic.hregnl.h
Detected Declarations
function reg_generate_netlink_eventfunction reg_event_genetlink_initfunction reg_event_initmodule init reg_event_init
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Regulator event over netlink
*
* Author: Naresh Solanki <Naresh.Solanki@9elements.com>
*/
#include <regulator/regulator.h>
#include <net/netlink.h>
#include <net/genetlink.h>
#include <linux/atomic.h>
#include "regnl.h"
static atomic_t reg_event_seqnum = ATOMIC_INIT(0);
static const struct genl_multicast_group reg_event_mcgrps[] = {
{ .name = REG_GENL_MCAST_GROUP_NAME, },
};
static struct genl_family reg_event_genl_family __ro_after_init = {
.module = THIS_MODULE,
.name = REG_GENL_FAMILY_NAME,
.version = REG_GENL_VERSION,
.maxattr = REG_GENL_ATTR_MAX,
.mcgrps = reg_event_mcgrps,
.n_mcgrps = ARRAY_SIZE(reg_event_mcgrps),
};
int reg_generate_netlink_event(const char *reg_name, u64 event)
{
struct sk_buff *skb;
struct nlattr *attr;
struct reg_genl_event *edata;
void *msg_header;
int size;
/* allocate memory */
size = nla_total_size(sizeof(struct reg_genl_event)) +
nla_total_size(0);
skb = genlmsg_new(size, GFP_ATOMIC);
if (!skb)
return -ENOMEM;
/* add the genetlink message header */
msg_header = genlmsg_put(skb, 0, atomic_inc_return(®_event_seqnum),
®_event_genl_family, 0, REG_GENL_CMD_EVENT);
if (!msg_header) {
nlmsg_free(skb);
return -ENOMEM;
}
/* fill the data */
attr = nla_reserve(skb, REG_GENL_ATTR_EVENT, sizeof(struct reg_genl_event));
if (!attr) {
nlmsg_free(skb);
return -EINVAL;
}
edata = nla_data(attr);
memset(edata, 0, sizeof(struct reg_genl_event));
strscpy(edata->reg_name, reg_name, sizeof(edata->reg_name));
edata->event = event;
/* send multicast genetlink message */
genlmsg_end(skb, msg_header);
size = genlmsg_multicast(®_event_genl_family, skb, 0, 0, GFP_ATOMIC);
return size;
}
static int __init reg_event_genetlink_init(void)
{
return genl_register_family(®_event_genl_family);
}
static int __init reg_event_init(void)
{
int error;
/* create genetlink for acpi event */
error = reg_event_genetlink_init();
if (error)
pr_warn("Failed to create genetlink family for reg event\n");
return 0;
}
Annotation
- Immediate include surface: `regulator/regulator.h`, `net/netlink.h`, `net/genetlink.h`, `linux/atomic.h`, `regnl.h`.
- Detected declarations: `function reg_generate_netlink_event`, `function reg_event_genetlink_init`, `function reg_event_init`, `module init reg_event_init`.
- Atlas domain: Driver Families / drivers/regulator.
- 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.