2014-04-15 04:49:42

by Daeseok Youn

[permalink] [raw]
Subject: [PATCH] [media] s2255drv: fix memory leak s2255_probe()


smatch says:
drivers/media/usb/s2255/s2255drv.c:2246 s2255_probe() warn:
possible memory leak of 'dev'

Signed-off-by: Daeseok Youn <[email protected]>
---
drivers/media/usb/s2255/s2255drv.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/drivers/media/usb/s2255/s2255drv.c b/drivers/media/usb/s2255/s2255drv.c
index 1d4ba2b..8aca3ef 100644
--- a/drivers/media/usb/s2255/s2255drv.c
+++ b/drivers/media/usb/s2255/s2255drv.c
@@ -2243,6 +2243,7 @@ static int s2255_probe(struct usb_interface *interface,
dev->cmdbuf = kzalloc(S2255_CMDBUF_SIZE, GFP_KERNEL);
if (dev->cmdbuf == NULL) {
s2255_dev_err(&interface->dev, "out of memory\n");
+ kfree(dev);
return -ENOMEM;
}

--
1.7.4.4


2014-04-15 09:33:13

by Sakari Ailus

[permalink] [raw]
Subject: Re: [PATCH] [media] s2255drv: fix memory leak s2255_probe()

Hi Daeseok,

On Tue, Apr 15, 2014 at 01:49:34PM +0900, Daeseok Youn wrote:
>
> smatch says:
> drivers/media/usb/s2255/s2255drv.c:2246 s2255_probe() warn:
> possible memory leak of 'dev'
>
> Signed-off-by: Daeseok Youn <[email protected]>
> ---
> drivers/media/usb/s2255/s2255drv.c | 1 +
> 1 files changed, 1 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/media/usb/s2255/s2255drv.c b/drivers/media/usb/s2255/s2255drv.c
> index 1d4ba2b..8aca3ef 100644
> --- a/drivers/media/usb/s2255/s2255drv.c
> +++ b/drivers/media/usb/s2255/s2255drv.c
> @@ -2243,6 +2243,7 @@ static int s2255_probe(struct usb_interface *interface,
> dev->cmdbuf = kzalloc(S2255_CMDBUF_SIZE, GFP_KERNEL);
> if (dev->cmdbuf == NULL) {
> s2255_dev_err(&interface->dev, "out of memory\n");
> + kfree(dev);
> return -ENOMEM;
> }
>

The rest of the function already uses goto and labels for error handling. I
think it'd take adding one more. dev is correctly released in other error
cases.

What do you think?

--
Kind regards,

Sakari Ailus
e-mail: [email protected] XMPP: [email protected]

2014-04-15 11:02:33

by Daeseok Youn

[permalink] [raw]
Subject: Re: [PATCH] [media] s2255drv: fix memory leak s2255_probe()

Hi, Sakari

2014-04-15 18:33 GMT+09:00 Sakari Ailus <[email protected]>:
> Hi Daeseok,
>
> On Tue, Apr 15, 2014 at 01:49:34PM +0900, Daeseok Youn wrote:
>>
>> smatch says:
>> drivers/media/usb/s2255/s2255drv.c:2246 s2255_probe() warn:
>> possible memory leak of 'dev'
>>
>> Signed-off-by: Daeseok Youn <[email protected]>
>> ---
>> drivers/media/usb/s2255/s2255drv.c | 1 +
>> 1 files changed, 1 insertions(+), 0 deletions(-)
>>
>> diff --git a/drivers/media/usb/s2255/s2255drv.c b/drivers/media/usb/s2255/s2255drv.c
>> index 1d4ba2b..8aca3ef 100644
>> --- a/drivers/media/usb/s2255/s2255drv.c
>> +++ b/drivers/media/usb/s2255/s2255drv.c
>> @@ -2243,6 +2243,7 @@ static int s2255_probe(struct usb_interface *interface,
>> dev->cmdbuf = kzalloc(S2255_CMDBUF_SIZE, GFP_KERNEL);
>> if (dev->cmdbuf == NULL) {
>> s2255_dev_err(&interface->dev, "out of memory\n");
>> + kfree(dev);
>> return -ENOMEM;
>> }
>>
>
> The rest of the function already uses goto and labels for error handling. I
> think it'd take adding one more. dev is correctly released in other error
> cases.
I am not sure that adding a new label for error handling when
allocation for dev->cmdbuf is failed.
I think it is ok to me. :-) Because I think it is not good adding a
new label and use goto statement for this.

Thanks for review.

Regards,
Daeseok Youn.
>
> What do you think?
>
> --
> Kind regards,
>
> Sakari Ailus
> e-mail: [email protected] XMPP: [email protected]