Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1686936pxb; Fri, 24 Sep 2021 09:42:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKFHV1ShY2TyD/oiYl9Jj5Afg99QF6uhvq4jxoZn3FKyCt/HfNJ9Loo/ysP2iGfX2UF8yH X-Received: by 2002:a05:6e02:1a44:: with SMTP id u4mr9200864ilv.35.1632501720352; Fri, 24 Sep 2021 09:42:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632501720; cv=none; d=google.com; s=arc-20160816; b=0ZqMccVKDVpJ8WLbRTCgDVuDMD2LrhVG0JN1zwm51khHBh62FhkOqPnhHu61UAozMG ODVRUfKH+Es6gvrGOpJUoxGu3r3sll8DWWwPBG0XCnQp1kmhcqN+iTF5ipQuE7jVazwL uwfTcGq5G8f33nkXLQByqVHd2Nytgbk8I3t+rn/XIHU8GTHEF1lJjvOSOX2HF9YUbjEU 8Ul8P8Nqb6DI2LNZHotpR3Yrnu1CWyQtrBtRAY6ozGgNH2uYo2YmWfI2p8pR3cureV0r AqoSQUC/0LZJkb+TU7bppwK51P+B9767jaUZq5vzZFUgSeQVoC8GcHbOpK3cFlSMBipm f9bQ== 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=Oj1Q/s2nC8r/4d2QnC5mtoDsMJ1z1J6qzUraNKBCg3U=; b=Iah93jkzzPWh5TlHkPA/R2HahtZsNIoZKhLF9XLmJUMgDoidx58NkzjDqcpL/GdVEQ Vt6T9pHFUP2+5M31WQwfmbdG9BwW+hjtlPoV2n+XzAko65zYUZOxP9dVOiuYrZipoWI7 uS/UH9OOV4jiyNIc4VZdWlkhTtaLE/oub/NekFqI4/4xXqG0yxMyJ64F3STjpRVhSIcV 1S3P34ETG0irvmhDZKO44X9doMDT9cbQRFGA/pqp5eX4v5ripshXiKiCFnUP5Kxnfawk 0fJMCP9LmydQ0yqyqqebUGp1JyzM5W7XuCfkp4h2p+wLYwwm7jrW6jMBNbj3XhWDhCkb N2Xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aR+5YZEy; 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 l18si11498187ilt.139.2021.09.24.09.41.46; Fri, 24 Sep 2021 09:42:00 -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=aR+5YZEy; 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 S1344944AbhIXMxm (ORCPT + 99 others); Fri, 24 Sep 2021 08:53:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:44324 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344122AbhIXMvy (ORCPT ); Fri, 24 Sep 2021 08:51:54 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9D2936135A; Fri, 24 Sep 2021 12:49:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632487760; bh=Kw1ekoYG9pMOhpMBdg5yUJvJIespP166y6hX4RuXWLw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aR+5YZEyAOjvJkIhPeMX44c5N4AHLvE1AxyZ7cWFkLV0VJNqv0SNCDYbY5OqmAvmm Vvqa+x+2/GTrH6CPAyBdSXnpLUDMvWeQbM30B1Pt56pDyusl2Twulkx+0zQ6gWrX9m EGEnZMQqvWYu0kicm7vv42KmVsLEnctkqAmPkVo0= 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 4.19 26/34] nilfs2: fix memory leak in nilfs_sysfs_create_##name##_group Date: Fri, 24 Sep 2021 14:44:20 +0200 Message-Id: <20210924124330.813815643@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210924124329.965218583@linuxfoundation.org> References: <20210924124329.965218583@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 ca720d958315..31d640a87b59 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