From patchwork Thu Aug 11 02:52:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: haoxin X-Patchwork-Id: 12941071 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C353DC00140 for ; Thu, 11 Aug 2022 02:53:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4A2F08E0002; Wed, 10 Aug 2022 22:53:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 452F88E0001; Wed, 10 Aug 2022 22:53:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 341AE8E0002; Wed, 10 Aug 2022 22:53:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 219118E0001 for ; Wed, 10 Aug 2022 22:53:07 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id EFD531A0710 for ; Thu, 11 Aug 2022 02:53:06 +0000 (UTC) X-FDA: 79785789972.19.DA2543D Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) by imf11.hostedemail.com (Postfix) with ESMTP id 206C34019B for ; Thu, 11 Aug 2022 02:53:04 +0000 (UTC) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046056;MF=xhao@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0VLxI13B_1660186379; Received: from localhost.localdomain(mailfrom:xhao@linux.alibaba.com fp:SMTPD_---0VLxI13B_1660186379) by smtp.aliyun-inc.com; Thu, 11 Aug 2022 10:53:01 +0800 From: Xin Hao To: cl@linux.com Cc: penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, vbabka@suse.cz, roman.gushchin@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm/slub: release kobject if kobject_init_and_add failed in sysfs_slab_add Date: Thu, 11 Aug 2022 10:52:58 +0800 Message-Id: <20220811025258.68684-1-xhao@linux.alibaba.com> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660186386; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=m4eupV/bqgraGkoSaNC0TueVTSirQ6nlHGLDaCkBbv0=; b=otuDwOBJAeBjNvDDbBMq/qOtYHAT92g6vKWc8zLi/tJCV3VS/C/LuGn6Xi23kRaP7LD/KE lXfbGqlD7r1HhWiF9veSQqufQOYNB+iO1mwyhh7sUatehUdjnxyd/IHUZEPDSFcosTlrh9 FnYeS3DhWnIB+BORgsx3KreFMX1GSNU= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of xhao@linux.alibaba.com designates 115.124.30.133 as permitted sender) smtp.mailfrom=xhao@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660186386; a=rsa-sha256; cv=none; b=TM08L62OgT0BcxXoNvSuq1+29YMnl0A14kTImWMvJjvZQUuPV1Fh2WwDsvGGUdlRtF6LtQ cOduJo2FTz9am6CDXWQdUcZSPNXy7+NzgoWOw6TQTF3HgZhxDwVPA7MDFfK4WtNn72rgXr jaxXNLPaeSgJFmoSEIGHC15HlXq5d3c= X-Stat-Signature: zdup5tcqxmq3am1mdmmcf3bfzwguito4 X-Rspamd-Queue-Id: 206C34019B Authentication-Results: imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of xhao@linux.alibaba.com designates 115.124.30.133 as permitted sender) smtp.mailfrom=xhao@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1660186384-377885 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In kobject_init_and_add() function, the refcount is setted by calling kobject_init() function, regardless of whether the return value is zero or not, therefore, we must call kobject_del(&s->kobj) to prevent memory of s->kobj is leaked. Signed-off-by: Xin Hao --- mm/slub.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index b1281b8654bd..63b0a8a3a71f 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -5981,19 +5981,18 @@ static int sysfs_slab_add(struct kmem_cache *s) err = sysfs_create_group(&s->kobj, &slab_attr_group); if (err) - goto out_del_kobj; + goto out; if (!unmergeable) { /* Setup first alias */ sysfs_slab_alias(s, s->name); } + return err; out: if (!unmergeable) kfree(name); - return err; -out_del_kobj: kobject_del(&s->kobj); - goto out; + return err; } void sysfs_slab_unlink(struct kmem_cache *s)