Skip to content

Commit

Permalink
spi: loopback-test: Fix kfree() NULL pointer error.
Browse files Browse the repository at this point in the history
Here, rx/tx allocation can fail. So avoid kvfree call
with NULL pointer.

Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Arvind Yadav authored and Mark Brown committed Jun 28, 2017
1 parent 478de2b commit 704c309
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions drivers/spi/spi-loopback-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1021,18 +1021,17 @@ int spi_test_run_tests(struct spi_device *spi,
rx = vmalloc(SPI_TEST_MAX_SIZE_PLUS);
else
rx = kzalloc(SPI_TEST_MAX_SIZE_PLUS, GFP_KERNEL);
if (!rx) {
ret = -ENOMEM;
goto out;
}
if (!rx)
return -ENOMEM;


if (use_vmalloc)
tx = vmalloc(SPI_TEST_MAX_SIZE_PLUS);
else
tx = kzalloc(SPI_TEST_MAX_SIZE_PLUS, GFP_KERNEL);
if (!tx) {
ret = -ENOMEM;
goto out;
goto err_tx;
}

/* now run the individual tests in the table */
Expand All @@ -1057,8 +1056,9 @@ int spi_test_run_tests(struct spi_device *spi,
}

out:
kvfree(rx);
kvfree(tx);
err_tx:
kvfree(rx);
return ret;
}
EXPORT_SYMBOL_GPL(spi_test_run_tests);

0 comments on commit 704c309

Please sign in to comment.