net/devres.c
Source file repositories/reference/linux-study-clean/net/devres.c
File Facts
- System
- Linux kernel
- Corpus path
net/devres.c- Extension
.c- Size
- 2250 bytes
- Lines
- 96
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.hlinux/etherdevice.hlinux/netdevice.h
Detected Declarations
struct net_device_devresfunction devm_free_netdevfunction devm_unregister_netdevfunction netdev_devres_matchfunction register_netdevexport devm_alloc_etherdev_mqsexport devm_register_netdev
Annotated Snippet
struct net_device_devres {
struct net_device *ndev;
};
static void devm_free_netdev(struct device *dev, void *this)
{
struct net_device_devres *res = this;
free_netdev(res->ndev);
}
struct net_device *devm_alloc_etherdev_mqs(struct device *dev, int sizeof_priv,
unsigned int txqs, unsigned int rxqs)
{
struct net_device_devres *dr;
dr = devres_alloc(devm_free_netdev, sizeof(*dr), GFP_KERNEL);
if (!dr)
return NULL;
dr->ndev = alloc_etherdev_mqs(sizeof_priv, txqs, rxqs);
if (!dr->ndev) {
devres_free(dr);
return NULL;
}
devres_add(dev, dr);
return dr->ndev;
}
EXPORT_SYMBOL(devm_alloc_etherdev_mqs);
static void devm_unregister_netdev(struct device *dev, void *this)
{
struct net_device_devres *res = this;
unregister_netdev(res->ndev);
}
static int netdev_devres_match(struct device *dev, void *this, void *match_data)
{
struct net_device_devres *res = this;
struct net_device *ndev = match_data;
return ndev == res->ndev;
}
/**
* devm_register_netdev - resource managed variant of register_netdev()
* @dev: managing device for this netdev - usually the parent device
* @ndev: device to register
*
* This is a devres variant of register_netdev() for which the unregister
* function will be called automatically when the managing device is
* detached. Note: the net_device used must also be resource managed by
* the same struct device.
*/
int devm_register_netdev(struct device *dev, struct net_device *ndev)
{
struct net_device_devres *dr;
int ret;
/* struct net_device must itself be managed. For now a managed netdev
* can only be allocated by devm_alloc_etherdev_mqs() so the check is
* straightforward.
*/
if (WARN_ON(!devres_find(dev, devm_free_netdev,
netdev_devres_match, ndev)))
return -EINVAL;
dr = devres_alloc(devm_unregister_netdev, sizeof(*dr), GFP_KERNEL);
if (!dr)
return -ENOMEM;
ret = register_netdev(ndev);
if (ret) {
devres_free(dr);
return ret;
}
dr->ndev = ndev;
devres_add(ndev->dev.parent, dr);
return 0;
}
EXPORT_SYMBOL(devm_register_netdev);
Annotation
- Immediate include surface: `linux/device.h`, `linux/etherdevice.h`, `linux/netdevice.h`.
- Detected declarations: `struct net_device_devres`, `function devm_free_netdev`, `function devm_unregister_netdev`, `function netdev_devres_match`, `function register_netdev`, `export devm_alloc_etherdev_mqs`, `export devm_register_netdev`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration 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.