2017-09-27 12:27:17

by Jeffy Chen

[permalink] [raw]
Subject: [PATCH] drm/rockchip: Fix memory leak in rockchip_drm_sys_resume()

Free the drm_atomic_state allocated by drm_atomic_helper_suspend().

Fixes: 5a5873830972 ("drm/rockchip: Use atomic PM helpers")
Signed-off-by: Jeffy Chen <[email protected]>
---

drivers/gpu/drm/rockchip/rockchip_drm_drv.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
index 76d63de5921d..80235b672deb 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
@@ -15,6 +15,7 @@
*/

#include <drm/drmP.h>
+#include <drm/drm_atomic.h>
#include <drm/drm_crtc_helper.h>
#include <drm/drm_fb_helper.h>
#include <drm/drm_gem_cma_helper.h>
@@ -299,6 +300,7 @@ static int rockchip_drm_sys_resume(struct device *dev)

priv = drm->dev_private;
drm_atomic_helper_resume(drm, priv->state);
+ drm_atomic_state_put(priv->state);
rockchip_drm_fb_resume(drm);
drm_kms_helper_poll_enable(drm);

--
2.11.0



2017-09-27 20:27:12

by Sean Paul

[permalink] [raw]
Subject: Re: [PATCH] drm/rockchip: Fix memory leak in rockchip_drm_sys_resume()

On Wed, Sep 27, 2017 at 08:26:42PM +0800, Jeffy Chen wrote:
> Free the drm_atomic_state allocated by drm_atomic_helper_suspend().
>
> Fixes: 5a5873830972 ("drm/rockchip: Use atomic PM helpers")
> Signed-off-by: Jeffy Chen <[email protected]>
> ---
>
> drivers/gpu/drm/rockchip/rockchip_drm_drv.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
> index 76d63de5921d..80235b672deb 100644
> --- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
> +++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
> @@ -15,6 +15,7 @@
> */
>
> #include <drm/drmP.h>
> +#include <drm/drm_atomic.h>
> #include <drm/drm_crtc_helper.h>
> #include <drm/drm_fb_helper.h>
> #include <drm/drm_gem_cma_helper.h>
> @@ -299,6 +300,7 @@ static int rockchip_drm_sys_resume(struct device *dev)
>
> priv = drm->dev_private;
> drm_atomic_helper_resume(drm, priv->state);
> + drm_atomic_state_put(priv->state);

Won't this be freed for you eventually in commit_tail()?

Sean

> rockchip_drm_fb_resume(drm);
> drm_kms_helper_poll_enable(drm);
>
> --
> 2.11.0
>
>
> _______________________________________________
> dri-devel mailing list
> [email protected]
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

--
Sean Paul, Software Engineer, Google / Chromium OS

2017-09-28 03:16:58

by Jeffy Chen

[permalink] [raw]
Subject: Re: [PATCH] drm/rockchip: Fix memory leak in rockchip_drm_sys_resume()

Hi Sean,

On 09/28/2017 04:27 AM, Sean Paul wrote:
>> >@@ -299,6 +300,7 @@ static int rockchip_drm_sys_resume(struct device *dev)
>> >
>> > priv = drm->dev_private;
>> > drm_atomic_helper_resume(drm, priv->state);
>> >+ drm_atomic_state_put(priv->state);
> Won't this be freed for you eventually in commit_tail()?
>
i think the drm_atomic_state_put in commit_tail is paired to the
drm_atomic_state_get in drm_atomic_helper_commit.

and the kmemleak shows(after a few suspend/resume):

unreferenced object 0xffffffc0ce0fa400 (size 256):
...
backtrace:
[<ffffffc00034a9a8>] __save_stack_trace+0x48/0x6c
[<ffffffc00034b088>] create_object+0x138/0x254
[<ffffffc0009d5504>] kmemleak_alloc+0x58/0x8c
[<ffffffc000345f78>] __kmalloc+0x1d4/0x2a0
[<ffffffc0006765bc>] usb_alloc_urb+0x30/0x60
[<ffffffbffc128598>] alloc_ctrl_urb+0x38/0x120 [btusb]
[<ffffffbffc129e7c>] btusb_send_frame+0x64/0xf8 [btusb]




checking the current code, i saw only i915/intel_display.c has this
drm_atomic_state_put for the state allocated by
drm_atomic_helper_suspend(), there're many drivers missing that(or maybe
they free it in some other way?)

> Sean
>