From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sasha Levin Subject: [PATCH AUTOSEL 5.4 11/12] nilfs2: fix memory leak in nilfs_sysfs_create_snapshot_group Date: Mon, 13 Sep 2021 18:35:03 -0400 Message-ID: <20210913223504.436087-11-sashal@kernel.org> References: <20210913223504.436087-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=1631572519; bh=EzL9KJn4SWgGVEjHbrIl82g6//S9PtBM8R84vzpgyao=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PN8AIFjI66Iq7vZ+stKw42vgogD4Z4xKnjf03WIs+8xlHpdA8DYw9lJB+K1emeZyD W/R1q5ohX9vzZrK/fKbvspazkri8A75b4S4T45mU/faYkhj58f9P29ao7kyjjGKETr 0tGcLLNILNOumH2vOi+eLdOVFCGdxQmZd8k2cjlIYcwTaMzq49KGc4BZb8mkN9SAA2 /6OoaC/84qNL5gbazEDBAYAgeSdtTBOs2RZKNSCnKZzZdZclslERfk2THihol2XyWC GrAz51oyeubMDsOmmRmoCaZvlQlwk1+lCAwOSmeAdJic9kZBjt30/ktogStJ/16vAx JrudTH16EovoA== In-Reply-To: <20210913223504.436087-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 b2fe39c248f3fa4bbb2a20759b4fdd83504190f7 ] If kobject_init_and_add returns 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-6-sunnanyong-hv44wF8Li93QT0dZR+AlfA@public.gmane.org Link: https://lkml.kernel.org/r/1625651306-10829-6-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 195f42192a15..6c92ac314b06 100644 --- a/fs/nilfs2/sysfs.c +++ b/fs/nilfs2/sysfs.c @@ -208,9 +208,9 @@ int nilfs_sysfs_create_snapshot_group(struct nilfs_root *root) } if (err) - return err; + kobject_put(&root->snapshot_kobj); - return 0; + return err; } void nilfs_sysfs_delete_snapshot_group(struct nilfs_root *root) -- 2.30.2