linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/crc-debugfs: Fix memleak in crc_control_write
@ 2020-08-19  8:22 Dinghao Liu
  2020-08-19 11:55 ` Laurent Pinchart
  0 siblings, 1 reply; 3+ messages in thread
From: Dinghao Liu @ 2020-08-19  8:22 UTC (permalink / raw)
  To: dinghao.liu, kjlu
  Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Daniel Vetter, Rodrigo Vivi, Laurent Pinchart,
	Leo Li, Mahesh Kumar, dri-devel, linux-kernel

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")
Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
---
 drivers/gpu/drm/drm_debugfs_crc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_debugfs_crc.c b/drivers/gpu/drm/drm_debugfs_crc.c
index 5d67a41f7c3a..3dd70d813f69 100644
--- a/drivers/gpu/drm/drm_debugfs_crc.c
+++ b/drivers/gpu/drm/drm_debugfs_crc.c
@@ -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);
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/crc-debugfs: Fix memleak in crc_control_write
  2020-08-19  8:22 [PATCH] drm/crc-debugfs: Fix memleak in crc_control_write Dinghao Liu
@ 2020-08-19 11:55 ` Laurent Pinchart
  2020-09-01  7:46   ` Daniel Vetter
  0 siblings, 1 reply; 3+ messages in thread
From: Laurent Pinchart @ 2020-08-19 11:55 UTC (permalink / raw)
  To: Dinghao Liu
  Cc: kjlu, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Daniel Vetter, Rodrigo Vivi, Leo Li, Mahesh Kumar,
	dri-devel, linux-kernel

Hi Dinghao,

Thank you for the patch.

On Wed, Aug 19, 2020 at 04:22:28PM +0800, Dinghao Liu wrote:
> 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,

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> ---
>  drivers/gpu/drm/drm_debugfs_crc.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/drm_debugfs_crc.c b/drivers/gpu/drm/drm_debugfs_crc.c
> index 5d67a41f7c3a..3dd70d813f69 100644
> --- a/drivers/gpu/drm/drm_debugfs_crc.c
> +++ b/drivers/gpu/drm/drm_debugfs_crc.c
> @@ -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);
>  

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/crc-debugfs: Fix memleak in crc_control_write
  2020-08-19 11:55 ` Laurent Pinchart
@ 2020-09-01  7:46   ` Daniel Vetter
  0 siblings, 0 replies; 3+ messages in thread
From: Daniel Vetter @ 2020-09-01  7:46 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Dinghao Liu, kjlu, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Daniel Vetter, Rodrigo Vivi,
	Leo Li, Mahesh Kumar, dri-devel, linux-kernel

On Wed, Aug 19, 2020 at 02:55:15PM +0300, Laurent Pinchart wrote:
> Hi Dinghao,
> 
> Thank you for the patch.
> 
> On Wed, Aug 19, 2020 at 04:22:28PM +0800, Dinghao Liu wrote:
> > 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,
> 
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Pushed to drm-misc-next.
-Daniel

> 
> > Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> > ---
> >  drivers/gpu/drm/drm_debugfs_crc.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/gpu/drm/drm_debugfs_crc.c b/drivers/gpu/drm/drm_debugfs_crc.c
> > index 5d67a41f7c3a..3dd70d813f69 100644
> > --- a/drivers/gpu/drm/drm_debugfs_crc.c
> > +++ b/drivers/gpu/drm/drm_debugfs_crc.c
> > @@ -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);
> >  
> 
> -- 
> Regards,
> 
> Laurent Pinchart

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-09-01  7:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-19  8:22 [PATCH] drm/crc-debugfs: Fix memleak in crc_control_write Dinghao Liu
2020-08-19 11:55 ` Laurent Pinchart
2020-09-01  7:46   ` Daniel Vetter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).