drivers/net/phy/mdio_devres.c
Source file repositories/reference/linux-study-clean/drivers/net/phy/mdio_devres.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/phy/mdio_devres.c- Extension
.c- Size
- 3106 bytes
- Lines
- 136
- Domain
- Driver Families
- Bucket
- drivers/net
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.hlinux/of_mdio.hlinux/phy.hlinux/stddef.h
Detected Declarations
struct mdiobus_devresfunction devm_mdiobus_freefunction devm_mdiobus_unregisterfunction mdiobus_devres_matchfunction __devm_mdiobus_registerfunction __devm_of_mdiobus_registerexport devm_mdiobus_alloc_sizeexport __devm_mdiobus_registerexport __devm_of_mdiobus_register
Annotated Snippet
struct mdiobus_devres {
struct mii_bus *mii;
};
static void devm_mdiobus_free(struct device *dev, void *this)
{
struct mdiobus_devres *dr = this;
mdiobus_free(dr->mii);
}
/**
* devm_mdiobus_alloc_size - Resource-managed mdiobus_alloc_size()
* @dev: Device to allocate mii_bus for
* @sizeof_priv: Space to allocate for private structure
*
* Managed mdiobus_alloc_size. mii_bus allocated with this function is
* automatically freed on driver detach.
*
* RETURNS:
* Pointer to allocated mii_bus on success, NULL on out-of-memory error.
*/
struct mii_bus *devm_mdiobus_alloc_size(struct device *dev, int sizeof_priv)
{
struct mdiobus_devres *dr;
dr = devres_alloc(devm_mdiobus_free, sizeof(*dr), GFP_KERNEL);
if (!dr)
return NULL;
dr->mii = mdiobus_alloc_size(sizeof_priv);
if (!dr->mii) {
devres_free(dr);
return NULL;
}
devres_add(dev, dr);
return dr->mii;
}
EXPORT_SYMBOL(devm_mdiobus_alloc_size);
static void devm_mdiobus_unregister(struct device *dev, void *this)
{
struct mdiobus_devres *dr = this;
mdiobus_unregister(dr->mii);
}
static int mdiobus_devres_match(struct device *dev,
void *this, void *match_data)
{
struct mdiobus_devres *res = this;
struct mii_bus *mii = match_data;
return mii == res->mii;
}
/**
* __devm_mdiobus_register - Resource-managed variant of mdiobus_register()
* @dev: Device to register mii_bus for
* @bus: MII bus structure to register
* @owner: Owning module
*
* Returns 0 on success, negative error number on failure.
*/
int __devm_mdiobus_register(struct device *dev, struct mii_bus *bus,
struct module *owner)
{
struct mdiobus_devres *dr;
int ret;
if (WARN_ON(!devres_find(dev, devm_mdiobus_free,
mdiobus_devres_match, bus)))
return -EINVAL;
dr = devres_alloc(devm_mdiobus_unregister, sizeof(*dr), GFP_KERNEL);
if (!dr)
return -ENOMEM;
ret = __mdiobus_register(bus, owner);
if (ret) {
devres_free(dr);
return ret;
}
dr->mii = bus;
devres_add(dev, dr);
return 0;
}
EXPORT_SYMBOL(__devm_mdiobus_register);
Annotation
- Immediate include surface: `linux/device.h`, `linux/of_mdio.h`, `linux/phy.h`, `linux/stddef.h`.
- Detected declarations: `struct mdiobus_devres`, `function devm_mdiobus_free`, `function devm_mdiobus_unregister`, `function mdiobus_devres_match`, `function __devm_mdiobus_register`, `function __devm_of_mdiobus_register`, `export devm_mdiobus_alloc_size`, `export __devm_mdiobus_register`, `export __devm_of_mdiobus_register`.
- Atlas domain: Driver Families / drivers/net.
- 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.