Re: [PATCH] dmaengine: dmatest: fix container_of member in dmatest_callback

From: Vinod Koul
Date: Sun Jan 28 2018 - 23:41:25 EST


On Mon, Jan 22, 2018 at 03:28:28PM +0800, Yang Shunyong wrote:
> The type of arg passed to dmatest_callback is struct dmatest_done.
> It refers to test_done in struct dmatest_thread, not done_wait.
>
> Fixes: 6f6a23a213be ("dmaengine: dmatest: move callback wait ...")
> Signed-off-by: Yang Shunyong <shunyong.yang@xxxxxxxxxxxxxxxx>
> ---
> drivers/dma/dmatest.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/dma/dmatest.c b/drivers/dma/dmatest.c
> index ec5f9d2bc820..906e85d6dedc 100644
> --- a/drivers/dma/dmatest.c
> +++ b/drivers/dma/dmatest.c
> @@ -355,7 +355,7 @@ static void dmatest_callback(void *arg)
> {
> struct dmatest_done *done = arg;
> struct dmatest_thread *thread =
> - container_of(arg, struct dmatest_thread, done_wait);
> + container_of(arg, struct dmatest_thread, test_done);

This fixes it but one of the reason why compilers didn't catch this
was the void arg. I just tested and used 'done' as the argument here
rather than 'arg' and compiler was quick to point out the error.

So a better fix IMO would be:

-- >8 --

diff --git a/drivers/dma/dmatest.c b/drivers/dma/dmatest.c
index ec5f9d2bc820..80cc2be6483c 100644
--- a/drivers/dma/dmatest.c
+++ b/drivers/dma/dmatest.c
@@ -355,7 +355,7 @@ static void dmatest_callback(void *arg)
{
struct dmatest_done *done = arg;
struct dmatest_thread *thread =
- container_of(arg, struct dmatest_thread, done_wait);
+ container_of(done, struct dmatest_thread, test_done);
if (!thread->done) {
done->done = true;
wake_up_all(done->wait);

--
~Vinod