dmam_alloc_coherent is just the default no-flags case of dmam_alloc_attrs, so take advantage of this similar to the non-managed version.
Showing the changes to kernel (1 of 2 files). Show all
Unified · Split
| @@ -45,45 +45,6 @@ static int dmam_match(struct device *dev, void *res, void *match_data) · 44 unmodified lines | |||
| 45 | return 0; | 45 | return 0; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | /** | ||
| 49 | * dmam_alloc_coherent - Managed dma_alloc_coherent() | ||
| 50 | * @dev: Device to allocate coherent memory for | ||
| 51 | * @size: Size of allocation | ||
| 52 | * @dma_handle: Out argument for allocated DMA handle | ||
| 53 | * @gfp: Allocation flags | ||
| 54 | * | ||
| 55 | * Managed dma_alloc_coherent(). Memory allocated using this function | ||
| 56 | * will be automatically released on driver detach. | ||
| 57 | * | ||
| 58 | * RETURNS: | ||
| 59 | * Pointer to allocated memory on success, NULL on failure. | ||
| 60 | */ | ||
| 61 | void *dmam_alloc_coherent(struct device *dev, size_t size, | ||
| 62 | dma_addr_t *dma_handle, gfp_t gfp) | ||
| 63 | { | ||
| 64 | struct dma_devres *dr; | ||
| 65 | void *vaddr; | ||
| 66 | |||
| 67 | dr = devres_alloc(dmam_release, sizeof(*dr), gfp); | ||
| 68 | if (!dr) | ||
| 69 | return NULL; | ||
| 70 | |||
| 71 | vaddr = dma_alloc_coherent(dev, size, dma_handle, gfp); | ||
| 72 | if (!vaddr) { | ||
| 73 | devres_free(dr); | ||
| 74 | return NULL; | ||
| 75 | } | ||
| 76 | |||
| 77 | dr->vaddr = vaddr; | ||
| 78 | dr->dma_handle = *dma_handle; | ||
| 79 | dr->size = size; | ||
| 80 | |||
| 81 | devres_add(dev, dr); | ||
| 82 | |||
| 83 | return vaddr; | ||
| 84 | } | ||
| 85 | EXPORT_SYMBOL(dmam_alloc_coherent); | ||
| 86 | |||
| 87 | /** | 48 | /** |
| 88 | * dmam_free_coherent - Managed dma_free_coherent() | 49 | * dmam_free_coherent - Managed dma_free_coherent() |
| 89 | * @dev: Device to free coherent memory for | 50 | * @dev: Device to free coherent memory for |