From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sasha Levin Subject: [PATCH AUTOSEL 5.14 22/25] nilfs2: fix memory leak in nilfs_sysfs_create_##name##_group Date: Mon, 13 Sep 2021 18:33:36 -0400 Message-ID: <20210913223339.435347-22-sashal@kernel.org> References: <20210913223339.435347-1-sashal@kernel.org> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631572450; bh=QqoS0K9JhF+ax8uAfFCb7d0X1az9U6uGiUzRhvW55P0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fJNYfyZ8HReQq6SO+EEGNeNlKRgGMhj2B/v1M5THwN+Rhw2s8fe8jE3SJYkjqESBD E1AckkTtLWqfrpZwfQq4lN5mbHajhBjt3XLtFLgIZK5539e2mtvYTNSG43W+E49BiT QtOyh8gSwiNvUj5XSyzaCwnn8/mlb+JM8oBf0lKO8h6o0kjud6Ha5quLbNs7xKQwky VJJsFPApLksCT+HxX79cheDWGkfLNoxLS7+ax/amnnZYxlrg7Mk8nv4oJxP/YreWww ZWnJnV5sK7E0e0V3Z8xu+MPXgDjVtspJGp5YJ7RDv2R9GRVOhMb7hl+0XPXWzq59C6 a68dF1k/Mmwow== In-Reply-To: <20210913223339.435347-1-sashal-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> List-ID: Content-Type: text/plain; charset="us-ascii" To: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org Cc: Nanyong Sun , Ryusuke Konishi , Andrew Morton , Linus Torvalds , Sasha Levin , linux-nilfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org From: Nanyong Sun [ Upstream commit 24f8cb1ed057c840728167dab33b32e44147c86f ] If kobject_init_and_add return with error, kobject_put() is needed here to avoid memory leak, because kobject_init_and_add may return error without freeing the memory associated with the kobject it allocated. Link: https://lkml.kernel.org/r/20210629022556.3985106-4-sunnanyong-hv44wF8Li93QT0dZR+AlfA@public.gmane.org Link: https://lkml.kernel.org/r/1625651306-10829-4-git-send-email-konishi.ryusuke-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Signed-off-by: Nanyong Sun Signed-off-by: Ryusuke Konishi Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- fs/nilfs2/sysfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/nilfs2/sysfs.c b/fs/nilfs2/sysfs.c index ec85ac53720d..6305e4ef7e39 100644 --- a/fs/nilfs2/sysfs.c +++ b/fs/nilfs2/sysfs.c @@ -79,8 +79,8 @@ static int nilfs_sysfs_create_##name##_group(struct the_nilfs *nilfs) \ err = kobject_init_and_add(kobj, &nilfs_##name##_ktype, parent, \ #name); \ if (err) \ - return err; \ - return 0; \ + kobject_put(kobj); \ + return err; \ } \ static void nilfs_sysfs_delete_##name##_group(struct the_nilfs *nilfs) \ { \ -- 2.30.2