Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5e6bbb64 authored by Mao Jinlong's avatar Mao Jinlong Committed by Gerrit - the friendly Code Review server
Browse files

coresight-tmc-etr: Use vmalloc once kcalloc fail



Sometimes system doesn't have enough continuous pages for kcalloc.
If kcalloc fail, use vmalloc instead.

Change-Id: Ie0864224f4eeedbd01b301f59b4eb307cc1f8df2
Signed-off-by: default avatarMao Jinlong <jinlmao@codeaurora.org>
parent 2ae37c23
Loading
Loading
Loading
Loading
+24 −7
Original line number Diff line number Diff line
@@ -168,7 +168,14 @@ static void tmc_pages_free(struct tmc_pages *tmc_pages,
			__free_page(tmc_pages->pages[i]);
	}

	if (is_vmalloc_addr(tmc_pages->pages))
		vfree(tmc_pages->pages);
	else
		kfree(tmc_pages->pages);

	if (is_vmalloc_addr(tmc_pages->daddrs))
		vfree(tmc_pages->daddrs);
	else
		kfree(tmc_pages->daddrs);
	tmc_pages->pages = NULL;
	tmc_pages->daddrs = NULL;
@@ -195,15 +202,25 @@ static int tmc_pages_alloc(struct tmc_pages *tmc_pages,
	nr_pages = tmc_pages->nr_pages;
	tmc_pages->daddrs = kcalloc(nr_pages, sizeof(*tmc_pages->daddrs),
					 GFP_KERNEL);
	if (!tmc_pages->daddrs) {
		tmc_pages->daddrs = vmalloc(sizeof(*tmc_pages->daddrs) * nr_pages);
		if (!tmc_pages->daddrs)
			return -ENOMEM;
	}

	tmc_pages->pages = kcalloc(nr_pages, sizeof(*tmc_pages->pages),
					 GFP_KERNEL);
	if (!tmc_pages->pages) {
		tmc_pages->pages = vmalloc(sizeof(*tmc_pages->pages) * nr_pages);
		if (!tmc_pages->pages) {
			if (is_vmalloc_addr(tmc_pages->daddrs))
				vfree(tmc_pages->daddrs);
			else
				kfree(tmc_pages->daddrs);
			tmc_pages->daddrs = NULL;
			return -ENOMEM;
		}
	}

	for (i = 0; i < nr_pages; i++) {
		if (pages && pages[i]) {