devm_ioremap_resource(9)
πΈ devm_ioremap_resource(9) β Kernel API Manual πΈ
ok so bestie, let me tell you about devm_ioremap_resource(9) β it's in the Kernel API Manual and it's literally the "check it, claim it, map it" combo platter. π
β¨ NAME β¨
devm_ioremap_resource β check, request region, and ioremap resource
Like, all three things. In one function. She's efficient.
β¨ SYNOPSIS β¨
void __iomem * devm_ioremap_resource (struct device *dev , const struct
resource *res );
β¨ ARGUMENTS β¨
devβ the generic device that's handling the resource for you π«Άresβ the resource being handled, the actual thing you're working with
β¨ DESCRIPTION β¨
okay so here's the vibe: it checks that a resource is a valid memory region, requests the memory region, and ioremaps it. That's the whole arc. π
And the iconic part? All operations are managed and will be undone on driver detach. So you don't have to clean up after yourself β devm's got you. Periodt.
Usage example, literally from the source:
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); base = devm_ioremap_resource(pdev->dev, res); if (IS_ERR(base)) return PTR_ERR(base);
no cap, that IS_ERR check is not optional, bestie. do not skip her. π
β¨ RETURN β¨
a pointer to the remapped memory, or an ERR_PTR encoded error code on failure. so check it with IS_ERR before you go doing main character things with it π
β¨ SEE ALSO β¨
Kernel file ./lib/devres.c β and the whole friend group:
devm_ioremap(9)devm_ioremap_uc(9)devm_ioremap_wc(9)devm_iounmap(9)devm_ioremap_resource_wc(9)devm_ioport_map(9)devm_ioport_unmap(9)devm_arch_phys_wc_add(9)devm_arch_io_reserve_memtype_wc(9)
π that's the whole page, you ate that. go forth and map responsibly.
ok bye ily, this came from ./lib, October 2026 version, and yes the footer really does say devm_ioremap_resource(9) again β she's consistent πβ¨π¦
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms