All of lore.kernel.org
 help / color / mirror / Atom feed
From: kernel test robot <lkp@intel.com>
To: oe-kbuild@lists.linux.dev
Cc: lkp@intel.com, Dan Carpenter <error27@gmail.com>
Subject: [linux-next:master 6296/7246] drivers/dma/sh/rz-dmac.c:726 rz_dmac_chan_get_residue() warn: can 'current_desc' even be NULL?
Date: Thu, 19 Mar 2026 02:40:15 +0800	[thread overview]
Message-ID: <202603190250.VAmYUWk2-lkp@intel.com> (raw)

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

WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@linaro.org>
To: oe-kbuild@lists.linux.dev, Biju Das <biju.das.jz@bp.renesas.com>
Cc: lkp@intel.com, oe-kbuild-all@lists.linux.dev,
	Vinod Koul <vkoul@kernel.org>, Long Luu <long.luu.ur@renesas.com>,
	Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>,
	Frank Li <Frank.Li@nxp.com>
Subject: [linux-next:master 6296/7246] drivers/dma/sh/rz-dmac.c:726 rz_dmac_chan_get_residue() warn: can 'current_desc' even be NULL?
Date: Thu, 19 Mar 2026 11:55:15 +0300	[thread overview]
Message-ID: <202603190250.VAmYUWk2-lkp@intel.com> (raw)
Message-ID: <20260319085515.aRRhzWxA5nPDBpqn4ECjsjkiJ2rR89zgw61JIlJL21I@z> (raw)

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


             reply	other threads:[~2026-03-18 18:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-18 18:40 kernel test robot [this message]
2026-03-19  8:55 ` [linux-next:master 6296/7246] drivers/dma/sh/rz-dmac.c:726 rz_dmac_chan_get_residue() warn: can 'current_desc' even be NULL? Dan Carpenter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202603190250.VAmYUWk2-lkp@intel.com \
    --to=lkp@intel.com \
    --cc=error27@gmail.com \
    --cc=oe-kbuild@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.