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

Commit 15af7d21 authored by qctecmdr's avatar qctecmdr Committed by Gerrit - the friendly Code Review server
Browse files

Merge "iommu-debug: allocate test_virt_addr when reading it"

parents 72bd5c71 ea0712d6
Loading
Loading
Loading
Loading
+20 −9
Original line number Diff line number Diff line
@@ -1472,9 +1472,13 @@ static ssize_t iommu_debug_test_virt_addr_read(struct file *file,

	memset(buf, 0, buf_len);

	if (!test_virt_addr)
	if (IS_ERR_OR_NULL(test_virt_addr))
		test_virt_addr = kzalloc(SZ_1M, GFP_KERNEL);

	if (!test_virt_addr) {
		test_virt_addr = ERR_PTR(-ENOMEM);
		strlcpy(buf, "FAIL\n", buf_len);
	else
	} else
		snprintf(buf, buf_len, "0x%pK\n", test_virt_addr);

	return simple_read_from_buffer(ubuf, count, offset, buf, strlen(buf));
@@ -1804,6 +1808,12 @@ static ssize_t iommu_debug_dma_map_write(struct file *file,
	if (kstrtouint(comma2 + 1, 0, &attr))
		goto invalid_format;

	if (IS_ERR(test_virt_addr))
		goto allocation_failure;

	if (!test_virt_addr)
		goto missing_allocation;

	if (v_addr < test_virt_addr || v_addr + size > test_virt_addr + SZ_1M)
		goto invalid_addr;

@@ -1851,6 +1861,14 @@ static ssize_t iommu_debug_dma_map_write(struct file *file,
invalid_addr:
	pr_err_ratelimited("Invalid addr given! Address should be within 1MB size from start addr returned by doing 'cat test_virt_addr'.\n");
	return retval;

allocation_failure:
	pr_err_ratelimited("Allocation of test_virt_addr failed.\n");
	return -ENOMEM;

missing_allocation:
	pr_err_ratelimited("Please attempt to do 'cat test_virt_addr'.\n");
	return retval;
}

static ssize_t iommu_debug_dma_map_read(struct file *file, char __user *ubuf,
@@ -2358,13 +2376,6 @@ static int iommu_debug_init_tests(void)
		return -ENODEV;
	}

	test_virt_addr = kzalloc(SZ_1M, GFP_KERNEL);

	if (!test_virt_addr) {
		debugfs_remove_recursive(debugfs_tests_dir);
		return -ENOMEM;
	}

	return 0;
}