linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/kmb: fix potential memleak in error branch
@ 2021-11-18  2:37 Bernard Zhao
  2021-11-20 16:08 ` kernel test robot
  2021-11-22  7:12 ` kernel test robot
  0 siblings, 2 replies; 3+ messages in thread
From: Bernard Zhao @ 2021-11-18  2:37 UTC (permalink / raw)
  To: Anitha Chrisanthus, Edmund Dea, David Airlie, Daniel Vetter,
	dri-devel, linux-kernel
  Cc: Bernard Zhao

This patch try to fix coccicheck warning:
./drivers/gpu/drm/kmb/kmb_drv.c:519:2-8: ERROR: missing put_device; call of_find_device_by_node on line 506, but without a corresponding object release within this function.
./drivers/gpu/drm/kmb/kmb_drv.c:522:2-8: ERROR: missing put_device; call of_find_device_by_node on line 506, but without a corresponding object release within this function.
./drivers/gpu/drm/kmb/kmb_drv.c:529:2-8: ERROR: missing put_device; call of_find_device_by_node on line 506, but without a corresponding object release within this function.
./drivers/gpu/drm/kmb/kmb_drv.c:579:1-7: ERROR: missing put_device; call of_find_device_by_node on line 506, but without a corresponding object release within this function.

Signed-off-by: Bernard Zhao <bernard@vivo.com>
---
 drivers/gpu/drm/kmb/kmb_drv.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/kmb/kmb_drv.c b/drivers/gpu/drm/kmb/kmb_drv.c
index 961ac6fb5fcf..4a7178288ecf 100644
--- a/drivers/gpu/drm/kmb/kmb_drv.c
+++ b/drivers/gpu/drm/kmb/kmb_drv.c
@@ -514,8 +514,10 @@ static int kmb_probe(struct platform_device *pdev)
 	ret = kmb_dsi_host_bridge_init(get_device(&dsi_pdev->dev));
 
 	if (ret == -EPROBE_DEFER) {
+		of_dev_put(dsi_pdev);
 		return -EPROBE_DEFER;
 	} else if (ret) {
+		of_dev_put(dsi_pdev);
 		DRM_ERROR("probe failed to initialize DSI host bridge\n");
 		return ret;
 	}
@@ -523,8 +525,10 @@ static int kmb_probe(struct platform_device *pdev)
 	/* Create DRM device */
 	kmb = devm_drm_dev_alloc(dev, &kmb_driver,
 				 struct kmb_drm_private, drm);
-	if (IS_ERR(kmb))
+	if (IS_ERR(kmb)) {
+		of_dev_put(dsi_pdev);
 		return PTR_ERR(kmb);
+	}
 
 	dev_set_drvdata(dev, &kmb->drm);
 
@@ -572,6 +576,8 @@ static int kmb_probe(struct platform_device *pdev)
 	dev_set_drvdata(dev, NULL);
 	kmb_dsi_host_unregister(kmb->kmb_dsi);
 
+	of_dev_put(dsi_pdev);
+
 	return ret;
 }
 
-- 
2.33.1


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

* Re: [PATCH] drm/kmb: fix potential memleak in error branch
  2021-11-18  2:37 [PATCH] drm/kmb: fix potential memleak in error branch Bernard Zhao
@ 2021-11-20 16:08 ` kernel test robot
  2021-11-22  7:12 ` kernel test robot
  1 sibling, 0 replies; 3+ messages in thread
From: kernel test robot @ 2021-11-20 16:08 UTC (permalink / raw)
  To: Bernard Zhao, Anitha Chrisanthus, Edmund Dea, David Airlie,
	Daniel Vetter, dri-devel, linux-kernel
  Cc: kbuild-all, Bernard Zhao

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

Hi Bernard,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on drm/drm-next]
[also build test ERROR on v5.16-rc1 next-20211118]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Bernard-Zhao/drm-kmb-fix-potential-memleak-in-error-branch/20211118-103810
base:   git://anongit.freedesktop.org/drm/drm drm-next
config: m68k-allmodconfig (attached as .config)
compiler: m68k-linux-gcc (GCC) 11.2.0
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
        # https://github.com/0day-ci/linux/commit/bbd8ae6a806e8e9e31c362a76ab4ba02a43b4694
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Bernard-Zhao/drm-kmb-fix-potential-memleak-in-error-branch/20211118-103810
        git checkout bbd8ae6a806e8e9e31c362a76ab4ba02a43b4694
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross ARCH=m68k 

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

All errors (new ones prefixed by >>):

   drivers/gpu/drm/kmb/kmb_drv.c: In function 'kmb_probe':
>> drivers/gpu/drm/kmb/kmb_drv.c:517:17: error: implicit declaration of function 'of_dev_put'; did you mean 'drm_dev_put'? [-Werror=implicit-function-declaration]
     517 |                 of_dev_put(dsi_pdev);
         |                 ^~~~~~~~~~
         |                 drm_dev_put
   cc1: some warnings being treated as errors


vim +517 drivers/gpu/drm/kmb/kmb_drv.c

   475	
   476	static int kmb_probe(struct platform_device *pdev)
   477	{
   478		struct device *dev = get_device(&pdev->dev);
   479		struct kmb_drm_private *kmb;
   480		int ret = 0;
   481		struct device_node *dsi_in;
   482		struct device_node *dsi_node;
   483		struct platform_device *dsi_pdev;
   484	
   485		/* The bridge (ADV 7535) will return -EPROBE_DEFER until it
   486		 * has a mipi_dsi_host to register its device to. So, we
   487		 * first register the DSI host during probe time, and then return
   488		 * -EPROBE_DEFER until the bridge is loaded. Probe will be called again
   489		 *  and then the rest of the driver initialization can proceed
   490		 *  afterwards and the bridge can be successfully attached.
   491		 */
   492		dsi_in = of_graph_get_endpoint_by_regs(dev->of_node, 0, 0);
   493		if (!dsi_in) {
   494			DRM_ERROR("Failed to get dsi_in node info from DT");
   495			return -EINVAL;
   496		}
   497		dsi_node = of_graph_get_remote_port_parent(dsi_in);
   498		if (!dsi_node) {
   499			of_node_put(dsi_in);
   500			DRM_ERROR("Failed to get dsi node from DT\n");
   501			return -EINVAL;
   502		}
   503	
   504		dsi_pdev = of_find_device_by_node(dsi_node);
   505		if (!dsi_pdev) {
   506			of_node_put(dsi_in);
   507			of_node_put(dsi_node);
   508			DRM_ERROR("Failed to get dsi platform device\n");
   509			return -EINVAL;
   510		}
   511	
   512		of_node_put(dsi_in);
   513		of_node_put(dsi_node);
   514		ret = kmb_dsi_host_bridge_init(get_device(&dsi_pdev->dev));
   515	
   516		if (ret == -EPROBE_DEFER) {
 > 517			of_dev_put(dsi_pdev);
   518			return -EPROBE_DEFER;
   519		} else if (ret) {
   520			of_dev_put(dsi_pdev);
   521			DRM_ERROR("probe failed to initialize DSI host bridge\n");
   522			return ret;
   523		}
   524	
   525		/* Create DRM device */
   526		kmb = devm_drm_dev_alloc(dev, &kmb_driver,
   527					 struct kmb_drm_private, drm);
   528		if (IS_ERR(kmb)) {
   529			of_dev_put(dsi_pdev);
   530			return PTR_ERR(kmb);
   531		}
   532	
   533		dev_set_drvdata(dev, &kmb->drm);
   534	
   535		/* Initialize MIPI DSI */
   536		kmb->kmb_dsi = kmb_dsi_init(dsi_pdev);
   537		if (IS_ERR(kmb->kmb_dsi)) {
   538			drm_err(&kmb->drm, "failed to initialize DSI\n");
   539			ret = PTR_ERR(kmb->kmb_dsi);
   540			goto err_free1;
   541		}
   542	
   543		kmb->kmb_dsi->dev = &dsi_pdev->dev;
   544		kmb->kmb_dsi->pdev = dsi_pdev;
   545		ret = kmb_hw_init(&kmb->drm, 0);
   546		if (ret)
   547			goto err_free1;
   548	
   549		ret = kmb_setup_mode_config(&kmb->drm);
   550		if (ret)
   551			goto err_free;
   552	
   553		ret = kmb_irq_install(&kmb->drm, kmb->irq_lcd);
   554		if (ret < 0) {
   555			drm_err(&kmb->drm, "failed to install IRQ handler\n");
   556			goto err_irq;
   557		}
   558	
   559		drm_kms_helper_poll_init(&kmb->drm);
   560	
   561		/* Register graphics device with the kernel */
   562		ret = drm_dev_register(&kmb->drm, 0);
   563		if (ret)
   564			goto err_register;
   565	
   566		return 0;
   567	
   568	 err_register:
   569		drm_kms_helper_poll_fini(&kmb->drm);
   570	 err_irq:
   571		pm_runtime_disable(kmb->drm.dev);
   572	 err_free:
   573		drm_crtc_cleanup(&kmb->crtc);
   574		drm_mode_config_cleanup(&kmb->drm);
   575	 err_free1:
   576		dev_set_drvdata(dev, NULL);
   577		kmb_dsi_host_unregister(kmb->kmb_dsi);
   578	
   579		of_dev_put(dsi_pdev);
   580	
   581		return ret;
   582	}
   583	

---
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: 61770 bytes --]

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

* Re: [PATCH] drm/kmb: fix potential memleak in error branch
  2021-11-18  2:37 [PATCH] drm/kmb: fix potential memleak in error branch Bernard Zhao
  2021-11-20 16:08 ` kernel test robot
@ 2021-11-22  7:12 ` kernel test robot
  1 sibling, 0 replies; 3+ messages in thread
From: kernel test robot @ 2021-11-22  7:12 UTC (permalink / raw)
  To: Bernard Zhao, Anitha Chrisanthus, Edmund Dea, David Airlie,
	Daniel Vetter, dri-devel, linux-kernel
  Cc: llvm, kbuild-all, Bernard Zhao

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

Hi Bernard,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on drm/drm-next]
[also build test ERROR on v5.16-rc2 next-20211118]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Bernard-Zhao/drm-kmb-fix-potential-memleak-in-error-branch/20211118-103810
base:   git://anongit.freedesktop.org/drm/drm drm-next
config: hexagon-randconfig-r016-20211118 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project c46becf500df2a7fb4b4fce16178a036c344315a)
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
        # https://github.com/0day-ci/linux/commit/bbd8ae6a806e8e9e31c362a76ab4ba02a43b4694
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Bernard-Zhao/drm-kmb-fix-potential-memleak-in-error-branch/20211118-103810
        git checkout bbd8ae6a806e8e9e31c362a76ab4ba02a43b4694
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 ARCH=hexagon 

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

All errors (new ones prefixed by >>):

>> drivers/gpu/drm/kmb/kmb_drv.c:517:3: error: implicit declaration of function 'of_dev_put' [-Werror,-Wimplicit-function-declaration]
                   of_dev_put(dsi_pdev);
                   ^
   drivers/gpu/drm/kmb/kmb_drv.c:520:3: error: implicit declaration of function 'of_dev_put' [-Werror,-Wimplicit-function-declaration]
                   of_dev_put(dsi_pdev);
                   ^
   drivers/gpu/drm/kmb/kmb_drv.c:529:3: error: implicit declaration of function 'of_dev_put' [-Werror,-Wimplicit-function-declaration]
                   of_dev_put(dsi_pdev);
                   ^
   drivers/gpu/drm/kmb/kmb_drv.c:579:2: error: implicit declaration of function 'of_dev_put' [-Werror,-Wimplicit-function-declaration]
           of_dev_put(dsi_pdev);
           ^
   4 errors generated.


vim +/of_dev_put +517 drivers/gpu/drm/kmb/kmb_drv.c

   475	
   476	static int kmb_probe(struct platform_device *pdev)
   477	{
   478		struct device *dev = get_device(&pdev->dev);
   479		struct kmb_drm_private *kmb;
   480		int ret = 0;
   481		struct device_node *dsi_in;
   482		struct device_node *dsi_node;
   483		struct platform_device *dsi_pdev;
   484	
   485		/* The bridge (ADV 7535) will return -EPROBE_DEFER until it
   486		 * has a mipi_dsi_host to register its device to. So, we
   487		 * first register the DSI host during probe time, and then return
   488		 * -EPROBE_DEFER until the bridge is loaded. Probe will be called again
   489		 *  and then the rest of the driver initialization can proceed
   490		 *  afterwards and the bridge can be successfully attached.
   491		 */
   492		dsi_in = of_graph_get_endpoint_by_regs(dev->of_node, 0, 0);
   493		if (!dsi_in) {
   494			DRM_ERROR("Failed to get dsi_in node info from DT");
   495			return -EINVAL;
   496		}
   497		dsi_node = of_graph_get_remote_port_parent(dsi_in);
   498		if (!dsi_node) {
   499			of_node_put(dsi_in);
   500			DRM_ERROR("Failed to get dsi node from DT\n");
   501			return -EINVAL;
   502		}
   503	
   504		dsi_pdev = of_find_device_by_node(dsi_node);
   505		if (!dsi_pdev) {
   506			of_node_put(dsi_in);
   507			of_node_put(dsi_node);
   508			DRM_ERROR("Failed to get dsi platform device\n");
   509			return -EINVAL;
   510		}
   511	
   512		of_node_put(dsi_in);
   513		of_node_put(dsi_node);
   514		ret = kmb_dsi_host_bridge_init(get_device(&dsi_pdev->dev));
   515	
   516		if (ret == -EPROBE_DEFER) {
 > 517			of_dev_put(dsi_pdev);
   518			return -EPROBE_DEFER;
   519		} else if (ret) {
   520			of_dev_put(dsi_pdev);
   521			DRM_ERROR("probe failed to initialize DSI host bridge\n");
   522			return ret;
   523		}
   524	
   525		/* Create DRM device */
   526		kmb = devm_drm_dev_alloc(dev, &kmb_driver,
   527					 struct kmb_drm_private, drm);
   528		if (IS_ERR(kmb)) {
   529			of_dev_put(dsi_pdev);
   530			return PTR_ERR(kmb);
   531		}
   532	
   533		dev_set_drvdata(dev, &kmb->drm);
   534	
   535		/* Initialize MIPI DSI */
   536		kmb->kmb_dsi = kmb_dsi_init(dsi_pdev);
   537		if (IS_ERR(kmb->kmb_dsi)) {
   538			drm_err(&kmb->drm, "failed to initialize DSI\n");
   539			ret = PTR_ERR(kmb->kmb_dsi);
   540			goto err_free1;
   541		}
   542	
   543		kmb->kmb_dsi->dev = &dsi_pdev->dev;
   544		kmb->kmb_dsi->pdev = dsi_pdev;
   545		ret = kmb_hw_init(&kmb->drm, 0);
   546		if (ret)
   547			goto err_free1;
   548	
   549		ret = kmb_setup_mode_config(&kmb->drm);
   550		if (ret)
   551			goto err_free;
   552	
   553		ret = kmb_irq_install(&kmb->drm, kmb->irq_lcd);
   554		if (ret < 0) {
   555			drm_err(&kmb->drm, "failed to install IRQ handler\n");
   556			goto err_irq;
   557		}
   558	
   559		drm_kms_helper_poll_init(&kmb->drm);
   560	
   561		/* Register graphics device with the kernel */
   562		ret = drm_dev_register(&kmb->drm, 0);
   563		if (ret)
   564			goto err_register;
   565	
   566		return 0;
   567	
   568	 err_register:
   569		drm_kms_helper_poll_fini(&kmb->drm);
   570	 err_irq:
   571		pm_runtime_disable(kmb->drm.dev);
   572	 err_free:
   573		drm_crtc_cleanup(&kmb->crtc);
   574		drm_mode_config_cleanup(&kmb->drm);
   575	 err_free1:
   576		dev_set_drvdata(dev, NULL);
   577		kmb_dsi_host_unregister(kmb->kmb_dsi);
   578	
   579		of_dev_put(dsi_pdev);
   580	
   581		return ret;
   582	}
   583	

---
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: 23770 bytes --]

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

end of thread, other threads:[~2021-11-22  7:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-18  2:37 [PATCH] drm/kmb: fix potential memleak in error branch Bernard Zhao
2021-11-20 16:08 ` kernel test robot
2021-11-22  7:12 ` 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).