mirror of
https://github.com/nxp-imx/linux-imx.git
synced 2025-07-08 18:35:20 +02:00
mmc: mmc_test: Fix NULL dereference on allocation failure
[ Upstream commita1e627af32
] If the "test->highmem = alloc_pages()" allocation fails then calling __free_pages(test->highmem) will result in a NULL dereference. Also change the error code to -ENOMEM instead of returning success. Fixes:2661081f5a
("mmc_test: highmem tests") Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> Link: https://lore.kernel.org/r/8c90be28-67b4-4b0d-a105-034dc72a0b31@stanley.mountain Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
88c232fd06
commit
cac2815f49
|
@ -3104,13 +3104,13 @@ static ssize_t mtf_test_write(struct file *file, const char __user *buf,
|
||||||
test->buffer = kzalloc(BUFFER_SIZE, GFP_KERNEL);
|
test->buffer = kzalloc(BUFFER_SIZE, GFP_KERNEL);
|
||||||
#ifdef CONFIG_HIGHMEM
|
#ifdef CONFIG_HIGHMEM
|
||||||
test->highmem = alloc_pages(GFP_KERNEL | __GFP_HIGHMEM, BUFFER_ORDER);
|
test->highmem = alloc_pages(GFP_KERNEL | __GFP_HIGHMEM, BUFFER_ORDER);
|
||||||
|
if (!test->highmem) {
|
||||||
|
count = -ENOMEM;
|
||||||
|
goto free_test_buffer;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_HIGHMEM
|
|
||||||
if (test->buffer && test->highmem) {
|
|
||||||
#else
|
|
||||||
if (test->buffer) {
|
if (test->buffer) {
|
||||||
#endif
|
|
||||||
mutex_lock(&mmc_test_lock);
|
mutex_lock(&mmc_test_lock);
|
||||||
mmc_test_run(test, testcase);
|
mmc_test_run(test, testcase);
|
||||||
mutex_unlock(&mmc_test_lock);
|
mutex_unlock(&mmc_test_lock);
|
||||||
|
@ -3118,6 +3118,7 @@ static ssize_t mtf_test_write(struct file *file, const char __user *buf,
|
||||||
|
|
||||||
#ifdef CONFIG_HIGHMEM
|
#ifdef CONFIG_HIGHMEM
|
||||||
__free_pages(test->highmem, BUFFER_ORDER);
|
__free_pages(test->highmem, BUFFER_ORDER);
|
||||||
|
free_test_buffer:
|
||||||
#endif
|
#endif
|
||||||
kfree(test->buffer);
|
kfree(test->buffer);
|
||||||
kfree(test);
|
kfree(test);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user