Re: [PATCH] drm/kmb: fix potential memleak in error branch

2021-11-21 Thread kernel test robot
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-2028]
[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/2028-103810
base:   git://anongit.freedesktop.org/drm/drm drm-next
config: hexagon-randconfig-r016-2028 (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/2028-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 

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 D

Re: [PATCH] drm/kmb: fix potential memleak in error branch

2021-11-20 Thread kernel test robot
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-2028]
[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/2028-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/2028-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 

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

[PATCH] drm/kmb: fix potential memleak in error branch

2021-11-17 Thread 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 
---
 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