diff options
author | Alexandru Ardelean <alexandru.ardelean@analog.com> | 2019-02-12 16:11:39 +0100 |
---|---|---|
committer | Vinod Koul <vkoul@kernel.org> | 2019-02-25 18:43:50 +0100 |
commit | 3b6679f91e6f7772b7bfa3417b637f09e5998357 (patch) | |
tree | bc3ce18d214657cd5629b850e9bd5b7e374424da /drivers/dma/dmatest.c | |
parent | dmaengine: dmatest: add short-hand `buf_size` var in dmatest_func() (diff) | |
download | linux-3b6679f91e6f7772b7bfa3417b637f09e5998357.tar.xz linux-3b6679f91e6f7772b7bfa3417b637f09e5998357.zip |
dmaengine: dmatest: move test data alloc & free into functions
This patch starts to take advantage of the `dmatest_data` struct by moving
the common allocation & free-ing bits into functions.
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Diffstat (limited to 'drivers/dma/dmatest.c')
-rw-r--r-- | drivers/dma/dmatest.c | 110 |
1 files changed, 55 insertions, 55 deletions
diff --git a/drivers/dma/dmatest.c b/drivers/dma/dmatest.c index 3b148c2647f8..50221d467d86 100644 --- a/drivers/dma/dmatest.c +++ b/drivers/dma/dmatest.c @@ -486,6 +486,53 @@ static unsigned long long dmatest_KBs(s64 runtime, unsigned long long len) return FIXPT_TO_INT(dmatest_persec(runtime, len >> 10)); } +static void __dmatest_free_test_data(struct dmatest_data *d, unsigned int cnt) +{ + unsigned int i; + + for (i = 0; i < cnt; i++) + kfree(d->raw[i]); + + kfree(d->aligned); + kfree(d->raw); +} + +static void dmatest_free_test_data(struct dmatest_data *d) +{ + __dmatest_free_test_data(d, d->cnt); +} + +static int dmatest_alloc_test_data(struct dmatest_data *d, + unsigned int buf_size, u8 align) +{ + unsigned int i = 0; + + d->raw = kcalloc(d->cnt + 1, sizeof(u8 *), GFP_KERNEL); + if (!d->raw) + return -ENOMEM; + + d->aligned = kcalloc(d->cnt + 1, sizeof(u8 *), GFP_KERNEL); + if (!d->aligned) + goto err; + + for (i = 0; i < d->cnt; i++) { + d->raw[i] = kmalloc(buf_size + align, GFP_KERNEL); + if (!d->raw[i]) + goto err; + + /* align to alignment restriction */ + if (align) + d->aligned[i] = PTR_ALIGN(d->raw[i], align); + else + d->aligned[i] = d->raw[i]; + } + + return 0; +err: + __dmatest_free_test_data(d, i); + return -ENOMEM; +} + /* * This function repeatedly tests DMA transfers of various lengths and * offsets for a given operation type until it is told to exit by @@ -588,55 +635,17 @@ static int dmatest_func(void *data) goto err_free_coefs; } - src->aligned = kcalloc(src->cnt + 1, sizeof(u8 *), GFP_KERNEL); - if (!src->aligned) + if (dmatest_alloc_test_data(src, buf_size, align) < 0) goto err_free_coefs; - src->raw = kcalloc(src->cnt + 1, sizeof(u8 *), GFP_KERNEL); - if (!src->raw) - goto err_usrcs; - - for (i = 0; i < src->cnt; i++) { - src->raw[i] = kmalloc(buf_size + align, - GFP_KERNEL); - if (!src->raw[i]) - goto err_srcbuf; - - /* align srcs to alignment restriction */ - if (align) - src->aligned[i] = PTR_ALIGN(src->raw[i], align); - else - src->aligned[i] = src->raw[i]; - } - src->aligned[i] = NULL; - - dst->aligned = kcalloc(dst->cnt + 1, sizeof(u8 *), GFP_KERNEL); - if (!dst->aligned) - goto err_dsts; - - dst->raw = kcalloc(dst->cnt + 1, sizeof(u8 *), GFP_KERNEL); - if (!dst->raw) - goto err_udsts; - - for (i = 0; i < dst->cnt; i++) { - dst->raw[i] = kmalloc(buf_size + align, - GFP_KERNEL); - if (!dst->raw[i]) - goto err_dstbuf; - - /* align dsts to alignment restriction */ - if (align) - dst->aligned[i] = PTR_ALIGN(dst->raw[i], align); - else - dst->aligned[i] = dst->raw[i]; - } - dst->aligned[i] = NULL; + if (dmatest_alloc_test_data(dst, buf_size, align) < 0) + goto err_src; set_user_nice(current, 10); srcs = kcalloc(src->cnt, sizeof(dma_addr_t), GFP_KERNEL); if (!srcs) - goto err_dstbuf; + goto err_dst; dma_pq = kcalloc(dst->cnt, sizeof(dma_addr_t), GFP_KERNEL); if (!dma_pq) @@ -865,19 +874,10 @@ static int dmatest_func(void *data) kfree(dma_pq); err_srcs_array: kfree(srcs); -err_dstbuf: - for (i = 0; dst->raw[i]; i++) - kfree(dst->raw[i]); - kfree(dst->raw); -err_udsts: - kfree(dst->aligned); -err_dsts: -err_srcbuf: - for (i = 0; src->raw[i]; i++) - kfree(src->raw[i]); - kfree(src->raw); -err_usrcs: - kfree(src->aligned); +err_dst: + dmatest_free_test_data(dst); +err_src: + dmatest_free_test_data(src); err_free_coefs: kfree(pq_coefs); err_thread_type: |