Two memory leak fixes in drm_client_modeset.c
Subsystems (3)
cover Two memory leak fixes in drm_client_modeset.c
Jocelyn Falempe (2):
drm/client: Fix memory leak in drm_client_target_cloned drm/client: Fix memory leak in drm_client_modeset_probe
drivers/gpu/drm/drm_client_modeset.c | 8 ++++++++ 1 file changed, 8 insertions(+)
base-commit: 2f98e686ef59b5d19af5847d755798e2031bee3a
Signature · 1 line
2.41.0
PATCH 1/2 drm/client: Fix memory leak in drm_client_target_cloned
dmt_mode is allocated and never freed in this function.
It was found with the ast driver, but most drivers using generic fbdev setup are probably affected.
This fixes the following kmemleak report:
backtrace:
[<00000000b391296d>] drm_mode_duplicate+0x45/0x220 [drm]
[<00000000e45bb5b3>] drm_client_target_cloned.constprop.0+0x27b/0x480 [drm]
[<00000000ed2d3a37>] drm_client_modeset_probe+0x6bd/0xf50 [drm]
[<0000000010e5cc9d>] __drm_fb_helper_initial_config_and_unlock+0xb4/0x2c0 [drm_kms_helper]
[<00000000909f82ca>] drm_fbdev_client_hotplug+0x2bc/0x4d0 [drm_kms_helper]
[<00000000063a69aa>] drm_client_register+0x169/0x240 [drm]
[<00000000a8c61525>] ast_pci_probe+0x142/0x190 [ast]
[<00000000987f19bb>] local_pci_probe+0xdc/0x180
[<000000004fca231b>] work_for_cpu_fn+0x4e/0xa0
[<0000000000b85301>] process_one_work+0x8b7/0x1540
[<000000003375b17c>] worker_thread+0x70a/0xed0
[<00000000b0d43cd9>] kthread+0x29f/0x340
[<000000008d770833>] ret_from_fork+0x1f/0x30unreferenced object 0xff11000333089a00 (size 128):
--- drivers/gpu/drm/drm_client_modeset.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/gpu/drm/drm_client_modeset.c +5 -0
@@ -311,6 +311,9 @@ static bool drm_client_target_cloned(struct drm_device *dev, can_clone = true; dmt_mode =drm_mode_find_dmt (dev,1024 ,768 ,60 , false); +if (!dmt_mode) + goto fail; +for (i =0 ; i < connector_count; i++) {if (!enabled[i])continue ;
@@ -326,11 +329,13 @@ static bool drm_client_target_cloned(struct drm_device *dev,if (!modes[i]) can_clone = false; } +kfree (dmt_mode);if (can_clone) {DRM_DEBUG_KMS ("can clone using 1024x768\n" );return true; } +fail:DRM_INFO ("kms: can't enable cloning when we probably wanted to.\n" );return false; }
Signature · 1 line
2.41.0
Re: [PATCH 1/2] drm/client: Fix memory leak in drm_client_target_cloned
Jocelyn Falempe <[email protected]> writes:
Hello Jocelyn,
Quoted 19 lines
dmt_modeis allocated and never freed in this function.
It was found with the ast driver, but most drivers using generic fbdev setup are probably affected.This fixes the following kmemleak report:
backtrace:[<00000000b391296d>] drm_mode_duplicate+0x45/0x220 [drm] [<00000000e45bb5b3>] drm_client_target_cloned.constprop.0+0x27b/0x480 [drm] [<00000000ed2d3a37>] drm_client_modeset_probe+0x6bd/0xf50 [drm] [<0000000010e5cc9d>] __drm_fb_helper_initial_config_and_unlock+0xb4/0x2c0 [drm_kms_helper] [<00000000909f82ca>] drm_fbdev_client_hotplug+0x2bc/0x4d0 [drm_kms_helper] [<00000000063a69aa>] drm_client_register+0x169/0x240 [drm] [<00000000a8c61525>] ast_pci_probe+0x142/0x190 [ast] [<00000000987f19bb>] local_pci_probe+0xdc/0x180 [<000000004fca231b>] work_for_cpu_fn+0x4e/0xa0 [<0000000000b85301>] process_one_work+0x8b7/0x1540 [<000000003375b17c>] worker_thread+0x70a/0xed0 [<00000000b0d43cd9>] kthread+0x29f/0x340 [<000000008d770833>] ret_from_fork+0x1f/0x30
Quoted 7 lines
unreferenced object
0xff11000333089a00(size 128):cc <[email protected]>Fixes 1d42bbc8f7f9 ("drm/fbdev: fix cloning on fbcon")Reported-by Zhang Yi <[email protected]>Signed-off-by Jocelyn Falempe <[email protected]>---
The patch looks good to me.
Signature · 5 lines
Best regards, Javier Martinez Canillas Core Platforms Red Hat
Re: [PATCH 1/2] drm/client: Fix memory leak in drm_client_target_cloned
In reply to Jocelyn FalempeAm 11.07.23 um 11:20 schrieb Jocelyn Falempe:
Quoted 19 lines
dmt_modeis allocated and never freed in this function.
It was found with the ast driver, but most drivers using generic fbdev setup are probably affected.This fixes the following kmemleak report:
backtrace: [<00000000b391296d>] drm_mode_duplicate+0x45/0x220 [drm] [<00000000e45bb5b3>] drm_client_target_cloned.constprop.0+0x27b/0x480 [drm] [<00000000ed2d3a37>] drm_client_modeset_probe+0x6bd/0xf50 [drm] [<0000000010e5cc9d>] __drm_fb_helper_initial_config_and_unlock+0xb4/0x2c0 [drm_kms_helper] [<00000000909f82ca>] drm_fbdev_client_hotplug+0x2bc/0x4d0 [drm_kms_helper] [<00000000063a69aa>] drm_client_register+0x169/0x240 [drm] [<00000000a8c61525>] ast_pci_probe+0x142/0x190 [ast] [<00000000987f19bb>] local_pci_probe+0xdc/0x180 [<000000004fca231b>] work_for_cpu_fn+0x4e/0xa0 [<0000000000b85301>] process_one_work+0x8b7/0x1540 [<000000003375b17c>] worker_thread+0x70a/0xed0 [<00000000b0d43cd9>] kthread+0x29f/0x340 [<000000008d770833>] ret_from_fork+0x1f/0x30
Quoted 6 lines
unreferenced object
0xff11000333089a00(size 128):cc <[email protected]>Fixes 1d42bbc8f7f9 ("drm/fbdev: fix cloning on fbcon")Reported-by Zhang Yi <[email protected]>Signed-off-by Jocelyn Falempe <[email protected]>
Quoted 32 lines
--- drivers/gpu/drm/drm_client_modeset.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/gpu/drm/drm_client_modeset.c +5
-0@@ -311,6 +311,9 @@ static bool drm_client_target_cloned(struct drm_device *dev, can_clone = true; dmt_mode =drm_mode_find_dmt (dev,1024 ,768 ,60 , false); +if (!dmt_mode) + goto fail; +for (i =0 ; i < connector_count; i++) {if (!enabled[i])continue ;@@ -326,11 +329,13 @@ static bool drm_client_target_cloned(struct drm_device *dev,if (!modes[i]) can_clone = false; } +kfree (dmt_mode);if (can_clone) {DRM_DEBUG_KMS ("can clone using 1024x768\n" );return true; } +fail:DRM_INFO ("kms: can't enable cloning when we probably wanted to.\n" );return false; }
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstrasse 146, 90461 Nuernberg, Germany GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman HRB 36809 (AG Nuernberg)
PATCH 2/2 drm/client: Fix memory leak in drm_client_modeset_probe
In reply to Jocelyn FalempeWhen a new mode is set to modeset->mode, the previous mode should be freed. This fixes the following kmemleak report:
drm_mode_duplicate+0x45/0x220 [drm] drm_client_modeset_probe+0x944/0xf50 [drm] __drm_fb_helper_initial_config_and_unlock+0xb4/0x2c0 [drm_kms_helper] drm_fbdev_client_hotplug+0x2bc/0x4d0 [drm_kms_helper] drm_client_register+0x169/0x240 [drm] ast_pci_probe+0x142/0x190 [ast] local_pci_probe+0xdc/0x180 work_for_cpu_fn+0x4e/0xa0 process_one_work+0x8b7/0x1540 worker_thread+0x70a/0xed0 kthread+0x29f/0x340 ret_from_fork+0x1f/0x30
--- drivers/gpu/drm/drm_client_modeset.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpu/drm/drm_client_modeset.c +3 -0
@@ -867,6 +867,9 @@ int drm_client_modeset_probe(struct drm_client_dev *client, unsigned int width,break ; } +if (modeset->mode) +kfree (modeset->mode); + modeset->mode =drm_mode_duplicate (dev, mode);drm_connector_get (connector); modeset->connectors[modeset->num_connectors++] = connector;
Signature · 1 line
2.41.0
Re: [PATCH 2/2] drm/client: Fix memory leak in drm_client_modeset_probe
Quoted 16 lines · Jocelyn Falempe
When a new mode is set to
modeset->mode, the previous mode should be freed. This fixes the following kmemleak report:drm_mode_duplicate+0x45/0x220 [drm] drm_client_modeset_probe+0x944/0xf50 [drm] __drm_fb_helper_initial_config_and_unlock+0xb4/0x2c0 [drm_kms_helper] drm_fbdev_client_hotplug+0x2bc/0x4d0 [drm_kms_helper] drm_client_register+0x169/0x240 [drm] ast_pci_probe+0x142/0x190 [ast] local_pci_probe+0xdc/0x180 work_for_cpu_fn+0x4e/0xa0 process_one_work+0x8b7/0x1540 worker_thread+0x70a/0xed0 kthread+0x29f/0x340 ret_from_fork+0x1f/0x30
Quoted 4 lines
cc <[email protected]>Reported-by Zhang Yi <[email protected]>Signed-off-by Jocelyn Falempe <[email protected]>---
Signature · 5 lines
Best regards, Javier Martinez Canillas Core Platforms Red Hat
Re: [PATCH 2/2] drm/client: Fix memory leak in drm_client_modeset_probe
In reply to Jocelyn FalempeAm 11.07.23 um 11:20 schrieb Jocelyn Falempe:
Quoted 28 lines
When a new mode is set to
modeset->mode, the previous mode should be freed. This fixes the following kmemleak report:drm_mode_duplicate+0x45/0x220 [drm] drm_client_modeset_probe+0x944/0xf50 [drm] __drm_fb_helper_initial_config_and_unlock+0xb4/0x2c0 [drm_kms_helper] drm_fbdev_client_hotplug+0x2bc/0x4d0 [drm_kms_helper] drm_client_register+0x169/0x240 [drm] ast_pci_probe+0x142/0x190 [ast] local_pci_probe+0xdc/0x180 work_for_cpu_fn+0x4e/0xa0 process_one_work+0x8b7/0x1540 worker_thread+0x70a/0xed0 kthread+0x29f/0x340 ret_from_fork+0x1f/0x30cc <[email protected]>Reported-by Zhang Yi <[email protected]>Signed-off-by Jocelyn Falempe <[email protected]>--- drivers/gpu/drm/drm_client_modeset.c | 3 +++ 1 file changed, 3 insertions(+)drivers/gpu/drm/drm_client_modeset.c +0
-0
drivers/gpu/drm/drm_client_modeset.c int drm_client_modeset_probe(struct drm_client_dev *client, unsigned int width, · line 871
Quoted 5 lines
drivers/gpu/drm/drm_client_modeset.c +2
-0@@ -867,6 +867,9 @@ int drm_client_modeset_probe(struct drm_client_dev *client, unsigned int width,break ; } +if (modeset->mode) +kfree (modeset->mode);
kfree() does a NULL-pointer test. So it can be removed here. With that changed:
Quoted 4 lines
drivers/gpu/drm/drm_client_modeset.c +1
-0+ modeset->mode =drm_mode_duplicate (dev, mode);drm_connector_get (connector); modeset->connectors[modeset->num_connectors++] = connector;
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstrasse 146, 90461 Nuernberg, Germany GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman HRB 36809 (AG Nuernberg)
Quoted 4 lines · Jocelyn Falempe
Jocelyn Falempe (2):
drm/client: Fix memory leak indrm_client_target_cloneddrm/client: Fix memory leak indrm_client_modeset_probe
I just pushed the two patches to drm-misc-fixes, after removing the useless NULL check of the second patch.
Thank for your quick reviews.
Best regards,
Signature · 1 line
Jocelyn
Quoted 5 lines
drivers/gpu/drm/drm_client_modeset.c | 8 ++++++++ 1 file changed, 8 insertions(+)base-commit:
2f98e686ef59b5d19af5847d755798e2031bee3a