From e3a44ab6e8684ccde865e0ba367c8f9bf5482a3e Mon Sep 17 00:00:00 2001 From: Ketan Patil Date: Wed, 4 Jan 2023 16:49:08 +0000 Subject: [PATCH] video: tegra: nvmap: Fix kmemleak issue get_task_struct increment the ref count over task struct, and it will be decremented as part of put_task_struct. task_struct won't be freed unless it's refcount becomes 0. Hence the missing put_task_struct in nvmap code was resulting into kmemleak. Fix it by add this missing call. Also, mutex_unlock was missing in one of the return path, add it. Bug 3901618 Change-Id: I630eac19e628a549179a8ddaad86ad4d2c9b9a53 Signed-off-by: Ketan Patil Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2837383 Reviewed-by: svcacv Reviewed-by: Ashish Mhetre Reviewed-by: Sachin Nikam GVS: Gerrit_Virtual_Submit --- drivers/video/tegra/nvmap/nvmap_dev.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/video/tegra/nvmap/nvmap_dev.c b/drivers/video/tegra/nvmap/nvmap_dev.c index 53c25e98..32e0c813 100644 --- a/drivers/video/tegra/nvmap/nvmap_dev.c +++ b/drivers/video/tegra/nvmap/nvmap_dev.c @@ -3,7 +3,7 @@ * * User-space interface to nvmap * - * Copyright (c) 2011-2022, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2011-2023, NVIDIA CORPORATION. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -223,6 +223,7 @@ struct nvmap_client *__nvmap_create_client(struct nvmap_device *dev, if (nvmap_client_pid(client) == pid) { /* Increment counter to track number of namespaces of a process */ atomic_add(1, &client->count); + put_task_struct(current->group_leader); is_existing_client = true; goto unlock; } @@ -234,8 +235,10 @@ unlock: } client = kzalloc(sizeof(*client), GFP_KERNEL); - if (!client) + if (!client) { + mutex_unlock(&dev->clients_lock); return NULL; + } client->name = name; client->handle_refs = RB_ROOT; client->task = task;