Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1845462pxb; Fri, 24 Sep 2021 13:21:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxMLfBYY2VN81qFBuyR7hIyqAtfyNyN/YMhvj83Vj28Gp4+HcJavms253vgSVDW74kVBXWD X-Received: by 2002:a17:906:8467:: with SMTP id hx7mr13379231ejc.369.1632514884575; Fri, 24 Sep 2021 13:21:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632514884; cv=none; d=google.com; s=arc-20160816; b=DTN17fD6/Q1OmPyxTYLzAK47ODLg83ABQEeQgTbCbLrQBC1tIjjsWDmqZuCvUKvuF9 gNB2F74Q8lQoSqsMZGoqv3FTBn0WtPpe7FtizgBq8kD0ZTpccwKo3Ycz7hkbHEAsb+at 3W0n+0CY+i96b/Nw+XSE37joUi/ldVTvYqCfpW8b6ZB0QhXY4XOzVq5/LcDMS/fEykYq ZCPgyO3xzoFSrJmCse3FQsU+XVlI56sFRQb8qlZe2pzJkZlbpMreuzwSP2KvW9uKy01K UY2Brfvsu8sh8PpoYiicogc6Mf4P2JXobAhOHQ5icUn3JUeXvYX4noeMFM8v8DopdDEX 721w== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=muJcCJclQVDYBfIz2b9KKqDVjBCGsPpWOETdCtBMW3Y=; b=jn+6AJMcJsKEZ/aO6Mn5TDz8j7/IZan1sYxCVQTVPbEdmhyP2aoh2Os5py6VPmNjDL lnP7V3bwg3uLEnw6tuI9pYgfXQAJVCOwfcd1vhAwG2XEkTBvb9gw47y5Z36O6EBDo+dm XXp2lPYcNUAB2nK3Oc+Upp+m+EOZSazymmwum5jm+nVjQD7wmQC8sGy1DTSRbuheEJcB lEU7mVK9vERrAf/n0mAO7oQeB2zEUwDeFineK5QFfiPT7lmNQPobhzzsfJBTJix95122 DRsVLa8lClwad9eRefQJdv9qKopMtT3Bv2Yor0XeW41G0UlIYpRwHNdDklK+2dkQvEyY fRpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RzHysESb; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c2si10768958ejz.69.2021.09.24.13.21.00; Fri, 24 Sep 2021 13:21:24 -0700 (PDT) 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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RzHysESb; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344835AbhIXNOI (ORCPT + 99 others); Fri, 24 Sep 2021 09:14:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:37584 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345087AbhIXNKG (ORCPT ); Fri, 24 Sep 2021 09:10:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0CF8661528; Fri, 24 Sep 2021 12:57:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632488274; bh=j93FAQ8D7dWrcDX6UdbDe1fyQgWNKzt95YO7Er+ywow=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RzHysESbArrOsxUjJI4WDRHZqCvlm2fNKMzu/X1gDLvVO9wNaWEeW5f6Rx2Inru5P gnW3z227V3o/tbfWBu+4S1PdyowaDfNYezDimIv4opDmHQy6oZ/6axaDx7beGCAHWM T0ZjitG6ZypfCdRQ+M0f+7NZs8ceeqSpTyXzWsYg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nanyong Sun , Ryusuke Konishi , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 5.10 51/63] nilfs2: fix memory leak in nilfs_sysfs_create_##name##_group Date: Fri, 24 Sep 2021 14:44:51 +0200 Message-Id: <20210924124336.031530334@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210924124334.228235870@linuxfoundation.org> References: <20210924124334.228235870@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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@huawei.com Link: https://lkml.kernel.org/r/1625651306-10829-4-git-send-email-konishi.ryusuke@gmail.com 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.33.0