Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3997569pxv; Mon, 28 Jun 2021 18:56:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyU25Uz5fGIh/+KSTSV5UhTLyCUNeUif7wOsIgFGGnsnnO5dRQ+653g5PB+R3muHNKzQMrl X-Received: by 2002:a92:3209:: with SMTP id z9mr10896805ile.115.1624931788221; Mon, 28 Jun 2021 18:56:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624931788; cv=none; d=google.com; s=arc-20160816; b=LsWu99kM2CxoV0akPfznwBd0kQDvnuoF0Lbqf/vc6ZFS4Y41ANdJI3svyhX83S2+SD tiSW0/QmXkOaTVlJGBfoQfmp7xrgr/4jbh9ipiZQ1XVBQ8I1QXV1y8o5Utumc78waKec gjwO9xnXyBQ6/FBRd7ZxfbSYXreFGXBUnR0ofR7N3qWfhL/34mQSPaPkjd62ZnhAlbQ/ 554Y4aropbHNde8V2NujgGPfnqvEAcOn8I4tDAtTguo6adGrAbgneIedJRiqI+cFvmC/ L3gcqSgvt/6swfBT/OWVJQr6rBZjy/cfr3pDzDifx2t/2XK2lWNYD0AH3RCJPwMFXrlT wifg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=wCg18Co7G/8WwTwwmpE01CRoTgw1h9m/35+3VnaWtL0=; b=CXQinffxmgKY725VIVgdRPwwZ9fEWdahQn72NuHPtW8D1pnEsCfJH/eGcXIpYtI/Q5 wFUojs0IH4f1xDKZI7AXlG3w5whCm1asoxxrW9nAsYrLsZWI4N+Ditkt4a/G+ST411Hu 3jJYuuUD2DmRfxFxJlZu/AUHJoFD52hs1ll8bV/poR4dOExDn16sHp+EoBPl1Z1gR0JC gJco3Pk8mZNa3lfkz0py+k59xUZP9+imSwWX1Mef+WAE3BCQpnJCagmx81+j0IHy1hpN BnAG5+8/sXPeVA9clKnUORGYDfDsvhvtYDiJQQ7t553N+olyK7vC2HmpVgh15cBSRZS+ Mhhg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i2si16407506ilv.49.2021.06.28.18.56.17; Mon, 28 Jun 2021 18:56:28 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231846AbhF2B5N (ORCPT + 99 others); Mon, 28 Jun 2021 21:57:13 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:6019 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230341AbhF2B5C (ORCPT ); Mon, 28 Jun 2021 21:57:02 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4GDS7w1T2rzXlwb; Tue, 29 Jun 2021 09:49:16 +0800 (CST) Received: from dggpemm000001.china.huawei.com (7.185.36.245) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Tue, 29 Jun 2021 09:54:29 +0800 Received: from huawei.com (10.175.113.32) by dggpemm000001.china.huawei.com (7.185.36.245) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Tue, 29 Jun 2021 09:54:29 +0800 From: Nanyong Sun To: CC: , , , Subject: [PATCH 3/6] nilfs2: fix memory leak in nilfs_sysfs_create_##name##_group Date: Tue, 29 Jun 2021 10:25:53 +0800 Message-ID: <20210629022556.3985106-4-sunnanyong@huawei.com> X-Mailer: git-send-email 2.18.0.huawei.25 In-Reply-To: <20210629022556.3985106-1-sunnanyong@huawei.com> References: <20210629022556.3985106-1-sunnanyong@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm000001.china.huawei.com (7.185.36.245) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Nanyong Sun --- 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 ec85ac53720d..6305e4ef7e39 100644 --- a/fs/nilfs2/sysfs.c +++ b/fs/nilfs2/sysfs.c @@ -79,8 +79,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.18.0.huawei.25