2019-10-28 21:28:30

by Jae Hyun Yoo

[permalink] [raw]
Subject: Re: [PATCH v2] media: aspeed-video: Fix memory leaks in aspeed_video_probe

On 10/28/2019 9:58 AM, Navid Emamdoost wrote:
> In the implementation of aspeed_video_probe() the allocated memory for
> video should be released if either devm_ioremap_resource()
> or aspeed_video_init() or aspeed_video_setup_video() fails. Replace
> kzalloc() with devm_kzalloc to avoid explicit release for video.
>
> Fixes: d2b4387f3bdf ("media: platform: Add Aspeed Video Engine driver")
> Signed-off-by: Navid Emamdoost <[email protected]>
> ---
> Changes in v2:
> -- replace kzalloc with devm_kzalloc based on Jae Hyun Yoo
> suggestion
>
> drivers/media/platform/aspeed-video.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/media/platform/aspeed-video.c b/drivers/media/platform/aspeed-video.c
> index eb12f3793062..2aa8ea2f9824 100644
> --- a/drivers/media/platform/aspeed-video.c
> +++ b/drivers/media/platform/aspeed-video.c
> @@ -1646,7 +1646,7 @@ static int aspeed_video_probe(struct platform_device *pdev)
> {
> int rc;
> struct resource *res;
> - struct aspeed_video *video = kzalloc(sizeof(*video), GFP_KERNEL);
> + struct aspeed_video *video = devm_kzalloc(sizeof(*video), GFP_KERNEL);

It can't be compiled. devm_kzalloc should have 3 parameters.

Cheers,

Jae


2019-10-28 21:31:52

by Navid Emamdoost

[permalink] [raw]
Subject: Re: [PATCH v2] media: aspeed-video: Fix memory leaks in aspeed_video_probe

On Mon, Oct 28, 2019 at 12:01 PM Jae Hyun Yoo
<[email protected]> wrote:
>
> On 10/28/2019 9:58 AM, Navid Emamdoost wrote:
> > In the implementation of aspeed_video_probe() the allocated memory for
> > video should be released if either devm_ioremap_resource()
> > or aspeed_video_init() or aspeed_video_setup_video() fails. Replace
> > kzalloc() with devm_kzalloc to avoid explicit release for video.
> >
> > Fixes: d2b4387f3bdf ("media: platform: Add Aspeed Video Engine driver")
> > Signed-off-by: Navid Emamdoost <[email protected]>
> > ---
> > Changes in v2:
> > -- replace kzalloc with devm_kzalloc based on Jae Hyun Yoo
> > suggestion
> >
> > drivers/media/platform/aspeed-video.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/media/platform/aspeed-video.c b/drivers/media/platform/aspeed-video.c
> > index eb12f3793062..2aa8ea2f9824 100644
> > --- a/drivers/media/platform/aspeed-video.c
> > +++ b/drivers/media/platform/aspeed-video.c
> > @@ -1646,7 +1646,7 @@ static int aspeed_video_probe(struct platform_device *pdev)
> > {
> > int rc;
> > struct resource *res;
> > - struct aspeed_video *video = kzalloc(sizeof(*video), GFP_KERNEL);
> > + struct aspeed_video *video = devm_kzalloc(sizeof(*video), GFP_KERNEL);
>
> It can't be compiled. devm_kzalloc should have 3 parameters.
>

Oops! my bad. Do you think such a list of parameters is fine:
devm_kzalloc(&pdev->dev, sizeof(*video), GFP_KERNEL);

> Cheers,
>
> Jae



--
Navid.

2019-10-29 06:24:21

by Jae Hyun Yoo

[permalink] [raw]
Subject: Re: [PATCH v2] media: aspeed-video: Fix memory leaks in aspeed_video_probe

On 10/28/2019 10:06 AM, Navid Emamdoost wrote:
> On Mon, Oct 28, 2019 at 12:01 PM Jae Hyun Yoo
> <[email protected]> wrote:
>>
>> On 10/28/2019 9:58 AM, Navid Emamdoost wrote:
>>> In the implementation of aspeed_video_probe() the allocated memory for
>>> video should be released if either devm_ioremap_resource()
>>> or aspeed_video_init() or aspeed_video_setup_video() fails. Replace
>>> kzalloc() with devm_kzalloc to avoid explicit release for video.
>>>
>>> Fixes: d2b4387f3bdf ("media: platform: Add Aspeed Video Engine driver")
>>> Signed-off-by: Navid Emamdoost <[email protected]>
>>> ---
>>> Changes in v2:
>>> -- replace kzalloc with devm_kzalloc based on Jae Hyun Yoo
>>> suggestion
>>>
>>> drivers/media/platform/aspeed-video.c | 2 +-
>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/media/platform/aspeed-video.c b/drivers/media/platform/aspeed-video.c
>>> index eb12f3793062..2aa8ea2f9824 100644
>>> --- a/drivers/media/platform/aspeed-video.c
>>> +++ b/drivers/media/platform/aspeed-video.c
>>> @@ -1646,7 +1646,7 @@ static int aspeed_video_probe(struct platform_device *pdev)
>>> {
>>> int rc;
>>> struct resource *res;
>>> - struct aspeed_video *video = kzalloc(sizeof(*video), GFP_KERNEL);
>>> + struct aspeed_video *video = devm_kzalloc(sizeof(*video), GFP_KERNEL);
>>
>> It can't be compiled. devm_kzalloc should have 3 parameters.
>>
>
> Oops! my bad. Do you think such a list of parameters is fine:
> devm_kzalloc(&pdev->dev, sizeof(*video), GFP_KERNEL);

Yes, it's fine.