From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sasha Levin Subject: [PATCH AUTOSEL 4.14 6/9] nilfs2: fix memory leak in nilfs_sysfs_create_##name##_group Date: Mon, 13 Sep 2021 18:35:32 -0400 Message-ID: <20210913223535.436405-6-sashal@kernel.org> References: <20210913223535.436405-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=1631572544; bh=oDGtwJ4FGpZDTscMcKSwGi6dBJcwpVGUXU9QH395xKI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jmbf8+MyMgcgQkyB4ewvwYgi3vSL3KPDEOGOxIpxeKvvotH1eBEjtrrQJsT05YvZp bXmHl5iAgzi1FwsIwcG9FIdqm2hk4sbYtff1KITEtFAun7nJxJ8Be5o+kWSiLMpXlG XsK+ImHUhNUMNJR0Aqb+CowTAZdjfxwBsOn1tWACbZoMv6qHT2AQZB6jzo2RughwRc aKMb+yth3fu2l/0D6WWchzQZgFjuNus4Gbj3oXMblligtKihyWBQedwQ5Nlv/pzdFF PcUGEZ8HCm9+ezIX/tGQS3/1nLG4W0ZU1IDpuVY/07wLNqP3OnAHnl3NmL7qWJF4wS OSRS8jFgRNo/Q== In-Reply-To: <20210913223535.436405-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 027a50bc0765..eab7bd68da12 100644 --- a/fs/nilfs2/sysfs.c +++ b/fs/nilfs2/sysfs.c @@ -101,8 +101,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