From patchwork Thu Aug 11 07:18:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: haoxin X-Patchwork-Id: 12941209 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 4177CC25B0C for ; Thu, 11 Aug 2022 07:18:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B70A78E0003; Thu, 11 Aug 2022 03:18:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AD0658E0001; Thu, 11 Aug 2022 03:18:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 972E98E0003; Thu, 11 Aug 2022 03:18:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 881978E0001 for ; Thu, 11 Aug 2022 03:18:57 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 5BC901406B7 for ; Thu, 11 Aug 2022 07:18:57 +0000 (UTC) X-FDA: 79786459914.21.9E32C9D Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) by imf02.hostedemail.com (Postfix) with ESMTP id 7975980023 for ; Thu, 11 Aug 2022 07:18:55 +0000 (UTC) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R951e4;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=10;SR=0;TI=SMTPD_---0VLyAV6Y_1660202329; Received: from localhost.localdomain(mailfrom:xhao@linux.alibaba.com fp:SMTPD_---0VLyAV6Y_1660202329) by smtp.aliyun-inc.com; Thu, 11 Aug 2022 15:18:50 +0800 From: Xin Hao To: cl@linux.com Cc: penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, 42.hyeyoo@gmail.com, akpm@linux-foundation.org, vbabka@suse.cz, roman.gushchin@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 1/1] mm/slub: release kobject if kobject_init_and_add failed in sysfs_slab_add Date: Thu, 11 Aug 2022 15:18:44 +0800 Message-Id: <20220811071844.74020-2-xhao@linux.alibaba.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20220811071844.74020-1-xhao@linux.alibaba.com> References: <20220811071844.74020-1-xhao@linux.alibaba.com> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660202337; 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:in-reply-to:references:references; bh=Ipx/airaToh5RUTQyOsvjaCH6xby90tiKuGOWTgiJqI=; b=XuzU0kIbYfJqVXXhPmvlS2vgQs2BDQBSzw6nBLey66HkhEmFcuYq3sXW7fmUwsDVLV66vP /M1huvSUXN9tFjv4rSj/qR2bSEfGYOTpGocSIw/5kQN1rVoRERsqQnL0Le0AYUTI4+3Tic bMHCy/QwSTSTnGakYtheuOAtncLJPik= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; spf=pass (imf02.hostedemail.com: domain of xhao@linux.alibaba.com designates 115.124.30.132 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=1660202337; a=rsa-sha256; cv=none; b=kn3vcPD3Ph8cFuAz8Ho0AEuwgKAdR3HUDfhj+o3gVH4rczJZerYxvXt7s/WTI/kGnDKBYd eUDsRlkhVQdSd+XvcV69zIedmFS3qJfUSFw3w7nWn/mjyZIXQqXO091n5jUv82tLWKrf/X U2MebqNK66EmJetc7XY0szzuqQ67udA= X-Stat-Signature: z195qu93m46ory46hi9cdyzu7rpw1s6d X-Rspamd-Queue-Id: 7975980023 Authentication-Results: imf02.hostedemail.com; dkim=none; spf=pass (imf02.hostedemail.com: domain of xhao@linux.alibaba.com designates 115.124.30.132 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: 1660202335-10906 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..940a3f52e07c 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); + kobject_put(&s->kobj); return err; -out_del_kobj: - kobject_del(&s->kobj); - goto out; } void sysfs_slab_unlink(struct kmem_cache *s)