dmaengine.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] dmaengine: sh: usb-dmac: handle pm_runtime_get_sync failure
@ 2020-06-04 20:30 Navid Emamdoost
  2020-06-04 23:55 ` kernel test robot
  0 siblings, 1 reply; 2+ messages in thread
From: Navid Emamdoost @ 2020-06-04 20:30 UTC (permalink / raw)
  To: Dan Williams, Vinod Koul, Geert Uytterhoeven, Simon Horman,
	Stephen Boyd, Navid Emamdoost, dmaengine, linux-kernel
  Cc: emamd001, wu000273, kjlu, mccamant

Calling pm_runtime_get_sync increments the counter even in case of
failure, causing incorrect ref count. Call pm_runtime_put if
pm_runtime_get_sync fails.

Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
---
 drivers/dma/sh/usb-dmac.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/sh/usb-dmac.c b/drivers/dma/sh/usb-dmac.c
index b218a013c260..43511434c90c 100644
--- a/drivers/dma/sh/usb-dmac.c
+++ b/drivers/dma/sh/usb-dmac.c
@@ -797,7 +797,7 @@ static int usb_dmac_probe(struct platform_device *pdev)
 	ret = pm_runtime_get_sync(&pdev->dev);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "runtime PM get sync failed (%d)\n", ret);
-		goto error_pm;
+		goto error_pm_get;
 	}
 
 	ret = usb_dmac_init(dmac);
@@ -853,6 +853,7 @@ static int usb_dmac_probe(struct platform_device *pdev)
 
 error:
 	of_dma_controller_free(pdev->dev.of_node);
+error_pm_get:
 	pm_runtime_put(&pdev->dev);
 error_pm:
 	pm_runtime_disable(&pdev->dev);
-- 
2.17.1


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

* Re: [PATCH] dmaengine: sh: usb-dmac: handle pm_runtime_get_sync failure
  2020-06-04 20:30 [PATCH] dmaengine: sh: usb-dmac: handle pm_runtime_get_sync failure Navid Emamdoost
@ 2020-06-04 23:55 ` kernel test robot
  0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2020-06-04 23:55 UTC (permalink / raw)
  To: Navid Emamdoost, Dan Williams, Vinod Koul, Geert Uytterhoeven,
	Simon Horman, Stephen Boyd, dmaengine, linux-kernel
  Cc: kbuild-all, clang-built-linux, emamd001, wu000273

[-- Attachment #1: Type: text/plain, Size: 9604 bytes --]

Hi Navid,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on slave-dma/next]
[also build test WARNING on linus/master v5.7 next-20200604]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Navid-Emamdoost/dmaengine-sh-usb-dmac-handle-pm_runtime_get_sync-failure/20200605-043604
base:   https://git.kernel.org/pub/scm/linux/kernel/git/vkoul/slave-dma.git next
config: x86_64-allyesconfig (attached as .config)
compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project ac47588bc4ff5927a01ed6fcd269ce86aba52a7c)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install x86_64 cross compiling tool for clang build
        # apt-get install binutils-x86-64-linux-gnu
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>, old ones prefixed by <<):

>> drivers/dma/sh/usb-dmac.c:858:1: warning: unused label 'error_pm' [-Wunused-label]
error_pm:
^~~~~~~~~
1 warning generated.

vim +/error_pm +858 drivers/dma/sh/usb-dmac.c

0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  763  
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  764  static int usb_dmac_probe(struct platform_device *pdev)
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  765  {
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  766  	const enum dma_slave_buswidth widths = USB_DMAC_SLAVE_BUSWIDTH;
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  767  	struct dma_device *engine;
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  768  	struct usb_dmac *dmac;
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  769  	struct resource *mem;
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  770  	unsigned int i;
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  771  	int ret;
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  772  
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  773  	dmac = devm_kzalloc(&pdev->dev, sizeof(*dmac), GFP_KERNEL);
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  774  	if (!dmac)
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  775  		return -ENOMEM;
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  776  
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  777  	dmac->dev = &pdev->dev;
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  778  	platform_set_drvdata(pdev, dmac);
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  779  
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  780  	ret = usb_dmac_parse_of(&pdev->dev, dmac);
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  781  	if (ret < 0)
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  782  		return ret;
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  783  
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  784  	dmac->channels = devm_kcalloc(&pdev->dev, dmac->n_channels,
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  785  				      sizeof(*dmac->channels), GFP_KERNEL);
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  786  	if (!dmac->channels)
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  787  		return -ENOMEM;
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  788  
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  789  	/* Request resources. */
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  790  	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  791  	dmac->iomem = devm_ioremap_resource(&pdev->dev, mem);
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  792  	if (IS_ERR(dmac->iomem))
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  793  		return PTR_ERR(dmac->iomem);
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  794  
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  795  	/* Enable runtime PM and initialize the device. */
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  796  	pm_runtime_enable(&pdev->dev);
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  797  	ret = pm_runtime_get_sync(&pdev->dev);
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  798  	if (ret < 0) {
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  799  		dev_err(&pdev->dev, "runtime PM get sync failed (%d)\n", ret);
7a0d517ffdb0ce Navid Emamdoost    2020-06-04  800  		goto error_pm_get;
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  801  	}
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  802  
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  803  	ret = usb_dmac_init(dmac);
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  804  
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  805  	if (ret) {
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  806  		dev_err(&pdev->dev, "failed to reset device\n");
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  807  		goto error;
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  808  	}
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  809  
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  810  	/* Initialize the channels. */
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  811  	INIT_LIST_HEAD(&dmac->engine.channels);
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  812  
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  813  	for (i = 0; i < dmac->n_channels; ++i) {
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  814  		ret = usb_dmac_chan_probe(dmac, &dmac->channels[i], i);
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  815  		if (ret < 0)
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  816  			goto error;
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  817  	}
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  818  
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  819  	/* Register the DMAC as a DMA provider for DT. */
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  820  	ret = of_dma_controller_register(pdev->dev.of_node, usb_dmac_of_xlate,
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  821  					 NULL);
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  822  	if (ret < 0)
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  823  		goto error;
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  824  
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  825  	/*
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  826  	 * Register the DMA engine device.
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  827  	 *
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  828  	 * Default transfer size of 32 bytes requires 32-byte alignment.
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  829  	 */
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  830  	engine = &dmac->engine;
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  831  	dma_cap_set(DMA_SLAVE, engine->cap_mask);
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  832  
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  833  	engine->dev = &pdev->dev;
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  834  
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  835  	engine->src_addr_widths = widths;
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  836  	engine->dst_addr_widths = widths;
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  837  	engine->directions = BIT(DMA_MEM_TO_DEV) | BIT(DMA_DEV_TO_MEM);
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  838  	engine->residue_granularity = DMA_RESIDUE_GRANULARITY_BURST;
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  839  
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  840  	engine->device_alloc_chan_resources = usb_dmac_alloc_chan_resources;
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  841  	engine->device_free_chan_resources = usb_dmac_free_chan_resources;
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  842  	engine->device_prep_slave_sg = usb_dmac_prep_slave_sg;
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  843  	engine->device_terminate_all = usb_dmac_chan_terminate_all;
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  844  	engine->device_tx_status = usb_dmac_tx_status;
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  845  	engine->device_issue_pending = usb_dmac_issue_pending;
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  846  
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  847  	ret = dma_async_device_register(engine);
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  848  	if (ret < 0)
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  849  		goto error;
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  850  
36fa4a530b7798 Geert Uytterhoeven 2015-10-25  851  	pm_runtime_put(&pdev->dev);
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  852  	return 0;
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  853  
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  854  error:
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  855  	of_dma_controller_free(pdev->dev.of_node);
7a0d517ffdb0ce Navid Emamdoost    2020-06-04  856  error_pm_get:
36fa4a530b7798 Geert Uytterhoeven 2015-10-25  857  	pm_runtime_put(&pdev->dev);
bf55555baaf80c Geert Uytterhoeven 2015-10-25 @858  error_pm:
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  859  	pm_runtime_disable(&pdev->dev);
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  860  	return ret;
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  861  }
0c1c8ff32fa29e Yoshihiro Shimoda  2015-04-01  862  

:::::: The code at line 858 was first introduced by commit
:::::: bf55555baaf80cdf2cc4176fee02545a07a8ff4a dmaengine: sh: usb-dmac: Fix pm_runtime_{enable,disable}() imbalance

:::::: TO: Geert Uytterhoeven <geert+renesas@glider.be>
:::::: CC: Vinod Koul <vinod.koul@intel.com>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 73468 bytes --]

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

end of thread, other threads:[~2020-06-05  0:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-04 20:30 [PATCH] dmaengine: sh: usb-dmac: handle pm_runtime_get_sync failure Navid Emamdoost
2020-06-04 23:55 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).