From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sasha Levin Subject: [PATCH AUTOSEL 5.13 16/19] nilfs2: fix memory leak in nilfs_sysfs_create_##name##_group Date: Mon, 13 Sep 2021 18:34:12 -0400 Message-ID: <20210913223415.435654-16-sashal@kernel.org> References: <20210913223415.435654-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=1631572477; bh=JJxAlnMO1RtxGCmp4Tk/rVED7CmQ4t0m16eubjcGGEk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XceWs2I6aLv53fYytxHlKxFgLVwzq3JlLMpuyl/hkHuMS7ZxJNDXkM5Rhe2ffnKj8 hGEkXKkDwQmtus4WOT23W3gQkTTGgIoBJ12fcGoyvDzDVawshkuBPUy4c98jCNMSgt QSOlYOzj7cHoTgWHGcjqcaH0/T9l++6eKNFHB3xZ6jy2eqr1sglismS46r+mIgp4xT vSnDjONAO9FgEZ2+lO7j1CmLB2nX4IjrHxx3EQ2jUMVMuIQtLXzhG7+bY7+ih1Ceik Lht72V+EDPOqRlRtxz9nQgjvmHHYGLwiPojqG+FKqpFvr+w3WIfsd7lHZZd7uAtyJt qTAZFXmVyiw0g== In-Reply-To: <20210913223415.435654-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 43f660beb9b4..5dc468ff5903 100644 --- a/fs/nilfs2/sysfs.c +++ b/fs/nilfs2/sysfs.c @@ -92,8 +92,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