Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dma-buf: handle testing kthreads creation failure

kthread creation may possibly fail inside race_signal_callback(). In
such a case stop the already started threads, put the already taken
references to them and return with error code.

Found by Linux Verification Center (linuxtesting.org).

Fixes: 2989f6451084 ("dma-buf: Add selftests for dma-fence")
Cc: stable@vger.kernel.org
Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
Reviewed-by: T.J. Mercier <tjmercier@google.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240522181308.841686-1-pchelkin@ispras.ru
Signed-off-by: Christian König <christian.koenig@amd.com>

authored by

Fedor Pchelkin and committed by
Christian König
6cb05d89 779aa4d7

+6
+6
drivers/dma-buf/st-dma-fence.c
··· 540 540 t[i].before = pass; 541 541 t[i].task = kthread_run(thread_signal_callback, &t[i], 542 542 "dma-fence:%d", i); 543 + if (IS_ERR(t[i].task)) { 544 + ret = PTR_ERR(t[i].task); 545 + while (--i >= 0) 546 + kthread_stop_put(t[i].task); 547 + return ret; 548 + } 543 549 get_task_struct(t[i].task); 544 550 } 545 551