drivers/media/cec/core/cec-notifier.c
Source file repositories/reference/linux-study-clean/drivers/media/cec/core/cec-notifier.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/cec/core/cec-notifier.c- Extension
.c- Size
- 6211 bytes
- Lines
- 257
- Domain
- Driver Families
- Bucket
- drivers/media
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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
linux/export.hlinux/platform_device.hlinux/string.hlinux/slab.hlinux/i2c.hlinux/list.hlinux/kref.hlinux/of_platform.hmedia/cec.hmedia/cec-notifier.hdrm/drm_edid.h
Detected Declarations
struct cec_notifierfunction cec_notifier_get_connfunction cec_notifier_releasefunction cec_notifier_putfunction cec_notifier_conn_registerfunction cec_notifier_conn_unregisterfunction cec_notifier_cec_adap_registerfunction cec_notifier_cec_adap_unregisterfunction cec_notifier_set_phys_addrfunction cec_notifier_set_phys_addr_from_edidexport cec_notifier_conn_registerexport cec_notifier_conn_unregisterexport cec_notifier_cec_adap_registerexport cec_notifier_cec_adap_unregisterexport cec_notifier_set_phys_addrexport cec_notifier_set_phys_addr_from_edidexport cec_notifier_parse_hdmi_phandle
Annotated Snippet
struct cec_notifier {
struct mutex lock;
struct list_head head;
struct kref kref;
struct device *hdmi_dev;
struct cec_connector_info conn_info;
const char *port_name;
struct cec_adapter *cec_adap;
u16 phys_addr;
};
static LIST_HEAD(cec_notifiers);
static DEFINE_MUTEX(cec_notifiers_lock);
/**
* cec_notifier_get_conn - find or create a new cec_notifier for the given
* device and connector tuple.
* @hdmi_dev: device that sends the events.
* @port_name: the connector name from which the event occurs
*
* If a notifier for device @dev already exists, then increase the refcount
* and return that notifier.
*
* If it doesn't exist, then allocate a new notifier struct and return a
* pointer to that new struct.
*
* Return NULL if the memory could not be allocated.
*/
static struct cec_notifier *
cec_notifier_get_conn(struct device *hdmi_dev, const char *port_name)
{
struct cec_notifier *n;
mutex_lock(&cec_notifiers_lock);
list_for_each_entry(n, &cec_notifiers, head) {
if (n->hdmi_dev == hdmi_dev &&
(!port_name ||
(n->port_name && !strcmp(n->port_name, port_name)))) {
kref_get(&n->kref);
mutex_unlock(&cec_notifiers_lock);
return n;
}
}
n = kzalloc_obj(*n);
if (!n)
goto unlock;
n->hdmi_dev = hdmi_dev;
if (port_name) {
n->port_name = kstrdup(port_name, GFP_KERNEL);
if (!n->port_name) {
kfree(n);
n = NULL;
goto unlock;
}
}
n->phys_addr = CEC_PHYS_ADDR_INVALID;
mutex_init(&n->lock);
kref_init(&n->kref);
list_add_tail(&n->head, &cec_notifiers);
unlock:
mutex_unlock(&cec_notifiers_lock);
return n;
}
static void cec_notifier_release(struct kref *kref)
{
struct cec_notifier *n =
container_of(kref, struct cec_notifier, kref);
list_del(&n->head);
kfree(n->port_name);
kfree(n);
}
static void cec_notifier_put(struct cec_notifier *n)
{
mutex_lock(&cec_notifiers_lock);
kref_put(&n->kref, cec_notifier_release);
mutex_unlock(&cec_notifiers_lock);
}
struct cec_notifier *
cec_notifier_conn_register(struct device *hdmi_dev, const char *port_name,
const struct cec_connector_info *conn_info)
{
struct cec_notifier *n = cec_notifier_get_conn(hdmi_dev, port_name);
if (!n)
Annotation
- Immediate include surface: `linux/export.h`, `linux/platform_device.h`, `linux/string.h`, `linux/slab.h`, `linux/i2c.h`, `linux/list.h`, `linux/kref.h`, `linux/of_platform.h`.
- Detected declarations: `struct cec_notifier`, `function cec_notifier_get_conn`, `function cec_notifier_release`, `function cec_notifier_put`, `function cec_notifier_conn_register`, `function cec_notifier_conn_unregister`, `function cec_notifier_cec_adap_register`, `function cec_notifier_cec_adap_unregister`, `function cec_notifier_set_phys_addr`, `function cec_notifier_set_phys_addr_from_edid`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: integration 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.