struct device
, in the Linux kernel device tree. The devres_head
field was added to the devres_head
(in fact, another one for access synchronization), which indicates the list of managed resources, if such were used at the stage ->probe()
. A managed resource is a dedicated memory on the heap associated with a data structure, in the case of kmalloc()
, for example, it is simply a void *
pointer.->probe()
, as I have already said, the list of managed resources is being replenished, at the stage ->remove()
basic part of the driver maintenance will take care of freeing all occupied resources exactly in the reverse order of adding them.devm_kasprintf ()
devm_kcalloc ()
devm_kmalloc ()
devm_kmemdup ()
devm_kstrdup ()
devm_kzalloc ()
struct my_cool_device { struct device *dev; void *memregion; }; int mydev_probe(...) { struct device *dev = ...; struct my_cool_device *cool; cool = devm_kzalloc(dev, ...); if (!cool) return -ENOMEM; cool->memregion = devm_kmalloc(dev, ...); if (!cool->memregion) return -ENOMEM; cool->dev = dev; dev_info(dev, "Found my cool device\n"); return 0; } void mydev_remove(...) { /* Nothing! */ }
->remove()
! void mydev_remove(...) { struct device *dev = ...; struct my_cool_device *cool = ...; devm_kfree(dev, cool->memregion); }
void mydev_remove(...) { struct my_cool_device *cool = ...; kfree(cool->memregion); }
dmam_alloc_coherent ()
dmam_alloc_noncoherent ()
dmam_pool_create ()
devm_ioport_map ()
devm_ioremap ()
devm_ioremap_resource (): checks a resource, requests a region of memory, projects it onto the physical addresses of the device
pcim_iomap ()
pcim_iomap_regions (): queries the region and projects the physical addresses specified in the required BARs onto it
pcim_iomap_table (): an array of projected addresses indexed by the BAR number
devm_request_any_context_irq ()
devm_request_irq ()
devm_request_threaded_irq ()
devm_regulator_bulk_get ()
devm_regulator_get ()
devm_regulator_register ()
devm_iio_device_alloc ()
devm_iio_device_register ()
devm_iio_kfifo_allocate ()
devm_iio_trigger_alloc ()
devm_mdiobus_alloc ()
devm_mdiobus_alloc_size ()
pcim_enable_device (): in case of successful completion all operations are assumed to be managed
pcim_pin_device (): leave the device enabled after release
pcim_enable_device()
. Once applied, it is necessary to clean out the release of regions, even if their selection and projection is carried out in the old way. For example, you can see the details in commit 5618955c4269 .devm_spi_register_master ()
devm_gpiod_get ()
devm_gpiod_get_index ()
devm_gpiod_get_index_optional ()
devm_gpiod_get_optional ()
devm_pinctrl_get ()
Source: https://habr.com/ru/post/255459/
All Articles