diff options
Diffstat (limited to 'mm/cma.c')
-rw-r--r-- | mm/cma.c | 15 |
1 files changed, 14 insertions, 1 deletions
@@ -278,6 +278,12 @@ int __init cma_declare_contiguous(phys_addr_t base, | |||
278 | */ | 278 | */ |
279 | alignment = max(alignment, (phys_addr_t)PAGE_SIZE << | 279 | alignment = max(alignment, (phys_addr_t)PAGE_SIZE << |
280 | max_t(unsigned long, MAX_ORDER - 1, pageblock_order)); | 280 | max_t(unsigned long, MAX_ORDER - 1, pageblock_order)); |
281 | if (fixed && base & (alignment - 1)) { | ||
282 | ret = -EINVAL; | ||
283 | pr_err("Region at %pa must be aligned to %pa bytes\n", | ||
284 | &base, &alignment); | ||
285 | goto err; | ||
286 | } | ||
281 | base = ALIGN(base, alignment); | 287 | base = ALIGN(base, alignment); |
282 | size = ALIGN(size, alignment); | 288 | size = ALIGN(size, alignment); |
283 | limit &= ~(alignment - 1); | 289 | limit &= ~(alignment - 1); |
@@ -308,6 +314,13 @@ int __init cma_declare_contiguous(phys_addr_t base, | |||
308 | if (limit == 0 || limit > memblock_end) | 314 | if (limit == 0 || limit > memblock_end) |
309 | limit = memblock_end; | 315 | limit = memblock_end; |
310 | 316 | ||
317 | if (base + size > limit) { | ||
318 | ret = -EINVAL; | ||
319 | pr_err("Size (%pa) of region at %pa exceeds limit (%pa)\n", | ||
320 | &size, &base, &limit); | ||
321 | goto err; | ||
322 | } | ||
323 | |||
311 | /* Reserve memory */ | 324 | /* Reserve memory */ |
312 | if (fixed) { | 325 | if (fixed) { |
313 | if (memblock_is_region_reserved(base, size) || | 326 | if (memblock_is_region_reserved(base, size) || |
@@ -494,7 +507,7 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align, | |||
494 | * @pages: Allocated pages. | 507 | * @pages: Allocated pages. |
495 | * @count: Number of allocated pages. | 508 | * @count: Number of allocated pages. |
496 | * | 509 | * |
497 | * This function releases memory allocated by alloc_cma(). | 510 | * This function releases memory allocated by cma_alloc(). |
498 | * It returns false when provided pages do not belong to contiguous area and | 511 | * It returns false when provided pages do not belong to contiguous area and |
499 | * true otherwise. | 512 | * true otherwise. |
500 | */ | 513 | */ |