Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1280310pxb; Fri, 21 Jan 2022 14:13:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJxX8CdbNU7wciYRDbOuf9wMyHfKGHNnqeksKvMFFN0tgSDHpTbDiTsuDJqPY6wVeHrpelOb X-Received: by 2002:a63:33cf:: with SMTP id z198mr4273838pgz.344.1642803186023; Fri, 21 Jan 2022 14:13:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642803186; cv=none; d=google.com; s=arc-20160816; b=xupV3KpRl5Xc/Cr5W546UZkPfR3VksymYPOMMlOm1AQElF2ns9P0lbI38grfYE7MiM JwXLmINKGtry1z36AAPPRpahtvIzS8iLcR/k/Ty85ad+EKP1HvO09hlec1Pfq6nlBvr0 YIaauj7XRUSERQsHuERtrWDVh+XNyimFePM+JYbia+xvPP4LUAl4xSJxATKASOPktcfH J1Sc0kRSrJ6wMHNYZ/2XEcPGuc9BxUs9Mw6axicG7be4475Xoecx4veGgyt65fjIidIu Z+LrsV/n1AlUbywUQvMlUFZi5b7vyPihgjLYz3HttaRsC+tApvM6fjXKYcK+2o2JqvOW clJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=gMEDNjjB/N8V69Z6rGE1pYgKTy3aC3k68p9DkWwGiow=; b=EFc0s39lkhLcuzHALWgn9tM2ARj/q1K7XEfezfAsYJya9+InTd1OvJ2u4Wpo4iC4Tr PNSjPAjrME49HJpSI7GnjhP+Upim3s/gMNks1a2w2xq1fUASovdZzhT7m3bZ1fS0deg9 2G/jVTXl+C1Gl1lOMRdgPWULK75GcjL5I4BBaFxAAwwLlMmK7ekigd/jIQyLAAVT/mNt gOVxFQwA2uSWwFB4FkFP4yjzheSdB5MESs65O5WvcpmM8yt+aITYfRPpsVHaZfJANOhH PLZAXMWIaYZTOJxQuZMoANamKG+lViZjbXyn7CBnfn6ANWu12YXfjo16sIggUGSD64jR eetA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mh3si8386648pjb.126.2022.01.21.14.12.54; Fri, 21 Jan 2022 14:13:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241566AbiATNp6 (ORCPT + 99 others); Thu, 20 Jan 2022 08:45:58 -0500 Received: from mail.hust.edu.cn ([202.114.0.240]:2507 "EHLO hust.edu.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1345551AbiATNpy (ORCPT ); Thu, 20 Jan 2022 08:45:54 -0500 Received: from localhost.localdomain ([172.16.0.254]) (user=dzm91@hust.edu.cn mech=LOGIN bits=0) by mx1.hust.edu.cn with ESMTP id 20KDiGAH029221-20KDiGAK029221 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Thu, 20 Jan 2022 21:44:20 +0800 From: Dongliang Mu To: Ryusuke Konishi , Pavel Skripkin , Andrew Morton Cc: Dongliang Mu , linux-nilfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] fs: nilfs2: fix memory leak in nilfs_sysfs_create_device_group Date: Thu, 20 Jan 2022 21:44:14 +0800 Message-Id: <20220120134415.57147-1-dzm91@hust.edu.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-FEAS-AUTH-USER: dzm91@hust.edu.cn Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The preivous commit 8fd0c1b0647a ("nilfs2: fix memory leak in nilfs_sysfs_delete_device_group") only handles the memory leak in the nilfs_sysfs_delete_device_group. However, the similar memory leak still occurs in the nilfs_sysfs_create_device_group. Fix it by adding kobject_del when kobject_init_and_add succeeds, but one of the following calls fails. Fixes: 8fd0c1b0647a ("nilfs2: fix memory leak in nilfs_sysfs_delete_device_group") Signed-off-by: Dongliang Mu --- fs/nilfs2/sysfs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/nilfs2/sysfs.c b/fs/nilfs2/sysfs.c index 379d22e28ed6..0b2db2b499d5 100644 --- a/fs/nilfs2/sysfs.c +++ b/fs/nilfs2/sysfs.c @@ -995,7 +995,7 @@ int nilfs_sysfs_create_device_group(struct super_block *sb) err = nilfs_sysfs_create_mounted_snapshots_group(nilfs); if (err) - goto cleanup_dev_kobject; + goto delete_dev_kobject; err = nilfs_sysfs_create_checkpoints_group(nilfs); if (err) @@ -1027,6 +1027,9 @@ int nilfs_sysfs_create_device_group(struct super_block *sb) delete_mounted_snapshots_group: nilfs_sysfs_delete_mounted_snapshots_group(nilfs); +delete_dev_kobject: + kobject_del(&nilfs->ns_dev_kobj); + cleanup_dev_kobject: kobject_put(&nilfs->ns_dev_kobj); kfree(nilfs->ns_dev_subgroups); -- 2.25.1