Skip to contentSkip to conversation

drm/crc-debugfs: Fix memleak in crc_control_write

PATCH Applied Dinghao Liu 3 participants 3 messages Aug 19, 2020 – Sep 1, 2020

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

PATCH 1/1 drm/crc-debugfs: Fix memleak in crc_control_write

When verify_crc_source() fails, source needs to be freed. However, current code is returning directly and ends up leaking memory.

Fixes c0811a7d5befe ("drm/crc: Cleanup crtc_crc_open function")
---
 drivers/gpu/drm/drm_debugfs_crc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_debugfs_crc.c +3 -1
index 5d67a41f7c3a..3dd70d813f69 100644
@@ -144,8 +144,10 @@ static ssize_t crc_control_write(struct file *file, const char __user *ubuf,
 		source[len - 1] = '\0';
 
 	ret = crtc->funcs->verify_crc_source(crtc, source, &values_cnt);
-	if (ret)
+	if (ret) {
+		kfree(source);
 		return ret;
+	}
 
 	spin_lock_irq(&crc->lock);
 
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw

Hi Dinghao,

Thank you for the patch.

Quoted 5 lines · Dinghao Liu

When verify_crc_source() fails, source needs to be freed. However, current code is returning directly and ends up leaking memory.

Fixes c0811a7d5befe ("drm/crc: Cleanup crtc_crc_open function")

I think the issue was introduced in d5cc15a0c66e ("drm: crc: Introduce verify_crc_source callback"). Apart from that,

Quoted 21 lines
---
 drivers/gpu/drm/drm_debugfs_crc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_debugfs_crc.c +3 -1
index 5d67a41f7c3a..3dd70d813f69 100644
@@ -144,8 +144,10 @@ static ssize_t crc_control_write(struct file *file, const char __user *ubuf,
 		source[len - 1] = '\0';
 
 	ret = crtc->funcs->verify_crc_source(crtc, source, &values_cnt);
-	if (ret)
+	if (ret) {
+		kfree(source);
 		return ret;
+	}
 
 	spin_lock_irq(&crc->lock);
 
Signature · 7 lines
Regards,

Laurent Pinchart
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw
Quoted 9 lines · Laurent Pinchart

Hi Dinghao,

Thank you for the patch.

Quoted 4 lines · Dinghao Liu

When verify_crc_source() fails, source needs to be freed. However, current code is returning directly and ends up leaking memory.

Quoted 6 lines
Quoted 1 line
Fixes c0811a7d5befe ("drm/crc: Cleanup crtc_crc_open function")

I think the issue was introduced in d5cc15a0c66e ("drm: crc: Introduce verify_crc_source callback"). Apart from that,

Pushed to drm-misc-next.
-Daniel

Quoted 27 lines
Quoted 22 lines
---
 drivers/gpu/drm/drm_debugfs_crc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_debugfs_crc.c +3 -1
index 5d67a41f7c3a..3dd70d813f69 100644
@@ -144,8 +144,10 @@ static ssize_t crc_control_write(struct file *file, const char __user *ubuf,
 		source[len - 1] = '\0';
 
 	ret = crtc->funcs->verify_crc_source(crtc, source, &values_cnt);
-	if (ret)
+	if (ret) {
+		kfree(source);
 		return ret;
+	}
 
 	spin_lock_irq(&crc->lock);
 
Signature · 3 lines
Regards,

Laurent Pinchart
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel