Handle / Release memory obtained by kasprintf
cover Handle / Release memory obtained by kasprintf
Arvind Yadav (2):
[PATCH 1/2] drm: tegra: dc: Handle return value of kasprintf [PATCH 2/2] drm: Release memory obtained by kasprintf
drivers/gpu/drm/drm_crtc.c | 1 + drivers/gpu/drm/tegra/dc.c | 2 ++ 2 files changed, 3 insertions(+)
Signature · 1 line
1.9.1
PATCH 1/2 drm: tegra: dc: Handle return value of kasprintf
kasprintf() can fail here and we must check its return value.
--- drivers/gpu/drm/tegra/dc.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/tegra/dc.c +2 -0
@@ -1695,6 +1695,8 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)int err; name =kasprintf (GFP_KERNEL ,"dc.%d" , dc->pipe); +if (!name) +return -ENOMEM ; dc->debugfs =debugfs_create_dir (name, minor->debugfs_root);kfree (name);
Signature · 1 line
1.9.1
Re: [PATCH 1/2] drm: tegra: dc: Handle return value of kasprintf
Quoted 12 lines · Arvind Yadav
kasprintf()can fail here and we must check its return value.Signed-off-by Arvind Yadav <[email protected]>--- drivers/gpu/drm/tegra/dc.c | 2 ++ 1 file changed, 2 insertions(+)drivers/gpu/drm/tegra/dc.c +0
-0
drivers/gpu/drm/tegra/dc.c static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor) · line 1700
Quoted 6 lines
drivers/gpu/drm/tegra/dc.c +2
-0@@ -1695,6 +1695,8 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)int err; name =kasprintf (GFP_KERNEL ,"dc.%d" , dc->pipe); +if (!name) +return -ENOMEM ; dc->debugfs =debugfs_create_dir (name, minor->debugfs_root);
Indeed, doesn't look like debugfs_create_dir() can be safely called w/ name==NULL.
Quoted 9 lines
drivers/gpu/drm/tegra/dc.c +0
-0kfree (name);Signature · 6 lines
1.9.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 6 lines
Ville Syrjälä Intel OTC _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 2/2 drm: Release memory obtained by kasprintf
In reply to Arvind YadavFree memory region, if drm_crtc_init_with_planes is not successful.
--- drivers/gpu/drm/drm_crtc.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/drm_crtc.c +1 -0
@@ -328,6 +328,7 @@ int drm_crtc_init_with_planes(struct drm_device *dev, struct drm_crtc *crtc, ret =drm_crtc_crc_init (crtc);if (ret) {drm_mode_object_unregister (dev, &crtc->base); +kfree (crtc->name);return ret; }
Signature · 1 line
1.9.1
Re: [PATCH 2/2] drm: Release memory obtained by kasprintf
Quoted 12 lines · Arvind Yadav
Free memory region, if
drm_crtc_init_with_planesis not successful.Signed-off-by Arvind Yadav <[email protected]>--- drivers/gpu/drm/drm_crtc.c | 1 + 1 file changed, 1 insertion(+)drivers/gpu/drm/drm_crtc.c +0
-0
drivers/gpu/drm/drm_crtc.c int drm_crtc_init_with_planes(struct drm_device *dev, struct drm_crtc *crtc, · line 331
Quoted 4 lines
drivers/gpu/drm/drm_crtc.c +1
-0@@ -328,6 +328,7 @@ int drm_crtc_init_with_planes(struct drm_device *dev, struct drm_crtc *crtc, ret =drm_crtc_crc_init (crtc);if (ret) {drm_mode_object_unregister (dev, &crtc->base); +kfree (crtc->name);
Looks correct. However my ocd would wish the kfree() to precede drm_mode_object_unregister() to make the unwinding mirror the allocation/registration sequence.
Quoted 10 lines
drivers/gpu/drm/drm_crtc.c +0
-0return ret; }Signature · 6 lines
1.9.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 6 lines
Ville Syrjälä Intel OTC _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel