drivers/dma-buf/st-dma-fence.c:415:10-35: opportunity for str_yes_no(dma_fence_is_signaled ( f2 ))

kernel test robot <[email protected]>
Newsgroups dev.linux.lists.oe-kbuild
Message-ID <[email protected]>
BCC: [email protected]
CC: [email protected]
CC: [email protected]
TO: Jason Gunthorpe <[email protected]>
CC: "Christian König" <[email protected]>

Hi Jason,

First bad commit (maybe != root cause):

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   a635d6748234582ea287c5ffeae28b9b23f91c7e
commit: 9baa35a3993999764965e70be949984891572d2d dma-buf: Change st-dma-fence.c to use kunit
date:   3 months ago
:::::: branch date: 21 hours ago
:::::: commit date: 3 months ago
config: sparc-randconfig-r063-20260708 (https://download.01.org/0day-ci/archive/20260711/[email protected]/config)
compiler: sparc64-linux-gcc (GCC) 12.5.0

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Fixes: 9baa35a39939 ("dma-buf: Change st-dma-fence.c to use kunit")
| Reported-by: kernel test robot <[email protected]>
| Reported-by: Julia Lawall <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

cocci warnings: (new ones prefixed by >>)
>> drivers/dma-buf/st-dma-fence.c:415:10-35: opportunity for str_yes_no(dma_fence_is_signaled ( f2 ))

vim +415 drivers/dma-buf/st-dma-fence.c

2989f6451084aed Chris Wilson 2019-08-19  364  
2989f6451084aed Chris Wilson 2019-08-19  365  static int thread_signal_callback(void *arg)
2989f6451084aed Chris Wilson 2019-08-19  366  {
2989f6451084aed Chris Wilson 2019-08-19  367  	const struct race_thread *t = arg;
2989f6451084aed Chris Wilson 2019-08-19  368  	unsigned long pass = 0;
2989f6451084aed Chris Wilson 2019-08-19  369  	unsigned long miss = 0;
2989f6451084aed Chris Wilson 2019-08-19  370  	int err = 0;
2989f6451084aed Chris Wilson 2019-08-19  371  
2989f6451084aed Chris Wilson 2019-08-19  372  	while (!err && !kthread_should_stop()) {
2989f6451084aed Chris Wilson 2019-08-19  373  		struct dma_fence *f1, *f2;
2989f6451084aed Chris Wilson 2019-08-19  374  		struct simple_cb cb;
2989f6451084aed Chris Wilson 2019-08-19  375  
2989f6451084aed Chris Wilson 2019-08-19  376  		f1 = mock_fence();
2989f6451084aed Chris Wilson 2019-08-19  377  		if (!f1) {
2989f6451084aed Chris Wilson 2019-08-19  378  			err = -ENOMEM;
2989f6451084aed Chris Wilson 2019-08-19  379  			break;
2989f6451084aed Chris Wilson 2019-08-19  380  		}
2989f6451084aed Chris Wilson 2019-08-19  381  
d62c43a953ce02d Arvind Yadav 2022-09-14  382  		dma_fence_enable_sw_signaling(f1);
d62c43a953ce02d Arvind Yadav 2022-09-14  383  
2989f6451084aed Chris Wilson 2019-08-19  384  		rcu_assign_pointer(t->fences[t->id], f1);
2989f6451084aed Chris Wilson 2019-08-19  385  		smp_wmb();
2989f6451084aed Chris Wilson 2019-08-19  386  
2989f6451084aed Chris Wilson 2019-08-19  387  		rcu_read_lock();
2989f6451084aed Chris Wilson 2019-08-19  388  		do {
2989f6451084aed Chris Wilson 2019-08-19  389  			f2 = dma_fence_get_rcu_safe(&t->fences[!t->id]);
2989f6451084aed Chris Wilson 2019-08-19  390  		} while (!f2 && !kthread_should_stop());
2989f6451084aed Chris Wilson 2019-08-19  391  		rcu_read_unlock();
2989f6451084aed Chris Wilson 2019-08-19  392  
2989f6451084aed Chris Wilson 2019-08-19  393  		if (t->before)
2989f6451084aed Chris Wilson 2019-08-19  394  			dma_fence_signal(f1);
2989f6451084aed Chris Wilson 2019-08-19  395  
2989f6451084aed Chris Wilson 2019-08-19  396  		smp_store_mb(cb.seen, false);
46d4a938fe6ddd6 Joe Perches  2020-08-24  397  		if (!f2 ||
46d4a938fe6ddd6 Joe Perches  2020-08-24  398  		    dma_fence_add_callback(f2, &cb.cb, simple_callback)) {
46d4a938fe6ddd6 Joe Perches  2020-08-24  399  			miss++;
46d4a938fe6ddd6 Joe Perches  2020-08-24  400  			cb.seen = true;
46d4a938fe6ddd6 Joe Perches  2020-08-24  401  		}
2989f6451084aed Chris Wilson 2019-08-19  402  
2989f6451084aed Chris Wilson 2019-08-19  403  		if (!t->before)
2989f6451084aed Chris Wilson 2019-08-19  404  			dma_fence_signal(f1);
2989f6451084aed Chris Wilson 2019-08-19  405  
2989f6451084aed Chris Wilson 2019-08-19  406  		if (!cb.seen) {
2989f6451084aed Chris Wilson 2019-08-19  407  			dma_fence_wait(f2, false);
2989f6451084aed Chris Wilson 2019-08-19  408  			__wait_for_callbacks(f2);
2989f6451084aed Chris Wilson 2019-08-19  409  		}
2989f6451084aed Chris Wilson 2019-08-19  410  
2989f6451084aed Chris Wilson 2019-08-19  411  		if (!READ_ONCE(cb.seen)) {
2989f6451084aed Chris Wilson 2019-08-19  412  			pr_err("Callback not seen on thread %d, pass %lu (%lu misses), signaling %s add_callback; fence signaled? %s\n",
2989f6451084aed Chris Wilson 2019-08-19  413  			       t->id, pass, miss,
2989f6451084aed Chris Wilson 2019-08-19  414  			       t->before ? "before" : "after",
2989f6451084aed Chris Wilson 2019-08-19 @415  			       dma_fence_is_signaled(f2) ? "yes" : "no");
2989f6451084aed Chris Wilson 2019-08-19  416  			err = -EINVAL;
2989f6451084aed Chris Wilson 2019-08-19  417  		}
2989f6451084aed Chris Wilson 2019-08-19  418  
2989f6451084aed Chris Wilson 2019-08-19  419  		dma_fence_put(f2);
2989f6451084aed Chris Wilson 2019-08-19  420  
2989f6451084aed Chris Wilson 2019-08-19  421  		rcu_assign_pointer(t->fences[t->id], NULL);
2989f6451084aed Chris Wilson 2019-08-19  422  		smp_wmb();
2989f6451084aed Chris Wilson 2019-08-19  423  
2989f6451084aed Chris Wilson 2019-08-19  424  		dma_fence_put(f1);
2989f6451084aed Chris Wilson 2019-08-19  425  
2989f6451084aed Chris Wilson 2019-08-19  426  		pass++;
2989f6451084aed Chris Wilson 2019-08-19  427  	}
2989f6451084aed Chris Wilson 2019-08-19  428  
2989f6451084aed Chris Wilson 2019-08-19  429  	pr_info("%s[%d] completed %lu passes, %lu misses\n",
2989f6451084aed Chris Wilson 2019-08-19  430  		__func__, t->id, pass, miss);
2989f6451084aed Chris Wilson 2019-08-19  431  	return err;
2989f6451084aed Chris Wilson 2019-08-19  432  }
2989f6451084aed Chris Wilson 2019-08-19  433  

:::::: The code at line 415 was first introduced by commit
:::::: 2989f6451084aed3f8cc9992477f7a9bf57a3716 dma-buf: Add selftests for dma-fence

:::::: TO: Chris Wilson <[email protected]>
:::::: CC: Chris Wilson <[email protected]>

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.