diff mbox series

[next] devlink: fix memory leak on 'resource'

Message ID 20180122103119.4801-1-colin.king@canonical.com
State Accepted, archived
Delegated to: David Miller
Headers show
Series [next] devlink: fix memory leak on 'resource' | expand

Commit Message

Colin Ian King Jan. 22, 2018, 10:31 a.m. UTC
From: Colin Ian King <colin.king@canonical.com>

Currently, if the call to devlink_resource_find returns null then
the error exit path does not free the devlink_resource 'resource'
and a memory leak occurs. Fix this by kfree'ing resource on the
error exit path.

Detected by CoverityScan, CID#1464184 ("Resource leak")

Fixes: d9f9b9a4d05f ("devlink: Add support for resource abstraction")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 net/core/devlink.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Jiri Pirko Jan. 22, 2018, 10:34 a.m. UTC | #1
Mon, Jan 22, 2018 at 11:31:19AM CET, colin.king@canonical.com wrote:
>From: Colin Ian King <colin.king@canonical.com>
>
>Currently, if the call to devlink_resource_find returns null then
>the error exit path does not free the devlink_resource 'resource'
>and a memory leak occurs. Fix this by kfree'ing resource on the
>error exit path.
>
>Detected by CoverityScan, CID#1464184 ("Resource leak")
>
>Fixes: d9f9b9a4d05f ("devlink: Add support for resource abstraction")
>Signed-off-by: Colin Ian King <colin.king@canonical.com>

Acked-by: Jiri Pirko <jiri@mellanox.com>

Thanks.
David Miller Jan. 22, 2018, 2:27 p.m. UTC | #2
From: Colin King <colin.king@canonical.com>
Date: Mon, 22 Jan 2018 10:31:19 +0000

> From: Colin Ian King <colin.king@canonical.com>
> 
> Currently, if the call to devlink_resource_find returns null then
> the error exit path does not free the devlink_resource 'resource'
> and a memory leak occurs. Fix this by kfree'ing resource on the
> error exit path.
> 
> Detected by CoverityScan, CID#1464184 ("Resource leak")
> 
> Fixes: d9f9b9a4d05f ("devlink: Add support for resource abstraction")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Applied, thanks Colin.
diff mbox series

Patch

diff --git a/net/core/devlink.c b/net/core/devlink.c
index dd7d6dd07bfb..2b6b8eebcda3 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -3181,6 +3181,7 @@  int devlink_resource_register(struct devlink *devlink,
 			resource_list = &parent_resource->resource_list;
 			resource->parent = parent_resource;
 		} else {
+			kfree(resource);
 			err = -EINVAL;
 			goto out;
 		}