All of lore.kernel.org
 help / color / mirror / Atom feed
* [linux-next:master 6296/7246] drivers/dma/sh/rz-dmac.c:726 rz_dmac_chan_get_residue() warn: can 'current_desc' even be NULL?
@ 2026-03-19  8:55 ` Dan Carpenter
  0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2026-03-18 18:40 UTC (permalink / raw)
  To: oe-kbuild; +Cc: lkp, Dan Carpenter

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
TO: Biju Das <biju.das.jz@bp.renesas.com>
CC: Vinod Koul <vkoul@kernel.org>
CC: Long Luu <long.luu.ur@renesas.com>
CC: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
CC: Frank Li <Frank.Li@nxp.com>

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   8e42d2514a7e8eb8d740d0ba82339dd6c0b6463f
commit: 21323b118c16d287355e6497e1098ce1ca348bd6 [6296/7246] dmaengine: sh: rz-dmac: Add device_tx_status() callback
:::::: branch date: 2 hours ago
:::::: commit date: 32 hours ago
config: m68k-randconfig-r073-20260318 (https://download.01.org/0day-ci/archive/20260319/202603190250.VAmYUWk2-lkp@intel.com/config)
compiler: m68k-linux-gcc (GCC) 13.4.0
smatch: v0.5.0-9004-gb810ac53

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
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <error27@gmail.com>
| Closes: https://lore.kernel.org/r/202603190250.VAmYUWk2-lkp@intel.com/

smatch warnings:
drivers/dma/sh/rz-dmac.c:726 rz_dmac_chan_get_residue() warn: can 'current_desc' even be NULL?

vim +/current_desc +726 drivers/dma/sh/rz-dmac.c

21323b118c16d2 Biju Das 2026-03-16  715  
21323b118c16d2 Biju Das 2026-03-16  716  static u32 rz_dmac_chan_get_residue(struct rz_dmac_chan *channel,
21323b118c16d2 Biju Das 2026-03-16  717  				    dma_cookie_t cookie)
21323b118c16d2 Biju Das 2026-03-16  718  {
21323b118c16d2 Biju Das 2026-03-16  719  	struct rz_dmac_desc *current_desc, *desc;
21323b118c16d2 Biju Das 2026-03-16  720  	enum dma_status status;
21323b118c16d2 Biju Das 2026-03-16  721  	u32 crla, crtb, i;
21323b118c16d2 Biju Das 2026-03-16  722  
21323b118c16d2 Biju Das 2026-03-16  723  	/* Get current processing virtual descriptor */
21323b118c16d2 Biju Das 2026-03-16  724  	current_desc = list_first_entry(&channel->ld_active,
21323b118c16d2 Biju Das 2026-03-16  725  					struct rz_dmac_desc, node);
21323b118c16d2 Biju Das 2026-03-16 @726  	if (!current_desc)
21323b118c16d2 Biju Das 2026-03-16  727  		return 0;
21323b118c16d2 Biju Das 2026-03-16  728  
21323b118c16d2 Biju Das 2026-03-16  729  	/*
21323b118c16d2 Biju Das 2026-03-16  730  	 * If the cookie corresponds to a descriptor that has been completed
21323b118c16d2 Biju Das 2026-03-16  731  	 * there is no residue. The same check has already been performed by the
21323b118c16d2 Biju Das 2026-03-16  732  	 * caller but without holding the channel lock, so the descriptor could
21323b118c16d2 Biju Das 2026-03-16  733  	 * now be complete.
21323b118c16d2 Biju Das 2026-03-16  734  	 */
21323b118c16d2 Biju Das 2026-03-16  735  	status = dma_cookie_status(&channel->vc.chan, cookie, NULL);
21323b118c16d2 Biju Das 2026-03-16  736  	if (status == DMA_COMPLETE)
21323b118c16d2 Biju Das 2026-03-16  737  		return 0;
21323b118c16d2 Biju Das 2026-03-16  738  
21323b118c16d2 Biju Das 2026-03-16  739  	/*
21323b118c16d2 Biju Das 2026-03-16  740  	 * If the cookie doesn't correspond to the currently processing virtual
21323b118c16d2 Biju Das 2026-03-16  741  	 * descriptor then the descriptor hasn't been processed yet, and the
21323b118c16d2 Biju Das 2026-03-16  742  	 * residue is equal to the full descriptor size. Also, a client driver
21323b118c16d2 Biju Das 2026-03-16  743  	 * is possible to call this function before rz_dmac_irq_handler_thread()
21323b118c16d2 Biju Das 2026-03-16  744  	 * runs. In this case, the running descriptor will be the next
21323b118c16d2 Biju Das 2026-03-16  745  	 * descriptor, and will appear in the done list. So, if the argument
21323b118c16d2 Biju Das 2026-03-16  746  	 * cookie matches the done list's cookie, we can assume the residue is
21323b118c16d2 Biju Das 2026-03-16  747  	 * zero.
21323b118c16d2 Biju Das 2026-03-16  748  	 */
21323b118c16d2 Biju Das 2026-03-16  749  	if (cookie != current_desc->vd.tx.cookie) {
21323b118c16d2 Biju Das 2026-03-16  750  		list_for_each_entry(desc, &channel->ld_free, node) {
21323b118c16d2 Biju Das 2026-03-16  751  			if (cookie == desc->vd.tx.cookie)
21323b118c16d2 Biju Das 2026-03-16  752  				return 0;
21323b118c16d2 Biju Das 2026-03-16  753  		}
21323b118c16d2 Biju Das 2026-03-16  754  
21323b118c16d2 Biju Das 2026-03-16  755  		list_for_each_entry(desc, &channel->ld_queue, node) {
21323b118c16d2 Biju Das 2026-03-16  756  			if (cookie == desc->vd.tx.cookie)
21323b118c16d2 Biju Das 2026-03-16  757  				return desc->len;
21323b118c16d2 Biju Das 2026-03-16  758  		}
21323b118c16d2 Biju Das 2026-03-16  759  
21323b118c16d2 Biju Das 2026-03-16  760  		list_for_each_entry(desc, &channel->ld_active, node) {
21323b118c16d2 Biju Das 2026-03-16  761  			if (cookie == desc->vd.tx.cookie)
21323b118c16d2 Biju Das 2026-03-16  762  				return desc->len;
21323b118c16d2 Biju Das 2026-03-16  763  		}
21323b118c16d2 Biju Das 2026-03-16  764  
21323b118c16d2 Biju Das 2026-03-16  765  		/*
21323b118c16d2 Biju Das 2026-03-16  766  		 * No descriptor found for the cookie, there's thus no residue.
21323b118c16d2 Biju Das 2026-03-16  767  		 * This shouldn't happen if the calling driver passes a correct
21323b118c16d2 Biju Das 2026-03-16  768  		 * cookie value.
21323b118c16d2 Biju Das 2026-03-16  769  		 */
21323b118c16d2 Biju Das 2026-03-16  770  		WARN(1, "No descriptor for cookie!");
21323b118c16d2 Biju Das 2026-03-16  771  		return 0;
21323b118c16d2 Biju Das 2026-03-16  772  	}
21323b118c16d2 Biju Das 2026-03-16  773  
21323b118c16d2 Biju Das 2026-03-16  774  	/*
21323b118c16d2 Biju Das 2026-03-16  775  	 * We need to read two registers. Make sure the hardware does not move
21323b118c16d2 Biju Das 2026-03-16  776  	 * to next lmdesc while reading the current lmdesc. Trying it 3 times
21323b118c16d2 Biju Das 2026-03-16  777  	 * should be enough: initial read, retry, retry for the paranoid.
21323b118c16d2 Biju Das 2026-03-16  778  	 */
21323b118c16d2 Biju Das 2026-03-16  779  	for (i = 0; i < 3; i++) {
21323b118c16d2 Biju Das 2026-03-16  780  		crla = rz_dmac_ch_readl(channel, CRLA, 1);
21323b118c16d2 Biju Das 2026-03-16  781  		crtb = rz_dmac_ch_readl(channel, CRTB, 1);
21323b118c16d2 Biju Das 2026-03-16  782  		/* Still the same? */
21323b118c16d2 Biju Das 2026-03-16  783  		if (crla == rz_dmac_ch_readl(channel, CRLA, 1))
21323b118c16d2 Biju Das 2026-03-16  784  			break;
21323b118c16d2 Biju Das 2026-03-16  785  	}
21323b118c16d2 Biju Das 2026-03-16  786  
21323b118c16d2 Biju Das 2026-03-16  787  	WARN_ONCE(i >= 3, "residue might not be continuous!");
21323b118c16d2 Biju Das 2026-03-16  788  
21323b118c16d2 Biju Das 2026-03-16  789  	/*
21323b118c16d2 Biju Das 2026-03-16  790  	 * Calculate number of bytes transferred in processing virtual descriptor.
21323b118c16d2 Biju Das 2026-03-16  791  	 * One virtual descriptor can have many lmdesc.
21323b118c16d2 Biju Das 2026-03-16  792  	 */
21323b118c16d2 Biju Das 2026-03-16  793  	return crtb + rz_dmac_calculate_residue_bytes_in_vd(channel, crla);
21323b118c16d2 Biju Das 2026-03-16  794  }
21323b118c16d2 Biju Das 2026-03-16  795  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [linux-next:master 6296/7246] drivers/dma/sh/rz-dmac.c:726 rz_dmac_chan_get_residue() warn: can 'current_desc' even be NULL?
@ 2026-03-19  8:55 ` Dan Carpenter
  0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2026-03-19  8:55 UTC (permalink / raw)
  To: oe-kbuild, Biju Das
  Cc: lkp, oe-kbuild-all, Vinod Koul, Long Luu, Claudiu Beznea,
	Frank Li

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   8e42d2514a7e8eb8d740d0ba82339dd6c0b6463f
commit: 21323b118c16d287355e6497e1098ce1ca348bd6 [6296/7246] dmaengine: sh: rz-dmac: Add device_tx_status() callback
config: m68k-randconfig-r073-20260318 (https://download.01.org/0day-ci/archive/20260319/202603190250.VAmYUWk2-lkp@intel.com/config)
compiler: m68k-linux-gcc (GCC) 13.4.0
smatch: v0.5.0-9004-gb810ac53

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
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
| Closes: https://lore.kernel.org/r/202603190250.VAmYUWk2-lkp@intel.com/

smatch warnings:
drivers/dma/sh/rz-dmac.c:726 rz_dmac_chan_get_residue() warn: can 'current_desc' even be NULL?

vim +/current_desc +726 drivers/dma/sh/rz-dmac.c

21323b118c16d2 Biju Das 2026-03-16  716  static u32 rz_dmac_chan_get_residue(struct rz_dmac_chan *channel,
21323b118c16d2 Biju Das 2026-03-16  717  				    dma_cookie_t cookie)
21323b118c16d2 Biju Das 2026-03-16  718  {
21323b118c16d2 Biju Das 2026-03-16  719  	struct rz_dmac_desc *current_desc, *desc;
21323b118c16d2 Biju Das 2026-03-16  720  	enum dma_status status;
21323b118c16d2 Biju Das 2026-03-16  721  	u32 crla, crtb, i;
21323b118c16d2 Biju Das 2026-03-16  722  
21323b118c16d2 Biju Das 2026-03-16  723  	/* Get current processing virtual descriptor */
21323b118c16d2 Biju Das 2026-03-16  724  	current_desc = list_first_entry(&channel->ld_active,
21323b118c16d2 Biju Das 2026-03-16  725  					struct rz_dmac_desc, node);
21323b118c16d2 Biju Das 2026-03-16 @726  	if (!current_desc)
21323b118c16d2 Biju Das 2026-03-16  727  		return 0;

Use list_first_entry_or_null() if you're not sure whether
the list is empty.  list_first_entry() never returns NULL.

21323b118c16d2 Biju Das 2026-03-16  728  
21323b118c16d2 Biju Das 2026-03-16  729  	/*
21323b118c16d2 Biju Das 2026-03-16  730  	 * If the cookie corresponds to a descriptor that has been completed
21323b118c16d2 Biju Das 2026-03-16  731  	 * there is no residue. The same check has already been performed by the
21323b118c16d2 Biju Das 2026-03-16  732  	 * caller but without holding the channel lock, so the descriptor could
21323b118c16d2 Biju Das 2026-03-16  733  	 * now be complete.

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-03-19  8:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-18 18:40 [linux-next:master 6296/7246] drivers/dma/sh/rz-dmac.c:726 rz_dmac_chan_get_residue() warn: can 'current_desc' even be NULL? kernel test robot
2026-03-19  8:55 ` Dan Carpenter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.