dmaengine: pxa_dma: Annotate struct pxad_desc_sw with __counted_by
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Sat, 7 Oct 2023 11:13:10 +0000 (13:13 +0200)
committerVinod Koul <vkoul@kernel.org>
Mon, 9 Oct 2023 05:17:26 +0000 (10:47 +0530)
commit0481291f0ccbc5147635cf0eb108f9fe5a05ee7d
treedeb32bfff86c301681ee9914137842e057822e83
parent83c761f568733277ce1f7eb9dc9e890649c29a8c
dmaengine: pxa_dma: Annotate struct pxad_desc_sw with __counted_by

Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

To do so, the code needs a little shuffling related to how hw_desc is used
and nb_desc incremented.

The one by one increment is needed for the error handling path, calling
pxad_free_desc(), to work correctly.

So, add a new intermediate variable, desc, to store the result of the
dma_pool_alloc() call.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/1c9ef22826f449a3756bb13a83494e9fe3e0be8b.1696676782.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Vinod Koul <vkoul@kernel.org>
drivers/dma/pxa_dma.c