Skip to contentSkip to conversation

drm/meson: clean up KMS polling on register failure

PATCH Superseded Myeonghun Pak 4 participants 8 messages May 24 – Aug 4

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/meson: clean up KMS polling on register failure

meson_drv_bind_master() starts the KMS polling helper before registering the DRM device. If drm_dev_register() fails, probe unwinds the IRQ and DRM device without stopping the polling helper.

Call drm_kms_helper_poll_fini() on that failure path before freeing the IRQ.

This issue was identified during our ongoing static-analysis research while reviewing kernel code.

Fixes bbbe775ec5b5 ("drm: Add support for Amlogic Meson Graphic Controller")
---
 drivers/gpu/drm/meson/meson_drv.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/meson/meson_drv.c +3 -1
index 49ff9f1f16..e49de5df73 100644
@@ -352,12 +352,14 @@ static int meson_drv_bind_master(struct device *dev, bool has_components)
 
 	ret = drm_dev_register(drm, 0);
 	if (ret)
-		goto uninstall_irq;
+		goto uninstall_poll;
 
 	drm_client_setup(drm, NULL);
 
 	return 0;
 
+uninstall_poll:
+	drm_kms_helper_poll_fini(drm);
 uninstall_irq:
 	free_irq(priv->vsync_irq, drm);
 exit_afbcd:
Signature · 1 line
2.47.1
#1 lore raw
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] Use-after-free of the drm pointer in the free_drm error path of meson_drv_bind_master().
- [High] Memory leak of devm_* allocated resources during component bind failures or unbind operations. --

commit 0a1b882dff3689e80c5546f7c0bf38c6930a1652
Author: Myeonghun Pak <[email protected]> drm/meson: clean up KMS polling on register failure

This commit fixes an issue in meson_drv_bind_master() where the KMS polling helper is left running if drm_dev_register() fails. It introduces a new uninstall_poll error path to call drm_kms_helper_poll_fini() before freeing the IRQ.

Quoted 10 lines
drivers/gpu/drm/meson/meson_drv.c +1 -1
index 49ff9f1f16d32..e49de5df73867 100644
@@ -352,12 +352,14 @@ static int meson_drv_bind_master(struct device *dev, bool has_components)
 
 	ret = drm_dev_register(drm, 0);
 	if (ret)
-		goto uninstall_irq;
+		goto uninstall_poll;

drivers/gpu/drm/meson/meson_drv.c static int meson_drv_bind_master(struct device *dev, bool has_components) · line 365

Quoted 10 lines
drivers/gpu/drm/meson/meson_drv.c +2 -0
 
 	drm_client_setup(drm, NULL);
 
 	return 0;
 
+uninstall_poll:
+	drm_kms_helper_poll_fini(drm);
 uninstall_irq:
 	free_irq(priv->vsync_irq, drm);
 exit_afbcd:

[Severity: High]
This isn't a bug introduced by this patch, but does the error unwinding path have a use-after-free?

Looking further down in this function at the free_drm label:

free_drm:

	drm_dev_put(drm);

	meson_encoder_dsi_remove(priv);
	meson_encoder_hdmi_remove(priv);
	meson_encoder_cvbs_remove(priv);

	if (has_components)
		component_unbind_all(dev, drm);

Since drm_dev_put() drops the final reference and frees the drm structure, won't component_unbind_all() trigger a use-after-free when unbind callbacks dereference the freed pointer?

[Severity: High]
This is also a pre-existing issue, but are we leaking devm_* resources during component bind failures or unbind operations?

Because devm allocations are scoped to the device probe lifecycle, they are not implicitly released during bind failure paths or unbind calls.

Could this result in permanent memory leaks across retries if component binding fails and is later retried?

Signature · 6 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1

_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic
#2 lore raw

Thanks for the review.

Both points look pre-existing and unrelated to this patch. This change only adds the missing drm_kms_helper_poll_fini() on the drm_dev_register() failure path after drm_kms_helper_poll_init(). It does not change the drm_dev_put()/component_unbind_all() ordering or the component bind devm resource lifetime.

I would prefer to keep this patch scoped to the KMS polling unwind fix.

2026년 5월 25일 (월) 오전 1:25, <[email protected]>님이 작성:

Quoted 70 lines

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] Use-after-free of the drm pointer in the free_drm error path of meson_drv_bind_master().
- [High] Memory leak of devm_* allocated resources during component bind failures or unbind operations. --

commit 0a1b882dff3689e80c5546f7c0bf38c6930a1652
Author: Myeonghun Pak <[email protected]> drm/meson: clean up KMS polling on register failure

This commit fixes an issue in meson_drv_bind_master() where the KMS polling helper is left running if drm_dev_register() fails. It introduces a new uninstall_poll error path to call drm_kms_helper_poll_fini() before freeing the IRQ.

Quoted 10 lines
drivers/gpu/drm/meson/meson_drv.c +1 -1
index 49ff9f1f16d32..e49de5df73867 100644
@@ -352,12 +352,14 @@ static int meson_drv_bind_master(struct device *dev, bool has_components)
 
      ret = drm_dev_register(drm, 0);
      if (ret)
-             goto uninstall_irq;
+             goto uninstall_poll;

drivers/gpu/drm/meson/meson_drv.c static int meson_drv_bind_master(struct device *dev, bool has_components) · line 365

Quoted 10 lines
drivers/gpu/drm/meson/meson_drv.c +2 -0
 
      drm_client_setup(drm, NULL);
 
      return 0;
 
+uninstall_poll:
+     drm_kms_helper_poll_fini(drm);
 uninstall_irq:
      free_irq(priv->vsync_irq, drm);
 exit_afbcd:

[Severity: High]
This isn't a bug introduced by this patch, but does the error unwinding path have a use-after-free?

Looking further down in this function at the free_drm label:

free_drm:

        drm_dev_put(drm);

        meson_encoder_dsi_remove(priv);
        meson_encoder_hdmi_remove(priv);
        meson_encoder_cvbs_remove(priv);

        if (has_components)
                component_unbind_all(dev, drm);

Since drm_dev_put() drops the final reference and frees the drm structure, won't component_unbind_all() trigger a use-after-free when unbind callbacks dereference the freed pointer?

[Severity: High]
This is also a pre-existing issue, but are we leaking devm_* resources during component bind failures or unbind operations?

Because devm allocations are scoped to the device probe lifecycle, they are not implicitly released during bind failure paths or unbind calls.

Could this result in permanent memory leaks across retries if component binding fails and is later retried?

--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1

maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to Myeonghun Pak
Quoted 29 lines · Myeonghun Pak

meson_drv_bind_master() starts the KMS polling helper before registering the DRM device. If drm_dev_register() fails, probe unwinds the IRQ and DRM device without stopping the polling helper.

Call drm_kms_helper_poll_fini() on that failure path before freeing the IRQ.

This issue was identified during our ongoing static-analysis research while reviewing kernel code.

Fixes bbbe775ec5b5 ("drm: Add support for Amlogic Meson Graphic Controller")
---
  drivers/gpu/drm/meson/meson_drv.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/meson/meson_drv.c +1 -1
index 49ff9f1f16..e49de5df73 100644
@@ -352,12 +352,14 @@ static int meson_drv_bind_master(struct device *dev, bool has_components)
 
  	ret = drm_dev_register(drm, 0);
  	if (ret)
-		goto uninstall_irq;
+		goto uninstall_poll;

drivers/gpu/drm/meson/meson_drv.c static int meson_drv_bind_master(struct device *dev, bool has_components) · line 365

Quoted 10 lines
drivers/gpu/drm/meson/meson_drv.c +2 -0
 
  	drm_client_setup(drm, NULL);
 
  	return 0;
 
+uninstall_poll:
+	drm_kms_helper_poll_fini(drm);
  uninstall_irq:
  	free_irq(priv->vsync_irq, drm);
  exit_afbcd:

Thanks,
Neil

#4 lore raw
In reply to Myeonghun Pak
kernel test robot noticed the following build warnings:

Hi Myeonghun,

kernel test robot noticed the following build warnings:

[auto build test WARNING on drm-misc/drm-misc-next]
[also build test WARNING on linus/master v7.1-rc5 next-20260526] [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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Myeonghun-Pak/drm-meson-clean-up-KMS-polling-on-register-failure/20260525-000807
base:   https://gitlab.freedesktop.org/drm/misc/kernel.git drm-misc-next
patch link:    https://lore.kernel.org/r/20260524160657.17802-1-mhun512%40gmail.com
patch subject: [PATCH] drm/meson: clean up KMS polling on register failure
config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20260527/[email protected]/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260527/[email protected]/reproduce)

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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> drivers/gpu/drm/meson/meson_drv.c:363:1: warning: unused label 'uninstall_irq' [-Wunused-label]
     363 | uninstall_irq:
         | ^~~~~~~~~~~~~~

1 warning generated.

vim +/uninstall_irq +363 drivers/gpu/drm/meson/meson_drv.c

8976eeee8de05f1 Neil Armstrong        2020-04-28  180  
8604889f83381ca Neil Armstrong        2017-05-29  181  static int meson_drv_bind_master(struct device *dev, bool has_components)
bbbe775ec5b5dac Neil Armstrong        2016-11-10  182  {
a41e82e6c4575b6 Neil Armstrong        2017-04-04  183  	struct platform_device *pdev = to_platform_device(dev);
d1b5e41e13a7e9b Neil Armstrong        2019-10-21  184  	const struct meson_drm_match_data *match;
bbbe775ec5b5dac Neil Armstrong        2016-11-10  185  	struct meson_drm *priv;
bbbe775ec5b5dac Neil Armstrong        2016-11-10  186  	struct drm_device *drm;
bbbe775ec5b5dac Neil Armstrong        2016-11-10  187  	struct resource *res;
bbbe775ec5b5dac Neil Armstrong        2016-11-10  188  	void __iomem *regs;
8976eeee8de05f1 Neil Armstrong        2020-04-28  189  	int ret, i;
bbbe775ec5b5dac Neil Armstrong        2016-11-10  190  
bbbe775ec5b5dac Neil Armstrong        2016-11-10  191  	/* Checks if an output connector is available */
bbbe775ec5b5dac Neil Armstrong        2016-11-10  192  	if (!meson_vpu_has_available_connectors(dev)) {
bbbe775ec5b5dac Neil Armstrong        2016-11-10  193  		dev_err(dev, "No output connector available\n");
bbbe775ec5b5dac Neil Armstrong        2016-11-10  194  		return -ENODEV;
bbbe775ec5b5dac Neil Armstrong        2016-11-10  195  	}
bbbe775ec5b5dac Neil Armstrong        2016-11-10  196  
d1b5e41e13a7e9b Neil Armstrong        2019-10-21  197  	match = of_device_get_match_data(dev);
d1b5e41e13a7e9b Neil Armstrong        2019-10-21  198  	if (!match)
d1b5e41e13a7e9b Neil Armstrong        2019-10-21  199  		return -ENODEV;
d1b5e41e13a7e9b Neil Armstrong        2019-10-21  200  
bbbe775ec5b5dac Neil Armstrong        2016-11-10  201  	drm = drm_dev_alloc(&meson_driver, dev);
bbbe775ec5b5dac Neil Armstrong        2016-11-10  202  	if (IS_ERR(drm))
bbbe775ec5b5dac Neil Armstrong        2016-11-10  203  		return PTR_ERR(drm);
bbbe775ec5b5dac Neil Armstrong        2016-11-10  204  
bbbe775ec5b5dac Neil Armstrong        2016-11-10  205  	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
bbbe775ec5b5dac Neil Armstrong        2016-11-10  206  	if (!priv) {
bbbe775ec5b5dac Neil Armstrong        2016-11-10  207  		ret = -ENOMEM;
bbbe775ec5b5dac Neil Armstrong        2016-11-10  208  		goto free_drm;
bbbe775ec5b5dac Neil Armstrong        2016-11-10  209  	}
bbbe775ec5b5dac Neil Armstrong        2016-11-10  210  	drm->dev_private = priv;
bbbe775ec5b5dac Neil Armstrong        2016-11-10  211  	priv->drm = drm;
bbbe775ec5b5dac Neil Armstrong        2016-11-10  212  	priv->dev = dev;
d1b5e41e13a7e9b Neil Armstrong        2019-10-21  213  	priv->compat = match->compat;
d1b5e41e13a7e9b Neil Armstrong        2019-10-21  214  	priv->afbcd.ops = match->afbcd_ops;
528a25d040bc212 Julien Masson         2019-08-22  215  
d4cb82aa2e4bc0e Cai Huoqing           2021-08-31  216  	regs = devm_platform_ioremap_resource_byname(pdev, "vpu");
2c18107b9d58972 Christophe JAILLET    2018-03-12  217  	if (IS_ERR(regs)) {
2c18107b9d58972 Christophe JAILLET    2018-03-12  218  		ret = PTR_ERR(regs);
2c18107b9d58972 Christophe JAILLET    2018-03-12  219  		goto free_drm;
2c18107b9d58972 Christophe JAILLET    2018-03-12  220  	}
bbbe775ec5b5dac Neil Armstrong        2016-11-10  221  
bbbe775ec5b5dac Neil Armstrong        2016-11-10  222  	priv->io_base = regs;
bbbe775ec5b5dac Neil Armstrong        2016-11-10  223  
bbbe775ec5b5dac Neil Armstrong        2016-11-10  224  	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "hhi");
01a9e9493fb3f65 Christophe JAILLET    2018-06-11  225  	if (!res) {
01a9e9493fb3f65 Christophe JAILLET    2018-06-11  226  		ret = -EINVAL;
01a9e9493fb3f65 Christophe JAILLET    2018-06-11  227  		goto free_drm;
01a9e9493fb3f65 Christophe JAILLET    2018-06-11  228  	}
bbbe775ec5b5dac Neil Armstrong        2016-11-10  229  	/* Simply ioremap since it may be a shared register zone */
bbbe775ec5b5dac Neil Armstrong        2016-11-10  230  	regs = devm_ioremap(dev, res->start, resource_size(res));
2c18107b9d58972 Christophe JAILLET    2018-03-12  231  	if (!regs) {
2c18107b9d58972 Christophe JAILLET    2018-03-12  232  		ret = -EADDRNOTAVAIL;
2c18107b9d58972 Christophe JAILLET    2018-03-12  233  		goto free_drm;
2c18107b9d58972 Christophe JAILLET    2018-03-12  234  	}
bbbe775ec5b5dac Neil Armstrong        2016-11-10  235  
bbbe775ec5b5dac Neil Armstrong        2016-11-10  236  	priv->hhi = devm_regmap_init_mmio(dev, regs,
bbbe775ec5b5dac Neil Armstrong        2016-11-10  237  					  &meson_regmap_config);
bbbe775ec5b5dac Neil Armstrong        2016-11-10  238  	if (IS_ERR(priv->hhi)) {
bbbe775ec5b5dac Neil Armstrong        2016-11-10  239  		dev_err(&pdev->dev, "Couldn't create the HHI regmap\n");
2c18107b9d58972 Christophe JAILLET    2018-03-12  240  		ret = PTR_ERR(priv->hhi);
2c18107b9d58972 Christophe JAILLET    2018-03-12  241  		goto free_drm;
bbbe775ec5b5dac Neil Armstrong        2016-11-10  242  	}
bbbe775ec5b5dac Neil Armstrong        2016-11-10  243  
66cae477c380d1a Maxime Jourdan        2018-11-05  244  	priv->canvas = meson_canvas_get(dev);
2bf6b5b0e374fcc Maxime Jourdan        2019-03-11  245  	if (IS_ERR(priv->canvas)) {
2bf6b5b0e374fcc Maxime Jourdan        2019-03-11  246  		ret = PTR_ERR(priv->canvas);
2bf6b5b0e374fcc Maxime Jourdan        2019-03-11  247  		goto free_drm;
2bf6b5b0e374fcc Maxime Jourdan        2019-03-11  248  	}
2bf6b5b0e374fcc Maxime Jourdan        2019-03-11  249  
66cae477c380d1a Maxime Jourdan        2018-11-05  250  	ret = meson_canvas_alloc(priv->canvas, &priv->canvas_id_osd1);
66cae477c380d1a Maxime Jourdan        2018-11-05  251  	if (ret)
66cae477c380d1a Maxime Jourdan        2018-11-05  252  		goto free_drm;
f9a2348196d1ab9 Neil Armstrong        2018-11-06  253  	ret = meson_canvas_alloc(priv->canvas, &priv->canvas_id_vd1_0);
a695949b2e9bb6b Yao Zi                2024-07-03  254  	if (ret)
a695949b2e9bb6b Yao Zi                2024-07-03  255  		goto free_canvas_osd1;
f9a2348196d1ab9 Neil Armstrong        2018-11-06  256  	ret = meson_canvas_alloc(priv->canvas, &priv->canvas_id_vd1_1);
a695949b2e9bb6b Yao Zi                2024-07-03  257  	if (ret)
a695949b2e9bb6b Yao Zi                2024-07-03  258  		goto free_canvas_vd1_0;
f9a2348196d1ab9 Neil Armstrong        2018-11-06  259  	ret = meson_canvas_alloc(priv->canvas, &priv->canvas_id_vd1_2);
a695949b2e9bb6b Yao Zi                2024-07-03  260  	if (ret)
a695949b2e9bb6b Yao Zi                2024-07-03  261  		goto free_canvas_vd1_1;
bbbe775ec5b5dac Neil Armstrong        2016-11-10  262  
bbbe775ec5b5dac Neil Armstrong        2016-11-10  263  	priv->vsync_irq = platform_get_irq(pdev, 0);
bbbe775ec5b5dac Neil Armstrong        2016-11-10  264  
e770f6bf18182bc Christophe JAILLET    2018-03-12  265  	ret = drm_vblank_init(drm, 1);
e770f6bf18182bc Christophe JAILLET    2018-03-12  266  	if (ret)
a695949b2e9bb6b Yao Zi                2024-07-03  267  		goto free_canvas_vd1_2;
e770f6bf18182bc Christophe JAILLET    2018-03-12  268  
8976eeee8de05f1 Neil Armstrong        2020-04-28  269  	/* Assign limits per soc revision/package */
8976eeee8de05f1 Neil Armstrong        2020-04-28  270  	for (i = 0 ; i < ARRAY_SIZE(meson_drm_soc_attrs) ; ++i) {
8976eeee8de05f1 Neil Armstrong        2020-04-28  271  		if (soc_device_match(meson_drm_soc_attrs[i].attrs)) {
8976eeee8de05f1 Neil Armstrong        2020-04-28  272  			priv->limits = &meson_drm_soc_attrs[i].limits;
8976eeee8de05f1 Neil Armstrong        2020-04-28  273  			break;
8976eeee8de05f1 Neil Armstrong        2020-04-28  274  		}
8976eeee8de05f1 Neil Armstrong        2020-04-28  275  	}
8976eeee8de05f1 Neil Armstrong        2020-04-28  276  
6848c291a54f8cd Thomas Zimmermann     2021-04-12  277  	/*
6848c291a54f8cd Thomas Zimmermann     2021-04-12  278  	 * Remove early framebuffers (ie. simplefb). The framebuffer can be
6848c291a54f8cd Thomas Zimmermann     2021-04-12  279  	 * located anywhere in RAM
6848c291a54f8cd Thomas Zimmermann     2021-04-12  280  	 */
736db96696b6232 Thomas Zimmermann     2024-09-30  281  	ret = aperture_remove_all_conflicting_devices(meson_driver.name);
6848c291a54f8cd Thomas Zimmermann     2021-04-12  282  	if (ret)
a695949b2e9bb6b Yao Zi                2024-07-03  283  		goto free_canvas_vd1_2;
e3de0aa6c9afdca Maxime Jourdan        2018-12-10  284  
bd9ff7b521a647a Simona Vetter         2020-03-23  285  	ret = drmm_mode_config_init(drm);
bd9ff7b521a647a Simona Vetter         2020-03-23  286  	if (ret)
a695949b2e9bb6b Yao Zi                2024-07-03  287  		goto free_canvas_vd1_2;
a41e82e6c4575b6 Neil Armstrong        2017-04-04  288  	drm->mode_config.max_width = 3840;
a41e82e6c4575b6 Neil Armstrong        2017-04-04  289  	drm->mode_config.max_height = 2160;
a41e82e6c4575b6 Neil Armstrong        2017-04-04  290  	drm->mode_config.funcs = &meson_mode_config_funcs;
ce0210c12433031 Neil Armstrong        2019-01-14  291  	drm->mode_config.helper_private	= &meson_mode_config_helpers;
a41e82e6c4575b6 Neil Armstrong        2017-04-04  292  
a41e82e6c4575b6 Neil Armstrong        2017-04-04  293  	/* Hardware Initialization */
a41e82e6c4575b6 Neil Armstrong        2017-04-04  294  
09762525d6eafb3 Neil Armstrong        2017-12-06  295  	meson_vpu_init(priv);
a41e82e6c4575b6 Neil Armstrong        2017-04-04  296  	meson_venc_init(priv);
a41e82e6c4575b6 Neil Armstrong        2017-04-04  297  	meson_vpp_init(priv);
a41e82e6c4575b6 Neil Armstrong        2017-04-04  298  	meson_viu_init(priv);
d1b5e41e13a7e9b Neil Armstrong        2019-10-21  299  	if (priv->afbcd.ops) {
d1b5e41e13a7e9b Neil Armstrong        2019-10-21  300  		ret = priv->afbcd.ops->init(priv);
d1b5e41e13a7e9b Neil Armstrong        2019-10-21  301  		if (ret)
a695949b2e9bb6b Yao Zi                2024-07-03  302  			goto free_canvas_vd1_2;
d1b5e41e13a7e9b Neil Armstrong        2019-10-21  303  	}
bbbe775ec5b5dac Neil Armstrong        2016-11-10  304  
bbbe775ec5b5dac Neil Armstrong        2016-11-10  305  	/* Encoder Initialization */
bbbe775ec5b5dac Neil Armstrong        2016-11-10  306  
1a9e51bef89af0f Martin Blumenstingl   2024-02-18  307  	ret = meson_encoder_cvbs_probe(priv);
bbbe775ec5b5dac Neil Armstrong        2016-11-10  308  	if (ret)
fa747d75f65d1b1 Martin Blumenstingl   2021-12-31  309  		goto exit_afbcd;
bbbe775ec5b5dac Neil Armstrong        2016-11-10  310  
8604889f83381ca Neil Armstrong        2017-05-29  311  	if (has_components) {
6a044642988b5f8 Neil Armstrong        2023-05-30  312  		ret = component_bind_all(dev, drm);
a41e82e6c4575b6 Neil Armstrong        2017-04-04  313  		if (ret) {
a41e82e6c4575b6 Neil Armstrong        2017-04-04  314  			dev_err(drm->dev, "Couldn't bind all components\n");
6a044642988b5f8 Neil Armstrong        2023-05-30  315  			/* Do not try to unbind */
6a044642988b5f8 Neil Armstrong        2023-05-30  316  			has_components = false;
fa747d75f65d1b1 Martin Blumenstingl   2021-12-31  317  			goto exit_afbcd;
a41e82e6c4575b6 Neil Armstrong        2017-04-04  318  		}
8604889f83381ca Neil Armstrong        2017-05-29  319  	}
bbbe775ec5b5dac Neil Armstrong        2016-11-10  320  
1a9e51bef89af0f Martin Blumenstingl   2024-02-18  321  	ret = meson_encoder_hdmi_probe(priv);
e67f6037ae1be34 Neil Armstrong        2021-10-20  322  	if (ret)
6a044642988b5f8 Neil Armstrong        2023-05-30  323  		goto exit_afbcd;
e67f6037ae1be34 Neil Armstrong        2021-10-20  324  
42dcf15f901c822 Neil Armstrong        2023-05-30  325  	if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) {
1a9e51bef89af0f Martin Blumenstingl   2024-02-18  326  		ret = meson_encoder_dsi_probe(priv);
42dcf15f901c822 Neil Armstrong        2023-05-30  327  		if (ret)
42dcf15f901c822 Neil Armstrong        2023-05-30  328  			goto exit_afbcd;
42dcf15f901c822 Neil Armstrong        2023-05-30  329  	}
42dcf15f901c822 Neil Armstrong        2023-05-30  330  
bbbe775ec5b5dac Neil Armstrong        2016-11-10  331  	ret = meson_plane_create(priv);
bbbe775ec5b5dac Neil Armstrong        2016-11-10  332  	if (ret)
6a044642988b5f8 Neil Armstrong        2023-05-30  333  		goto exit_afbcd;
bbbe775ec5b5dac Neil Armstrong        2016-11-10  334  
f9a2348196d1ab9 Neil Armstrong        2018-11-06  335  	ret = meson_overlay_create(priv);
f9a2348196d1ab9 Neil Armstrong        2018-11-06  336  	if (ret)
6a044642988b5f8 Neil Armstrong        2023-05-30  337  		goto exit_afbcd;
f9a2348196d1ab9 Neil Armstrong        2018-11-06  338  
bbbe775ec5b5dac Neil Armstrong        2016-11-10  339  	ret = meson_crtc_create(priv);
bbbe775ec5b5dac Neil Armstrong        2016-11-10  340  	if (ret)
6a044642988b5f8 Neil Armstrong        2023-05-30  341  		goto exit_afbcd;
bbbe775ec5b5dac Neil Armstrong        2016-11-10  342  
65a969655cb91fa Thomas Zimmermann     2021-07-06  343  	ret = request_irq(priv->vsync_irq, meson_irq, 0, drm->driver->name, drm);
bbbe775ec5b5dac Neil Armstrong        2016-11-10  344  	if (ret)
6a044642988b5f8 Neil Armstrong        2023-05-30  345  		goto exit_afbcd;
bbbe775ec5b5dac Neil Armstrong        2016-11-10  346  
bbbe775ec5b5dac Neil Armstrong        2016-11-10  347  	drm_mode_config_reset(drm);
bbbe775ec5b5dac Neil Armstrong        2016-11-10  348  
bbbe775ec5b5dac Neil Armstrong        2016-11-10  349  	drm_kms_helper_poll_init(drm);
bbbe775ec5b5dac Neil Armstrong        2016-11-10  350  
bbbe775ec5b5dac Neil Armstrong        2016-11-10  351  	platform_set_drvdata(pdev, priv);
bbbe775ec5b5dac Neil Armstrong        2016-11-10  352  
bbbe775ec5b5dac Neil Armstrong        2016-11-10  353  	ret = drm_dev_register(drm, 0);
bbbe775ec5b5dac Neil Armstrong        2016-11-10  354  	if (ret)
e31803f51415af4 Myeonghun Pak         2026-05-25  355  		goto uninstall_poll;
bbbe775ec5b5dac Neil Armstrong        2016-11-10  356  
57a03512c49a2e3 Thomas Zimmermann     2024-09-24  357  	drm_client_setup(drm, NULL);
efbb9df91e03b31 Noralf Trønnes        2018-09-08  358  
bbbe775ec5b5dac Neil Armstrong        2016-11-10  359  	return 0;
bbbe775ec5b5dac Neil Armstrong        2016-11-10  360  
e31803f51415af4 Myeonghun Pak         2026-05-25  361  uninstall_poll:
e31803f51415af4 Myeonghun Pak         2026-05-25  362  	drm_kms_helper_poll_fini(drm);
2d8f92897ad816f Jean-Philippe Brucker 2019-03-22 @363  uninstall_irq:
65a969655cb91fa Thomas Zimmermann     2021-07-06  364  	free_irq(priv->vsync_irq, drm);
fa747d75f65d1b1 Martin Blumenstingl   2021-12-31  365  exit_afbcd:
fa747d75f65d1b1 Martin Blumenstingl   2021-12-31  366  	if (priv->afbcd.ops)
fa747d75f65d1b1 Martin Blumenstingl   2021-12-31  367  		priv->afbcd.ops->exit(priv);
a695949b2e9bb6b Yao Zi                2024-07-03  368  free_canvas_vd1_2:
a695949b2e9bb6b Yao Zi                2024-07-03  369  	meson_canvas_free(priv->canvas, priv->canvas_id_vd1_2);
a695949b2e9bb6b Yao Zi                2024-07-03  370  free_canvas_vd1_1:
a695949b2e9bb6b Yao Zi                2024-07-03  371  	meson_canvas_free(priv->canvas, priv->canvas_id_vd1_1);
a695949b2e9bb6b Yao Zi                2024-07-03  372  free_canvas_vd1_0:
a695949b2e9bb6b Yao Zi                2024-07-03  373  	meson_canvas_free(priv->canvas, priv->canvas_id_vd1_0);
a695949b2e9bb6b Yao Zi                2024-07-03  374  free_canvas_osd1:
a695949b2e9bb6b Yao Zi                2024-07-03  375  	meson_canvas_free(priv->canvas, priv->canvas_id_osd1);
bbbe775ec5b5dac Neil Armstrong        2016-11-10  376  free_drm:
dcacf65139e3def Christophe JAILLET    2018-03-12  377  	drm_dev_put(drm);
bbbe775ec5b5dac Neil Armstrong        2016-11-10  378  
42dcf15f901c822 Neil Armstrong        2023-05-30  379  	meson_encoder_dsi_remove(priv);
6a044642988b5f8 Neil Armstrong        2023-05-30  380  	meson_encoder_hdmi_remove(priv);
6a044642988b5f8 Neil Armstrong        2023-05-30  381  	meson_encoder_cvbs_remove(priv);
6a044642988b5f8 Neil Armstrong        2023-05-30  382  
6a044642988b5f8 Neil Armstrong        2023-05-30  383  	if (has_components)
6a044642988b5f8 Neil Armstrong        2023-05-30  384  		component_unbind_all(dev, drm);
6a044642988b5f8 Neil Armstrong        2023-05-30  385  
bbbe775ec5b5dac Neil Armstrong        2016-11-10  386  	return ret;
bbbe775ec5b5dac Neil Armstrong        2016-11-10  387  }
bbbe775ec5b5dac Neil Armstrong        2016-11-10  388  

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

#5 lore raw
In reply to Myeonghun Pak
kernel test robot noticed the following build warnings:

Hi Myeonghun,

kernel test robot noticed the following build warnings:

[auto build test WARNING on drm-misc/drm-misc-next]
[also build test WARNING on linus/master v7.1-rc5 next-20260526] [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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Myeonghun-Pak/drm-meson-clean-up-KMS-polling-on-register-failure/20260525-000807
base:   https://gitlab.freedesktop.org/drm/misc/kernel.git drm-misc-next
patch link:    https://lore.kernel.org/r/20260524160657.17802-1-mhun512%40gmail.com
patch subject: [PATCH] drm/meson: clean up KMS polling on register failure
config: i386-allmodconfig (https://download.01.org/0day-ci/archive/20260527/[email protected]/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260527/[email protected]/reproduce)

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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

drivers/gpu/drm/meson/meson_drv.c: In function 'meson_drv_bind_master':

>> drivers/gpu/drm/meson/meson_drv.c:363:1: warning: label 'uninstall_irq' defined but not used [-Wunused-label]
     363 | uninstall_irq:
         | ^~~~~~~~~~~~~

vim +/uninstall_irq +363 drivers/gpu/drm/meson/meson_drv.c

8976eeee8de05f Neil Armstrong        2020-04-28  180  
8604889f83381c Neil Armstrong        2017-05-29  181  static int meson_drv_bind_master(struct device *dev, bool has_components)
bbbe775ec5b5da Neil Armstrong        2016-11-10  182  {
a41e82e6c4575b Neil Armstrong        2017-04-04  183  	struct platform_device *pdev = to_platform_device(dev);
d1b5e41e13a7e9 Neil Armstrong        2019-10-21  184  	const struct meson_drm_match_data *match;
bbbe775ec5b5da Neil Armstrong        2016-11-10  185  	struct meson_drm *priv;
bbbe775ec5b5da Neil Armstrong        2016-11-10  186  	struct drm_device *drm;
bbbe775ec5b5da Neil Armstrong        2016-11-10  187  	struct resource *res;
bbbe775ec5b5da Neil Armstrong        2016-11-10  188  	void __iomem *regs;
8976eeee8de05f Neil Armstrong        2020-04-28  189  	int ret, i;
bbbe775ec5b5da Neil Armstrong        2016-11-10  190  
bbbe775ec5b5da Neil Armstrong        2016-11-10  191  	/* Checks if an output connector is available */
bbbe775ec5b5da Neil Armstrong        2016-11-10  192  	if (!meson_vpu_has_available_connectors(dev)) {
bbbe775ec5b5da Neil Armstrong        2016-11-10  193  		dev_err(dev, "No output connector available\n");
bbbe775ec5b5da Neil Armstrong        2016-11-10  194  		return -ENODEV;
bbbe775ec5b5da Neil Armstrong        2016-11-10  195  	}
bbbe775ec5b5da Neil Armstrong        2016-11-10  196  
d1b5e41e13a7e9 Neil Armstrong        2019-10-21  197  	match = of_device_get_match_data(dev);
d1b5e41e13a7e9 Neil Armstrong        2019-10-21  198  	if (!match)
d1b5e41e13a7e9 Neil Armstrong        2019-10-21  199  		return -ENODEV;
d1b5e41e13a7e9 Neil Armstrong        2019-10-21  200  
bbbe775ec5b5da Neil Armstrong        2016-11-10  201  	drm = drm_dev_alloc(&meson_driver, dev);
bbbe775ec5b5da Neil Armstrong        2016-11-10  202  	if (IS_ERR(drm))
bbbe775ec5b5da Neil Armstrong        2016-11-10  203  		return PTR_ERR(drm);
bbbe775ec5b5da Neil Armstrong        2016-11-10  204  
bbbe775ec5b5da Neil Armstrong        2016-11-10  205  	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
bbbe775ec5b5da Neil Armstrong        2016-11-10  206  	if (!priv) {
bbbe775ec5b5da Neil Armstrong        2016-11-10  207  		ret = -ENOMEM;
bbbe775ec5b5da Neil Armstrong        2016-11-10  208  		goto free_drm;
bbbe775ec5b5da Neil Armstrong        2016-11-10  209  	}
bbbe775ec5b5da Neil Armstrong        2016-11-10  210  	drm->dev_private = priv;
bbbe775ec5b5da Neil Armstrong        2016-11-10  211  	priv->drm = drm;
bbbe775ec5b5da Neil Armstrong        2016-11-10  212  	priv->dev = dev;
d1b5e41e13a7e9 Neil Armstrong        2019-10-21  213  	priv->compat = match->compat;
d1b5e41e13a7e9 Neil Armstrong        2019-10-21  214  	priv->afbcd.ops = match->afbcd_ops;
528a25d040bc21 Julien Masson         2019-08-22  215  
d4cb82aa2e4bc0 Cai Huoqing           2021-08-31  216  	regs = devm_platform_ioremap_resource_byname(pdev, "vpu");
2c18107b9d5897 Christophe JAILLET    2018-03-12  217  	if (IS_ERR(regs)) {
2c18107b9d5897 Christophe JAILLET    2018-03-12  218  		ret = PTR_ERR(regs);
2c18107b9d5897 Christophe JAILLET    2018-03-12  219  		goto free_drm;
2c18107b9d5897 Christophe JAILLET    2018-03-12  220  	}
bbbe775ec5b5da Neil Armstrong        2016-11-10  221  
bbbe775ec5b5da Neil Armstrong        2016-11-10  222  	priv->io_base = regs;
bbbe775ec5b5da Neil Armstrong        2016-11-10  223  
bbbe775ec5b5da Neil Armstrong        2016-11-10  224  	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "hhi");
01a9e9493fb3f6 Christophe JAILLET    2018-06-11  225  	if (!res) {
01a9e9493fb3f6 Christophe JAILLET    2018-06-11  226  		ret = -EINVAL;
01a9e9493fb3f6 Christophe JAILLET    2018-06-11  227  		goto free_drm;
01a9e9493fb3f6 Christophe JAILLET    2018-06-11  228  	}
bbbe775ec5b5da Neil Armstrong        2016-11-10  229  	/* Simply ioremap since it may be a shared register zone */
bbbe775ec5b5da Neil Armstrong        2016-11-10  230  	regs = devm_ioremap(dev, res->start, resource_size(res));
2c18107b9d5897 Christophe JAILLET    2018-03-12  231  	if (!regs) {
2c18107b9d5897 Christophe JAILLET    2018-03-12  232  		ret = -EADDRNOTAVAIL;
2c18107b9d5897 Christophe JAILLET    2018-03-12  233  		goto free_drm;
2c18107b9d5897 Christophe JAILLET    2018-03-12  234  	}
bbbe775ec5b5da Neil Armstrong        2016-11-10  235  
bbbe775ec5b5da Neil Armstrong        2016-11-10  236  	priv->hhi = devm_regmap_init_mmio(dev, regs,
bbbe775ec5b5da Neil Armstrong        2016-11-10  237  					  &meson_regmap_config);
bbbe775ec5b5da Neil Armstrong        2016-11-10  238  	if (IS_ERR(priv->hhi)) {
bbbe775ec5b5da Neil Armstrong        2016-11-10  239  		dev_err(&pdev->dev, "Couldn't create the HHI regmap\n");
2c18107b9d5897 Christophe JAILLET    2018-03-12  240  		ret = PTR_ERR(priv->hhi);
2c18107b9d5897 Christophe JAILLET    2018-03-12  241  		goto free_drm;
bbbe775ec5b5da Neil Armstrong        2016-11-10  242  	}
bbbe775ec5b5da Neil Armstrong        2016-11-10  243  
66cae477c380d1 Maxime Jourdan        2018-11-05  244  	priv->canvas = meson_canvas_get(dev);
2bf6b5b0e374fc Maxime Jourdan        2019-03-11  245  	if (IS_ERR(priv->canvas)) {
2bf6b5b0e374fc Maxime Jourdan        2019-03-11  246  		ret = PTR_ERR(priv->canvas);
2bf6b5b0e374fc Maxime Jourdan        2019-03-11  247  		goto free_drm;
2bf6b5b0e374fc Maxime Jourdan        2019-03-11  248  	}
2bf6b5b0e374fc Maxime Jourdan        2019-03-11  249  
66cae477c380d1 Maxime Jourdan        2018-11-05  250  	ret = meson_canvas_alloc(priv->canvas, &priv->canvas_id_osd1);
66cae477c380d1 Maxime Jourdan        2018-11-05  251  	if (ret)
66cae477c380d1 Maxime Jourdan        2018-11-05  252  		goto free_drm;
f9a2348196d1ab Neil Armstrong        2018-11-06  253  	ret = meson_canvas_alloc(priv->canvas, &priv->canvas_id_vd1_0);
a695949b2e9bb6 Yao Zi                2024-07-03  254  	if (ret)
a695949b2e9bb6 Yao Zi                2024-07-03  255  		goto free_canvas_osd1;
f9a2348196d1ab Neil Armstrong        2018-11-06  256  	ret = meson_canvas_alloc(priv->canvas, &priv->canvas_id_vd1_1);
a695949b2e9bb6 Yao Zi                2024-07-03  257  	if (ret)
a695949b2e9bb6 Yao Zi                2024-07-03  258  		goto free_canvas_vd1_0;
f9a2348196d1ab Neil Armstrong        2018-11-06  259  	ret = meson_canvas_alloc(priv->canvas, &priv->canvas_id_vd1_2);
a695949b2e9bb6 Yao Zi                2024-07-03  260  	if (ret)
a695949b2e9bb6 Yao Zi                2024-07-03  261  		goto free_canvas_vd1_1;
bbbe775ec5b5da Neil Armstrong        2016-11-10  262  
bbbe775ec5b5da Neil Armstrong        2016-11-10  263  	priv->vsync_irq = platform_get_irq(pdev, 0);
bbbe775ec5b5da Neil Armstrong        2016-11-10  264  
e770f6bf18182b Christophe JAILLET    2018-03-12  265  	ret = drm_vblank_init(drm, 1);
e770f6bf18182b Christophe JAILLET    2018-03-12  266  	if (ret)
a695949b2e9bb6 Yao Zi                2024-07-03  267  		goto free_canvas_vd1_2;
e770f6bf18182b Christophe JAILLET    2018-03-12  268  
8976eeee8de05f Neil Armstrong        2020-04-28  269  	/* Assign limits per soc revision/package */
8976eeee8de05f Neil Armstrong        2020-04-28  270  	for (i = 0 ; i < ARRAY_SIZE(meson_drm_soc_attrs) ; ++i) {
8976eeee8de05f Neil Armstrong        2020-04-28  271  		if (soc_device_match(meson_drm_soc_attrs[i].attrs)) {
8976eeee8de05f Neil Armstrong        2020-04-28  272  			priv->limits = &meson_drm_soc_attrs[i].limits;
8976eeee8de05f Neil Armstrong        2020-04-28  273  			break;
8976eeee8de05f Neil Armstrong        2020-04-28  274  		}
8976eeee8de05f Neil Armstrong        2020-04-28  275  	}
8976eeee8de05f Neil Armstrong        2020-04-28  276  
6848c291a54f8c Thomas Zimmermann     2021-04-12  277  	/*
6848c291a54f8c Thomas Zimmermann     2021-04-12  278  	 * Remove early framebuffers (ie. simplefb). The framebuffer can be
6848c291a54f8c Thomas Zimmermann     2021-04-12  279  	 * located anywhere in RAM
6848c291a54f8c Thomas Zimmermann     2021-04-12  280  	 */
736db96696b623 Thomas Zimmermann     2024-09-30  281  	ret = aperture_remove_all_conflicting_devices(meson_driver.name);
6848c291a54f8c Thomas Zimmermann     2021-04-12  282  	if (ret)
a695949b2e9bb6 Yao Zi                2024-07-03  283  		goto free_canvas_vd1_2;
e3de0aa6c9afdc Maxime Jourdan        2018-12-10  284  
bd9ff7b521a647 Simona Vetter         2020-03-23  285  	ret = drmm_mode_config_init(drm);
bd9ff7b521a647 Simona Vetter         2020-03-23  286  	if (ret)
a695949b2e9bb6 Yao Zi                2024-07-03  287  		goto free_canvas_vd1_2;
a41e82e6c4575b Neil Armstrong        2017-04-04  288  	drm->mode_config.max_width = 3840;
a41e82e6c4575b Neil Armstrong        2017-04-04  289  	drm->mode_config.max_height = 2160;
a41e82e6c4575b Neil Armstrong        2017-04-04  290  	drm->mode_config.funcs = &meson_mode_config_funcs;
ce0210c1243303 Neil Armstrong        2019-01-14  291  	drm->mode_config.helper_private	= &meson_mode_config_helpers;
a41e82e6c4575b Neil Armstrong        2017-04-04  292  
a41e82e6c4575b Neil Armstrong        2017-04-04  293  	/* Hardware Initialization */
a41e82e6c4575b Neil Armstrong        2017-04-04  294  
09762525d6eafb Neil Armstrong        2017-12-06  295  	meson_vpu_init(priv);
a41e82e6c4575b Neil Armstrong        2017-04-04  296  	meson_venc_init(priv);
a41e82e6c4575b Neil Armstrong        2017-04-04  297  	meson_vpp_init(priv);
a41e82e6c4575b Neil Armstrong        2017-04-04  298  	meson_viu_init(priv);
d1b5e41e13a7e9 Neil Armstrong        2019-10-21  299  	if (priv->afbcd.ops) {
d1b5e41e13a7e9 Neil Armstrong        2019-10-21  300  		ret = priv->afbcd.ops->init(priv);
d1b5e41e13a7e9 Neil Armstrong        2019-10-21  301  		if (ret)
a695949b2e9bb6 Yao Zi                2024-07-03  302  			goto free_canvas_vd1_2;
d1b5e41e13a7e9 Neil Armstrong        2019-10-21  303  	}
bbbe775ec5b5da Neil Armstrong        2016-11-10  304  
bbbe775ec5b5da Neil Armstrong        2016-11-10  305  	/* Encoder Initialization */
bbbe775ec5b5da Neil Armstrong        2016-11-10  306  
1a9e51bef89af0 Martin Blumenstingl   2024-02-18  307  	ret = meson_encoder_cvbs_probe(priv);
bbbe775ec5b5da Neil Armstrong        2016-11-10  308  	if (ret)
fa747d75f65d1b Martin Blumenstingl   2021-12-31  309  		goto exit_afbcd;
bbbe775ec5b5da Neil Armstrong        2016-11-10  310  
8604889f83381c Neil Armstrong        2017-05-29  311  	if (has_components) {
6a044642988b5f Neil Armstrong        2023-05-30  312  		ret = component_bind_all(dev, drm);
a41e82e6c4575b Neil Armstrong        2017-04-04  313  		if (ret) {
a41e82e6c4575b Neil Armstrong        2017-04-04  314  			dev_err(drm->dev, "Couldn't bind all components\n");
6a044642988b5f Neil Armstrong        2023-05-30  315  			/* Do not try to unbind */
6a044642988b5f Neil Armstrong        2023-05-30  316  			has_components = false;
fa747d75f65d1b Martin Blumenstingl   2021-12-31  317  			goto exit_afbcd;
a41e82e6c4575b Neil Armstrong        2017-04-04  318  		}
8604889f83381c Neil Armstrong        2017-05-29  319  	}
bbbe775ec5b5da Neil Armstrong        2016-11-10  320  
1a9e51bef89af0 Martin Blumenstingl   2024-02-18  321  	ret = meson_encoder_hdmi_probe(priv);
e67f6037ae1be3 Neil Armstrong        2021-10-20  322  	if (ret)
6a044642988b5f Neil Armstrong        2023-05-30  323  		goto exit_afbcd;
e67f6037ae1be3 Neil Armstrong        2021-10-20  324  
42dcf15f901c82 Neil Armstrong        2023-05-30  325  	if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) {
1a9e51bef89af0 Martin Blumenstingl   2024-02-18  326  		ret = meson_encoder_dsi_probe(priv);
42dcf15f901c82 Neil Armstrong        2023-05-30  327  		if (ret)
42dcf15f901c82 Neil Armstrong        2023-05-30  328  			goto exit_afbcd;
42dcf15f901c82 Neil Armstrong        2023-05-30  329  	}
42dcf15f901c82 Neil Armstrong        2023-05-30  330  
bbbe775ec5b5da Neil Armstrong        2016-11-10  331  	ret = meson_plane_create(priv);
bbbe775ec5b5da Neil Armstrong        2016-11-10  332  	if (ret)
6a044642988b5f Neil Armstrong        2023-05-30  333  		goto exit_afbcd;
bbbe775ec5b5da Neil Armstrong        2016-11-10  334  
f9a2348196d1ab Neil Armstrong        2018-11-06  335  	ret = meson_overlay_create(priv);
f9a2348196d1ab Neil Armstrong        2018-11-06  336  	if (ret)
6a044642988b5f Neil Armstrong        2023-05-30  337  		goto exit_afbcd;
f9a2348196d1ab Neil Armstrong        2018-11-06  338  
bbbe775ec5b5da Neil Armstrong        2016-11-10  339  	ret = meson_crtc_create(priv);
bbbe775ec5b5da Neil Armstrong        2016-11-10  340  	if (ret)
6a044642988b5f Neil Armstrong        2023-05-30  341  		goto exit_afbcd;
bbbe775ec5b5da Neil Armstrong        2016-11-10  342  
65a969655cb91f Thomas Zimmermann     2021-07-06  343  	ret = request_irq(priv->vsync_irq, meson_irq, 0, drm->driver->name, drm);
bbbe775ec5b5da Neil Armstrong        2016-11-10  344  	if (ret)
6a044642988b5f Neil Armstrong        2023-05-30  345  		goto exit_afbcd;
bbbe775ec5b5da Neil Armstrong        2016-11-10  346  
bbbe775ec5b5da Neil Armstrong        2016-11-10  347  	drm_mode_config_reset(drm);
bbbe775ec5b5da Neil Armstrong        2016-11-10  348  
bbbe775ec5b5da Neil Armstrong        2016-11-10  349  	drm_kms_helper_poll_init(drm);
bbbe775ec5b5da Neil Armstrong        2016-11-10  350  
bbbe775ec5b5da Neil Armstrong        2016-11-10  351  	platform_set_drvdata(pdev, priv);
bbbe775ec5b5da Neil Armstrong        2016-11-10  352  
bbbe775ec5b5da Neil Armstrong        2016-11-10  353  	ret = drm_dev_register(drm, 0);
bbbe775ec5b5da Neil Armstrong        2016-11-10  354  	if (ret)
e31803f51415af Myeonghun Pak         2026-05-25  355  		goto uninstall_poll;
bbbe775ec5b5da Neil Armstrong        2016-11-10  356  
57a03512c49a2e Thomas Zimmermann     2024-09-24  357  	drm_client_setup(drm, NULL);
efbb9df91e03b3 Noralf Trønnes        2018-09-08  358  
bbbe775ec5b5da Neil Armstrong        2016-11-10  359  	return 0;
bbbe775ec5b5da Neil Armstrong        2016-11-10  360  
e31803f51415af Myeonghun Pak         2026-05-25  361  uninstall_poll:
e31803f51415af Myeonghun Pak         2026-05-25  362  	drm_kms_helper_poll_fini(drm);
2d8f92897ad816 Jean-Philippe Brucker 2019-03-22 @363  uninstall_irq:
65a969655cb91f Thomas Zimmermann     2021-07-06  364  	free_irq(priv->vsync_irq, drm);
fa747d75f65d1b Martin Blumenstingl   2021-12-31  365  exit_afbcd:
fa747d75f65d1b Martin Blumenstingl   2021-12-31  366  	if (priv->afbcd.ops)
fa747d75f65d1b Martin Blumenstingl   2021-12-31  367  		priv->afbcd.ops->exit(priv);
a695949b2e9bb6 Yao Zi                2024-07-03  368  free_canvas_vd1_2:
a695949b2e9bb6 Yao Zi                2024-07-03  369  	meson_canvas_free(priv->canvas, priv->canvas_id_vd1_2);
a695949b2e9bb6 Yao Zi                2024-07-03  370  free_canvas_vd1_1:
a695949b2e9bb6 Yao Zi                2024-07-03  371  	meson_canvas_free(priv->canvas, priv->canvas_id_vd1_1);
a695949b2e9bb6 Yao Zi                2024-07-03  372  free_canvas_vd1_0:
a695949b2e9bb6 Yao Zi                2024-07-03  373  	meson_canvas_free(priv->canvas, priv->canvas_id_vd1_0);
a695949b2e9bb6 Yao Zi                2024-07-03  374  free_canvas_osd1:
a695949b2e9bb6 Yao Zi                2024-07-03  375  	meson_canvas_free(priv->canvas, priv->canvas_id_osd1);
bbbe775ec5b5da Neil Armstrong        2016-11-10  376  free_drm:
dcacf65139e3de Christophe JAILLET    2018-03-12  377  	drm_dev_put(drm);
bbbe775ec5b5da Neil Armstrong        2016-11-10  378  
42dcf15f901c82 Neil Armstrong        2023-05-30  379  	meson_encoder_dsi_remove(priv);
6a044642988b5f Neil Armstrong        2023-05-30  380  	meson_encoder_hdmi_remove(priv);
6a044642988b5f Neil Armstrong        2023-05-30  381  	meson_encoder_cvbs_remove(priv);
6a044642988b5f Neil Armstrong        2023-05-30  382  
6a044642988b5f Neil Armstrong        2023-05-30  383  	if (has_components)
6a044642988b5f Neil Armstrong        2023-05-30  384  		component_unbind_all(dev, drm);
6a044642988b5f Neil Armstrong        2023-05-30  385  
bbbe775ec5b5da Neil Armstrong        2016-11-10  386  	return ret;
bbbe775ec5b5da Neil Armstrong        2016-11-10  387  }
bbbe775ec5b5da Neil Armstrong        2016-11-10  388  

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

#6 lore raw

PATCH v2 1/1 drm/meson: clean up KMS polling on register failure

In reply to Myeonghun Pak

meson_drv_bind_master() starts the KMS polling helper before registering the DRM device. If drm_dev_register() fails, probe unwinds the IRQ and DRM device without stopping the polling helper.

Call drm_kms_helper_poll_fini() on that failure path before freeing the IRQ.

This issue was identified during our ongoing static-analysis research while reviewing kernel code.

Fixes bbbe775ec5b5 ("drm: Add support for Amlogic Meson Graphic Controller")

---
Changes in v2:
- Avoid the unused uninstall_irq label reported by the kernel test robot.
- Link to v1: https://lore.kernel.org/r/[email protected]

 drivers/gpu/drm/meson/meson_drv.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/meson/meson_drv.c +3 -1
index 49ff9f1f16..bcc36f2cdc 100644
@@ -351,8 +351,10 @@ static int meson_drv_bind_master(struct device *dev, bool has_components)
 	platform_set_drvdata(pdev, priv);
 
 	ret = drm_dev_register(drm, 0);
-	if (ret)
+	if (ret) {
+		drm_kms_helper_poll_fini(drm);
 		goto uninstall_irq;
+	}
 
 	drm_client_setup(drm, NULL);
 
Signature · 1 line
2.47.1
#7 lore raw
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:

Pre-existing issues:
- [High] NULL pointer dereference in error path if devm_kzalloc() fails to allocate priv
- [High] Use-After-Free due to DRM objects allocated with devm_kzalloc instead of drmm_kzalloc
- [High] Kernel panic/Resource leak on driver unload if initialized without component framework
- [High] Use-After-Free of devm-allocated bridges due to leakage in the global bridge_list
- [High] Use-After-Free due to drm_dev_put() dropping the DRM device before component_unbind_all() accesses it --

--- Patch [1]: [PATCH v2] drm/meson: clean up KMS polling on register failure --- commit 86a9a25dd06d99107bc269bc3d6752c0df753219
Author: Myeonghun Pak <[email protected]>

drm/meson: clean up KMS polling on register failure

This commit ensures that drm_kms_helper_poll_fini() is called when drm_dev_register() fails in meson_drv_bind_master(). This stops the KMS polling helper before the probe error path unwinds the IRQ and frees the DRM device.

Quoted 6 lines
drivers/gpu/drm/meson/meson_drv.c +0 -0
index 49ff9f1f16d32..bcc36f2cdc9a9 100644
@@ -351,8 +351,10 @@ static int meson_drv_bind_master(struct device *dev, bool has_components)
 	platform_set_drvdata(pdev, priv);

drivers/gpu/drm/meson/meson_drv.c static int meson_drv_bind_master(struct device *dev, bool has_components) · line 360

Quoted 10 lines
drivers/gpu/drm/meson/meson_drv.c +3 -1
 
 	ret = drm_dev_register(drm, 0);
-	if (ret)
+	if (ret) {
+		drm_kms_helper_poll_fini(drm);
 		goto uninstall_irq;
+	}
 
 	drm_client_setup(drm, NULL);
 

[Severity: High]
This isn't a bug introduced by this patch, but can this error path in meson_drv_bind_master() trigger a NULL pointer dereference?

If devm_kzalloc() fails to allocate memory for priv, it jumps to free_drm:

drivers/gpu/drm/meson/meson_drv.c:meson_drv_bind_master() {
	...
	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
	if (!priv) {
		ret = -ENOMEM;
		goto free_drm;
	}
	...
}

At the free_drm label, meson_encoder_dsi_remove(priv) is called, which immediately dereferences the NULL priv pointer:

drivers/gpu/drm/meson/meson_encoder_dsi.c:meson_encoder_dsi_remove() {
	...
	if (priv->encoders[MESON_ENC_DSI]) {
	...
}

[Severity: High]
This is a pre-existing issue, but does using devm_kzalloc() for the DRM plane risk a use-after-free?

drivers/gpu/drm/meson/meson_plane.c:meson_plane_create() {
	...
	meson_plane = devm_kzalloc(priv->drm->dev, sizeof(*meson_plane),
				   GFP_KERNEL);
	...
}

Because devm_kzalloc() ties the memory lifetime to the platform device, if the device is unbound (e.g., via sysfs) while userspace still holds a DRM file descriptor open, devres frees the plane structure. Later, when the file descriptor is closed, the DRM core cleans up and accesses this already-freed structure to invoke its .destroy hook.

[Severity: High]
This isn't a bug introduced by this patch, but does the driver unload sequence leak resources if initialized without the component framework?

drivers/gpu/drm/meson/meson_drv.c:meson_drv_probe() {
	...
	if (count && !match)
		return meson_drv_bind_master(&pdev->dev, false);
	...
}

If no matching components are found, it bypasses the component framework. However, during driver teardown, it only cleans up via the component framework:

drivers/gpu/drm/meson/meson_drv.c:meson_drv_remove() {
	...
	component_master_del(&pdev->dev, &meson_drv_master_ops);
}

Because it was never added as a component master, meson_drv_unbind() is never called, leaving the DRM device registered and memory allocated while the module is unloaded.

[Severity: High]
This is a pre-existing issue, but if drm_simple_encoder_init() fails, does this leak the bridge in the global bridge_list?

drivers/gpu/drm/meson/meson_encoder_dsi.c:meson_encoder_dsi_probe() {
	...
	drm_bridge_add(&meson_encoder_dsi->bridge);

	meson_encoder_dsi->priv = priv;

	/* Encoder */
	ret = drm_simple_encoder_init(priv->drm, &meson_encoder_dsi->encoder,
				      DRM_MODE_ENCODER_DSI);
	if (ret)
		return dev_err_probe(priv->dev, ret,
				     "Failed to init DSI encoder\n");
	...
}

If drm_simple_encoder_init() fails, the function returns an error without calling drm_bridge_remove(). Because the bridge is a devm allocation, its memory is freed on probe failure, but a dangling pointer remains in the global bridge_list.

[Severity: High]
This isn't a bug introduced by this patch, but can the teardown order cause a use-after-free when cleaning up components?

drivers/gpu/drm/meson/meson_drv.c:meson_drv_bind_master() {
	...
free_drm:
	drm_dev_put(drm);

	meson_encoder_dsi_remove(priv);
	meson_encoder_hdmi_remove(priv);
	meson_encoder_cvbs_remove(priv);

	if (has_components)
		component_unbind_all(dev, drm);
	...
}

The call to drm_dev_put(drm) drops the final reference and frees the drm device. Then component_unbind_all(dev, drm) passes this newly freed drm pointer to the unbind callbacks, which may attempt to access it. This same sequence also exists in meson_drv_unbind().

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1